Project生成一个nuget包,该包依赖于另一个不创建nuget包的项目 [英] Project generates a nuget package that depends on another project that does not create a nuget package

查看:98
本文介绍了Project生成一个nuget包,该包依赖于另一个不创建nuget包的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个构建nuget程序包的项目(P1),而我依赖于一个不构建nuget程序包的项目(P2),则生成的程序包仍将P2 称为nuget包.

If I have a project (P1) that builds a nuget package, and I make it depend on a project (P2) that doesn't build a nuget package, the generated package will still reference P2 as a nuget package.

  • 使用2个C#项目(P1和P2)创建解决方案
  • 让P1依赖于P2.
  • 将以下行添加到P1.csproj(以使其构建一个nuget包)

  • Create a solution with 2 C# projects (P1 and P2)
  • Make P1 depend on P2.
  • Add the following line to P1.csproj (to make it build a nuget package)

<GeneratePackageOnBuild>true</GeneratePackageOnBuild>

请注意,NuGet程序包依赖于另一个称为P2的NuGet程序包.但是,该程序包不存在,也永远不会存在,因为我没有告诉P2项目构建nuget程序包.

Note that the NuGet package depends on another NuGet package called P2. However, that package does not exist, and will never exist, as I have not told the P2 project to build a nuget package.

如何强制将P2.dll包含在P1.nupkg的lib文件夹中?理想情况下,它将仅对自己创建nuget包的引用强制使用它.

How do I force P2.dll to be included in P1.nupkg's lib folder? Ideally it will force it only for references that don't create a nuget package themselves.

  • Package .NET Standard library as Nuget package and include all project dependencies / references is related, but assumes the use of nuget pack. I am using dotnet build or Visual Studio to build the nuget package, so doesn't apply.
  • This GitHub query is pretty much the same as my issue.

推荐答案

一种解决方法是将您不希望包含的任何资产标记为<PrivateAssets>all</PrivateAssets>,然后在项目文件中包含以下代码.

One workaround is to mark any assets you don't want to include as <PrivateAssets>all</PrivateAssets>, and then include the below code in your project file.

请参见 https://github.com/nuget/home/issues/3891 #issuecomment-459848847 了解更多信息

<ItemGroup>
  <ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj">
    <PrivateAssets>all</PrivateAssets>
  </ProjectReference>
</ItemGroup>

<!--
  The following solves the problem that 'dotnet pack' does not include the DLLs from referenced projects.
  See https://github.com/NuGet/Home/issues/3891 for a description of the problem
  and for newer versions / workarounds / built-in methods.
-->
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
  <!-- include PDBs in the NuGet package -->
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="ResolveReferences">
    <ItemGroup>
        <BuildOutputInPackage Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'all'))" />
    </ItemGroup>
</Target>

这篇关于Project生成一个nuget包,该包依赖于另一个不创建nuget包的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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