有没有办法强制 dotnet pack
包含所有引用的程序集(即 project.json 中的所有依赖项)?
我认为这与以下问题有关:
有没有办法强制 dotnet pack
包含所有引用的程序集(即 project.json 中的所有依赖项)?
我认为这与以下问题有关:
PrivateAssets="all"
,根据包的README进行更新。
<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>
PrivateAssets="all"
来标记所依赖的项目引用,然后它就可以正常工作了。我一直在寻找这个答案,但很不爽地发现找不到一个明显的解决方案。对于我最好的解决方法是创建nuspec,在spec中添加我想要在nupkg中的DLL列表,然后使用dotnet pack进行构建。我在这里创建了一个简单的示例和readme - nuget示例应用程序
.csproj
文件中所有内容的作用。在.nuspec
文件中包含有关依赖项的信息感觉更自然。 - OutstandingBill.csproj
文件中,在<PropertyGroup>
中有<NuspecFile>./relative/path/to.nuspec</NuspecFile>
允许我们使用dotnet pack
命令与.nuspec
文件。 - Yas Ikeda解决问题的另一种方法是创建一个定制的.targets文件并将其包含在项目中。您可以添加一些msbuild指令来包含需要放入软件包中的文件。这里有一些文档,告诉您如何操作,以下是一个简短的示例:
<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>
我在构建系统上安装了章鱼构建工具,因此我使用octo pack
创建软件包。虽然这基本上与调用老旧的nuget.exe
相同。
https://octopus.com/docs/packaging-applications/create-packages/octopus-cli
dotnet publish
命令即可? - Efrain<dependencies>
中移除。<dependencies>
部分。<PropertyGroup>
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);CopyProjectReferencesToPackage</TargetsForTfmSpecificBuildOutput>
</PropertyGroup>
<Target Name="CopyProjectReferencesToPackage" DependsOnTargets="BuildOnlySettings;ResolveReferences">
<ItemGroup>
<BuildOutputInPackage Include="$(OutputPath)MyReference.dll" TargetPath=""/>
</ItemGroup>
</Target>
dotnet pack
命令时非常有效。希望这能对您有所帮助。
nuget pack yournuspecfile.nuspec -properties Configuration=Release -IncludeReferencedProjects
或者您的其他命令。
--no-build
标志不兼容(在 AppVeyor 上是默认行为),因为它由于DependsOn
的原因隐式地调用了(重新)构建。dotnet pack -c release -o pack --no-build
会产生错误error NETSDK1085: The 'NoBuild' property was set to true but the 'Build' target was invoked.
。 - riezebosch