针对多个框架的dotnet包

时间:2017-05-03 14:39:33

标签: .net nuget .net-core

我有一个针对2个框架的dotnet核心项目:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>netcoreapp1.0;net45</TargetFramework>
    </PropertyGroup>
</Project>

使用dotnet build -c Release -f net45|netcoreapp1.0我可以为所需的framewok构建我的类库。 但我无法找到如何使用dotnet-pack命令执行相同的操作。我因以下错误而失败:

C:\Program Files\dotnet\sdk\1.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(84,5): error : Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='netcoreapp1.0'. They must be specified explicitly. [C:\Users\olduh\sly\sly\sly\sly.csproj]

构建nuget包时有没有办法建立多目标框架?

感谢您的回答,

奥利弗

1 个答案:

答案 0 :(得分:6)

对于多目标定位,请使用复数TargetFrameworks属性来提供框架列表。 TargetFramework(单数)只接受一个框架。如果您在属性名称上修复了缺少的sdotnet pack -c Release应该按预期工作 - 而无需指定任何框架参数。

添加其他框架时,您可能没有更新该属性。通过指定-f选项,您已覆盖此属性以使其正常工作,但我想dotnet build将失败并出现相同的错误。

相关问题