我在我的项目 .csproj
的 AfterBuild 部分添加了一个命令文件,如果它是一个发布配置,它会自动创建一个 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 脚本的情况下做到这一点?
最佳答案
有一个answer to a previous question它显示了如何在构建后事件中公开版本号。结合你已有的,你可以执行 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 - 如何在 Visual Studio 中将 'nuget add' 作为构建后事件运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38000691/