简体   繁体   中英

netcoreapp1.0 does not find net461 specific package

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?

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM