使用 dotnet pack 包含所有依赖项
Include all dependencies using dotnet pack
有什么方法可以强制 dotnet pack
包含所有引用的程序集(project.json 中的所有依赖项)?
我认为这是相关的:
根据设计,每个依赖项都需要单独打包。
有些人将他们发布文件夹中的 dll 作为文件包含在他们的包选项中以解决设计问题。
但是,为每个单独的依赖项创建包会导致代码更易于版本控制、维护、更新等...
希望对您有所帮助。
nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects
或您的命令。
我一直在寻找这个答案,但当我找不到明显的答案时感到很恼火。最适合我的解决方案是创建一个 nuspec,将 nupkg 中我想要的 DLL 列表添加到该规范,然后使用 dotnet pack 进行构建。我在这里创建了一个简单的示例和自述文件 - nuget sample app
截至 2020 年,还没有官方支持的方法来执行此操作。然而各种人想出了办法实现它,目前最好的办法是安装一个NuGet package prepared by the amazing Teroneko. Then all you need to do is edit your .csproj to update all your project to be flagged with PrivateAssets="all"
, as per the package README.
如果您无法安装上述 NuGet 包,您可以通过编辑 by editing your .csproj
to include the following 来达到同样的效果(再一次,这是由 Teroneko 发现的——这实际上就是他创建的 NuGet 包所做的):
<Project>
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
</ItemGroup>
<!-- Print batches for debug purposes -->
<Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" />
<ItemGroup>
<!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/>
</ItemGroup>
</Target>
</Project>
与包一样,您随后在 .csproj 中使用 PrivateAssets="all"
标记依赖的项目引用,并且它 Just Works(tm)。
因为我在构建系统上安装了 Octopus 构建工具,所以我使用 octo pack
来创建包。尽管这与调用 good old nuget.exe
.
基本相同
https://octopus.com/docs/packaging-applications/create-packages/octopus-cli
该问题的另一个解决方案是创建自定义 .targets 文件以包含在您的项目中。您可以添加一些 msbuild 指令以将您需要的文件包含在包中。有一些关于如何做到这一点的 documentation here,这里是一个简短的例子
<PropertyGroup Condition="$(PackAsComponent) != ''">
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CustomBuildOutput</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);CustomContentInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="CustomBuildOutput">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)*.dll" Exclude="$(TargetPath)" />
<BuildOutputInPackage Include="$(OutputPath)*.pdb" />
<BuildOutputInPackage Include="$(OutputPath)*.exe" Exclude="$(TargetPath)" />
</ItemGroup>
</Target>
<Target Name="CustomContentInPackage">
<ItemGroup>
<TfmSpecificPackageFile Include="abc.txt">
<PackagePath>mycontent/$(TargetFramework)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
基本上我在我的项目中设置 PackAsComponent 属性 时激活它。
这会 100% 保留“dotnet pack”功能,而无需指定任何参数。
有什么方法可以强制 dotnet pack
包含所有引用的程序集(project.json 中的所有依赖项)?
我认为这是相关的:
根据设计,每个依赖项都需要单独打包。
有些人将他们发布文件夹中的 dll 作为文件包含在他们的包选项中以解决设计问题。
但是,为每个单独的依赖项创建包会导致代码更易于版本控制、维护、更新等...
希望对您有所帮助。
nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects
或您的命令。
我一直在寻找这个答案,但当我找不到明显的答案时感到很恼火。最适合我的解决方案是创建一个 nuspec,将 nupkg 中我想要的 DLL 列表添加到该规范,然后使用 dotnet pack 进行构建。我在这里创建了一个简单的示例和自述文件 - nuget sample app
截至 2020 年,还没有官方支持的方法来执行此操作。然而各种人想出了办法实现它,目前最好的办法是安装一个NuGet package prepared by the amazing Teroneko. Then all you need to do is edit your .csproj to update all your project to be flagged with PrivateAssets="all"
, as per the package README.
如果您无法安装上述 NuGet 包,您可以通过编辑 by editing your .csproj
to include the following 来达到同样的效果(再一次,这是由 Teroneko 发现的——这实际上就是他创建的 NuGet 包所做的):
<Project>
<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<!-- Filter out unnecessary files -->
<_ReferenceCopyLocalPaths Include="@(ReferenceCopyLocalPaths->WithMetadataValue('ReferenceSourceTarget', 'ProjectReference')->WithMetadataValue('PrivateAssets', 'All'))"/>
</ItemGroup>
<!-- Print batches for debug purposes -->
<Message Text="Batch for .nupkg: ReferenceCopyLocalPaths = @(_ReferenceCopyLocalPaths), ReferenceCopyLocalPaths.DestinationSubDirectory = %(_ReferenceCopyLocalPaths.DestinationSubDirectory) Filename = %(_ReferenceCopyLocalPaths.Filename) Extension = %(_ReferenceCopyLocalPaths.Extension)" Importance="High" Condition="'@(_ReferenceCopyLocalPaths)' != ''" />
<ItemGroup>
<!-- Add file to package with consideration of sub folder. If empty, the root folder is chosen. -->
<BuildOutputInPackage Include="@(_ReferenceCopyLocalPaths)" TargetPath="%(_ReferenceCopyLocalPaths.DestinationSubDirectory)"/>
</ItemGroup>
</Target>
</Project>
与包一样,您随后在 .csproj 中使用 PrivateAssets="all"
标记依赖的项目引用,并且它 Just Works(tm)。
因为我在构建系统上安装了 Octopus 构建工具,所以我使用 octo pack
来创建包。尽管这与调用 good old nuget.exe
.
https://octopus.com/docs/packaging-applications/create-packages/octopus-cli
该问题的另一个解决方案是创建自定义 .targets 文件以包含在您的项目中。您可以添加一些 msbuild 指令以将您需要的文件包含在包中。有一些关于如何做到这一点的 documentation here,这里是一个简短的例子
<PropertyGroup Condition="$(PackAsComponent) != ''">
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CustomBuildOutput</TargetsForTfmSpecificBuildOutput>
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);CustomContentInPackage</TargetsForTfmSpecificContentInPackage>
</PropertyGroup>
<Target Name="CustomBuildOutput">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)*.dll" Exclude="$(TargetPath)" />
<BuildOutputInPackage Include="$(OutputPath)*.pdb" />
<BuildOutputInPackage Include="$(OutputPath)*.exe" Exclude="$(TargetPath)" />
</ItemGroup>
</Target>
<Target Name="CustomContentInPackage">
<ItemGroup>
<TfmSpecificPackageFile Include="abc.txt">
<PackagePath>mycontent/$(TargetFramework)</PackagePath>
</TfmSpecificPackageFile>
</ItemGroup>
</Target>
基本上我在我的项目中设置 PackAsComponent 属性 时激活它。 这会 100% 保留“dotnet pack”功能,而无需指定任何参数。