如何在使用msbuild pack时将本地DLL引用包含到NuGet包中?

8
我们有几个项目需要包含一些静态 DLL。因此,项目文件包括以下代码:
   <ItemGroup>
     <Reference Include="..\_Solutions\dependencies\abc123.dll" />
     <Reference Include="..\_Solutions\dependencies\def456.dll" />
     <Reference Include="System.Web" />
   </ItemGroup>

期望结果:

我们期望这两个dll文件abc123.dlldef456.dll会在nupkg文件中找到。

实际情况:

然而,nupkg文件并不包括abc123.dlldef456.dll文件。

2个回答

18

用户可以在NuGet包中始终包含自定义内容。像这样:

<ItemGroup>
  <Content Include="$(OutputPath)\ReferencedLib.dll">
    <Pack>true</Pack>
    <PackagePath>lib\$(TargetFramework)</PackagePath>
  </Content>
</ItemGroup>

如果你的目标是多个框架:

<PropertyGroup>
  <TargetFrameworks>netstandard2.0;netstandard1.6</TargetFrameworks>
  <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);IncludeReferencedProjectInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="IncludeReferencedProjectInPackage" Condition="'$(IncludeBuildOutput)' != 'false'">
  <ItemGroup>
    <TfmSpecificPackageFile Include="$(OutputPath)\ReferencedLib.dll" PackagePath="lib/$(TargetFramework)" />
  </ItemGroup>
</Target>

0
如何在调用msbuild pack时将本地DLL引用包含到NuGet包中?
根据GitHub上的问题,目前NuGet不直接支持此功能。
我的建议是使用.nuspec文件进行解决:

NuGet允许您通过设置项目中的属性来禁用自动生成 .nuspec文件和自动收集文件,同时还可以传递替换令牌以解析 .nuspec文件。

详细信息请参见Martin的答案

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接