RB.*_*RB. 3 c# msbuild csproj nuget
如果我有一个构建nuget程序包的项目(P1),并且使它依赖于没有构建nuget程序包的项目(P2),则生成的程序包仍将P2 称为nuget程序包。
将以下行添加到P1.csproj(以使其构建nuget包)
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
请注意,NuGet程序包依赖于另一个称为P2的NuGet程序包。但是,该程序包不存在,也永远不会存在,因为我没有告诉P2项目构建nuget程序包。
如何强制将P2.dll包含在P1.nupkg的lib文件夹中?理想情况下,它将仅对本身不会创建nuget包的引用强制使用它。
nuget pack。我正在使用dotnet buildVisual Studio或Visual Studio构建nuget包,因此不适用。一种解决方法是将您不希望包含的任何资产标记为<PrivateAssets>all</PrivateAssets>,然后在项目文件中包含以下代码。
有关更多信息,请参见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>
Run Code Online (Sandbox Code Playgroud)
如果我理解正确,引用的项目程序集不会包含在 nuget 包中。
您可以在使用以下命令生成 nuget 包时尝试以下命令:
nuget pack projectfile.csproj -IncludeReferencedProjects
Run Code Online (Sandbox Code Playgroud)
这应该包括 nuget 中的 P2.dll。 请参阅此 MSDN 页面了解更多详细信息。
希望这可以帮助。