Reputation: 45
I am using VS Code to build a net core app. I need to use a NuGet package that is not supported, and therefore changed my project.json file's framework part to the following:
"frameworks": {
"net461": {
"dependencies": {
"ScrapySharp": "2.6.2"
}
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
}
}
Restoring the project seems to work and the package (ScrapySharp) is installed. However when I use the package, it appears that both netcoreapp and net461 look for it. While net461 finds and references it properly, netcoreapp throws the following error:
The type or namespace name 'ScrapySharp' could not be found
Is there anything I can do to work around this?
Upvotes: 1
Views: 172
Reputation: 16805
If package available only for one framework of two - you should modify your program code and do not use this package when compiled under netcoreapp
. Effectively, you will lost some functionality of your app when compiled under netcoreapp
.
If this suitable for you, then use preprocessor directives like this:
public void function DoSomething()
{
#if NET461 then
// do something with ScrapySharp
#else
// Say to your user that this feature is not available
throw new Exception("This feature is not available on this platform");
#endif
}
Upvotes: 1