2016-06-23 32 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パッケージをコピーするために、追加のnuget add $(NugetFileName) -source c:\NugetLocalコマンドを追加したいと思います。残念ながら、$(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> 
関連する問題