Visual Studio 2017 Nuget 包将项目引用排除为另一个 nuget 引用,而是添加程序集 [英] Visual Studio 2017 Nuget pack exclude Project reference as another nuget reference, add assembly instead

查看:15
本文介绍了Visual Studio 2017 Nuget 包将项目引用排除为另一个 nuget 引用,而是添加程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们在 Visual Studio 2017 中创建一个 nuget 包时,它默认将项目引用添加为另一个 nuget 引用.我们如何在创建包时禁用它,而不是:

When we create a nuget package in visual studio 2017, it adds the project references as another nuget reference by default. How can we disable that while creating package and instead:

  • 选择不同的包名
  • 在创建包时包含项目的 dll

推荐答案

PackageReference 可以用 PrivateAssets="All" 标记,以确保它不会结束打包时作为使用库的 NuGet 依赖项.然后消费库可以使用自定义目标将文件添加到构建的 nuget 包中.csproj 文件的完整示例如下所示:

The PackageReference can be marked with PrivateAssets="All" to ensure that it doesn't end up as a NuGet dependency of the consuming library when packed. Then the consuming library can use a custom target to add files to the built nuget package. A full example for the csproj file could look like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);IncludeP2PAssets</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <ItemGroup>
    <ProjectReference Include="..	estprivatelib	estprivatelib.csproj" PrivateAssets="All" />
  </ItemGroup>

  <Target Name="IncludeP2PAssets">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutputPath)	estprivatelib.dll" />
    </ItemGroup>
  </Target>
</Project>

其中 testprivatelib.csproj 是一个构建 DLL 的项目,您希望将其另外包含到 .nupkg 文件中,并且不为该引用的项目发布额外的 NuGet 包.

Where testprivatelib.csproj is a project that builds a DLL that you want to additionally include into the .nupkg file and not publish an extra NuGet package for that referenced project.

指定不同的 NuGet 包更加困难.它需要手动创建一个 .nuspec 文件,使用它来打包 NuGet 包.您可以在 https://github.com/dasMulli/nuget-include-p2p-example/tree/master/LibA - LibA.csproj 设置为使用 LibA.nuspecdotnet pack 被调用时.

Specifying different NuGet packages is more difficult. It requires manually creating a .nuspec file using it to pack a NuGet package. You can see an example how this can be done at https://github.com/dasMulli/nuget-include-p2p-example/tree/master/LibA - the LibA.csproj is set up to use LibA.nuspec when dotnet pack is called.

这篇关于Visual Studio 2017 Nuget 包将项目引用排除为另一个 nuget 引用,而是添加程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆