簡體   English   中英

netcoreapp1.0 沒有找到 net461 特定的包

[英]netcoreapp1.0 does not find net461 specific package

我正在使用 VS Code 構建一個網絡核心應用程序。 我需要使用不受支持的 NuGet 包,因此將 project.json 文件的框架部分更改為以下內容:

"frameworks": {
  "net461": {
    "dependencies": {
      "ScrapySharp": "2.6.2"
    }
  },
  "netcoreapp1.0": {
    "dependencies": {
      "Microsoft.NETCore.App": {
        "type": "platform",
        "version": "1.0.0"
      }
    }
  }
}

恢復項目似乎有效,並且安裝了包 (ScrapySharp)。 但是,當我使用該軟件包時,似乎 netcoreapp 和 net461 都在尋找它。 當 net461 找到並正確引用它時,netcoreapp 會拋出以下錯誤:

The type or namespace name 'ScrapySharp' could not be found

我能做些什么來解決這個問題嗎?

如果包僅適用於兩個框架中的一個 - 您應該修改您的程序代碼,並且在netcoreapp下編譯時不要使用此包。 實際上,在netcoreapp下編譯時,您將丟失應用程序的某些功能。

如果這適合你,那么使用這樣的預處理器指令:

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
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM