Project generates a nuget package that depends on another project that does not create a nuget package

那年仲夏 提交于 2019-12-06 03:47:53

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.

See https://github.com/nuget/home/issues/3891#issuecomment-459848847 for more information

<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>

If I understood correctly, the referenced project assemblies are not getting included in the nuget package.

You can try below command while generating nuget package by using below command:

nuget pack projectfile.csproj -IncludeReferencedProjects

This should include P2.dll in the nuget. Refer this MSDN page for more details.

Hope this helps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!