2016-06-23 31 views
3

我在項目的.csproj文件的AfterBuild部分中添加了一個命令,如果它是發佈配置,它會自動創建一個NuGet包。正如下面的代碼片段所述,這部分工作正常。如何在Visual Studio中運行'nuget add'作爲生成後事件?

<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腳本?

回答

2

有一個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> 
相關問題