2016-10-14 52 views
1

安裝我有以下project.json .NET核心項目:.NETStandard庫NuGet包 - 無法在標準項目

{ 
    "version": "1.0.0-*", 

    "dependencies": { 
    "NETStandard.Library": "1.6.0" 
    }, 

    "frameworks": { 
    "netstandard1.6": { 
     "imports": "dnxcore50" 
    } 
    }, 

    "scripts": { 
    "postcompile": [ 
     "dotnet pack --no-build --configuration %compile:Configuration%" 
    ] 
    } 
} 

我已經創建NuGet包(見上postcompile),並發表在的NuGet。

然後我創建了標準4.6.2庫,但無法安裝包 - 出現錯誤,該包不包含用於目標.NET Framework 4.6.2的有效程序集。

我應該如何準備nuget包以使其在標準庫中可用?我認爲NETStandard對於核心和標準項目都是有效的。

+0

nope。你必須在你的nuget包中添加target-framework-support。將net462添加到你的project.json中 –

+0

它可能與postcompile?在文檔中https://docs.microsoft.com/zh-cn/dotnet/articles/core/tools/dotnet-pack沒有這樣的選項。 – pwas

+0

將targetframework net462添加到project.json中。後編譯它是不可能的。添加目標框架後,您的軟件包將獲得支持。 (有net462和netstandard1.6之間的代碼/庫差異) –

回答

1

你應該能夠與加入 「net462」 你project.json增加對.Net框架4.6.2支持:

{ 
    "version": "1.0.0-*", 

    "dependencies": { 
    "NETStandard.Library": "1.6.0" 
    }, 

    "frameworks": { 
    "netstandard1.6": { 
     "imports": "dnxcore50" 
    }, 
    "net462": { 
     "dependencies" : { 
      "System.Runtime": "4.0.20.0" // you may have to add this 
      // add here your dependencies 
     } 
    } 
    }, 

    "scripts": { 
    "postcompile": [ 
     "dotnet pack --no-build --configuration %compile:Configuration%" 
    ] 
    } 
} 

see also my project.json on github with a few supported frameworks

5

如果你檢查.NET的兼容性矩陣標準它看起來像.Net 4.6.2只支持NetStandard 1.5。在框架下,您的目標是針對vNext標記的1.6。

See here for the compatibility matrix to know what version you should target

因此,換句話說,如果你改變你的配置你應該能夠自由地引用庫中的以下內容:

"frameworks": 
{ 
    "netstandard1.5": {} 
} 

你並不需要添加提示另一個框架型樣在另一個答案中,因爲4.6.2應該能夠引用一個1.5標準。

+0

與此有關的另一個大問題,如果您打包自己的nuget包,請小心「全局」nuget緩存你的用戶文件夾,如果你意外地結束了一個遺留軟件包的配置不正確,它可能會讓你撓頭一段時間,只有VS的鈍角錯誤... –

相關問題