[英]How to run 'nuget add' as a post-build event in Visual Studio?
我已经在项目的.csproj
文件的AfterBuild部分添加了一个命令,如果它是Release配置,它会自动创建一个NuGet包。 这部分,如下面的代码片段所示,运行良好。
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
<Exec Command="nuget pack $(ProjectFileName) -IncludeReferencedProjects -Prop Configuration=Release"></Exec>
</Target>
我现在想添加一个额外的nuget add $(NugetFileName) -source c:\\NugetLocal
命令来将NuGet包复制到我的本地存储库。 不幸的是, $(NugetFileName)
宏不存在。 我可以使用$(TargetName)
宏结合.nupkg
但包名称包含程序集版本号,它似乎没有一个方便的宏。 有没有办法在不使用MSBuild脚本的情况下执行此操作?
回答上一个问题 ,该问题显示了如何在after build事件中公开版本号。 将它与您已经拥有的相结合,您可以执行带有版本号的nuget add
命令:
<Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
</GetAssemblyIdentity>
<Exec Command="nuget pack $(ProjectFileName) -IncludeReferencedProjects -Prop Configuration=Release"></Exec>
<Exec Command="nuget add $(TargetName).%(AssemblyVersion.Version).nupkg -Source C:\NugetLocal"></Exec>
</Target>
在Visual Studio 2019中添加了在构建项目时自动创建Nuget包,因此您不必在后期构建事件中创建它。 将包添加到本地存储库它只是.csproj文件中的一行代码
<Target Name="NugetAdd" AfterTargets="Pack">
<exec command="nuget add $(OutputPath)$(PackageId).$(PackageVersion).nupkg -source d:\NuGetLocal" />
</Target>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.