【问题标题】:How to add <frameworkAssembly> into nuget package generated from csproj如何将 <frameworkAssembly> 添加到从 csproj 生成的 nuget 包中
【发布时间】:2017-11-11 15:28:30
【问题描述】:

我正在使用 VS2017 和新的 csproj 文件格式来创建 nuget 包。

在我的 csproj 文件中,我有以下内容:

<ItemGroup>
   <Reference Include="System.Net" />
</ItemGroup>

当您构建它时,它工作正常(TargetFrameworks == net45)。但是当我将它打包在 nuget 包中时,我希望目标包将其作为

<frameworkAssemblies>
  <frameworkAssembly assemblyName="System.Net" targetFramework="net45" />
</frameworkAssemblies>

我怎样才能用这个新工具做到这一点?

【问题讨论】:

    标签: msbuild nuget visual-studio-2017


    【解决方案1】:

    这是当前1.0.* 工具的限制。在即将推出的“.NET SDK”版本1.1.*2.0.* 中,这将自动完成,所有&lt;Reference&gt; 元素都作为框架程序集添加到生成的NuGet 包中(除非它们被标记为@987654326 @)。这些更改也将成为 VS 2017 15.3 的一部分(在撰写本文时尚未发布)。请注意,我说的是工具(安装了 SDK 的dotnet --version)版本,而不是 .NET Core 运行时版本。

    有一种方法可以使用包目标的当前预览包,覆盖 SDK 提供的那些 - 请注意,这是一种非常老套的方式,一旦您使用新的 1.1 或 2.0 工具,就应该将其删除。

    <Project>
      <PropertyGroup>
        <NuGetBuildTasksPackTargets>junk-value-to-avoid-conflicts</NuGetBuildTasksPackTargets>
      </PropertyGroup>
      <Import Project="Sdk.props" Sdk="Microsoft.NET.Sdk" />
    
      <!-- All your project's other content here -->
    
      <ItemGroup>
        <PackageReference Include="NuGet.Build.Tasks.Pack" Version="4.3.0-preview1-4045" PrivateAssets="All" />
      </ItemGroup>
      <Import Project="Sdk.targets" Sdk="Microsoft.NET.Sdk" />
    </Project>
    

    另请参阅related GitHub issue on the NuGet repo,此解决方法的信息来源于此。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-05
      • 1970-01-01
      • 2022-01-12
      • 2016-11-14
      • 2017-11-01
      • 1970-01-01
      相关资源
      最近更新 更多