2017-05-09 11 views
0

.NET 4.5プロジェクトがリリースビルドされているときにVS2017のcsprojファイルを修正してNugetパッケージを作成しました。次の自動化ステップは、このパッケージをネットワーク共有上の私用フィードに追加することです。msbuildのnupkgバージョン番号を取得する

<Exec Command="nuget.exe pack -Properties &quot;Configuration=Release&quot; -Symbols $(ProjectName).csproj" /> 
<Exec Command="nuget.exe add $(ProjectName).$(ProductVersion).nupkg -source \\MYSERVER\Nuget packages" /> 

ライン1つの作品とフォームproductname.nn.nn.nn.nnのnupkgファイルを生成します。ここで私が使用しているコマンドです。

しかし、2行目はProductBersionトークン(私の一部の推測でした)のの値を返していません。

MSBUILDトークン(それ自体は知っておくと便利でしょう)の参照を見つけるのに苦労しましたが、私が本当に知る必要があるのは、バージョンの正しいMSBUILDトークン/変数/プロパティです。生成されたNugetパッケージと同じ値です。

+0

を読ん

は、統合MSBuildのnugetサポートした "新世界" SDKベースのcsprojはこれです(WITH'始まる<プロジェクトSDK = ".."> ')または古典的なcsproj + nuspecですか?最初のものには '$(PackageVersion)'があります –

+0

旧式のものではありません。私はとにかくそれを行ったが、バージョン番号は返されませんでした。 – CrispinH

答えて

0

このマクロを使用してアセンブリバージョンを取得できます。私はマーティン・ウルリッヒによって提案$(PackageVersion)を調査したが、それもNuget 4.10インストールして、古いプロジェクトで作業するつもりはない

<!--Macro to get the version --> 
<Target Name="PostBuildMacros"> 
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)"> 
     <Output TaskParameter="Assemblies" ItemName="CurrentAssembly" /> 
    </GetAssemblyIdentity> 
    <ItemGroup> 
     <VersionNumber Include="%(CurrentAssembly.Version)" /> 
    </ItemGroup> 
</Target> 
<!-- override PostBuildEvent to call PostBuildMacros --> 
<PropertyGroup> 
    <PostBuildEventDependsOn> 
     $(PostBuildEventDependsOn); 
     PostBuildMacros; 
    </PostBuildEventDependsOn> 
    <PostBuildEvent> 
     ... 
    </PostBuildEvent> 
</PropertyGroup> 
0

例えばポストビルドイベントの前にそれを呼び出します。また、私はTroopersのサンプルを私が望んでいた方法で動作させることができませんでした。投稿の1つにバリエーションがありました。here。私はファイルバージョンとは対照的に、アセンブリバージョンを私に与えるように修正しました。

<UsingTask TaskName="GetVersionParts" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll"> 
    <ParameterGroup> 
     <AssemblyPath ParameterType="System.String" Required="true" /> 
     <MajorVersion ParameterType="System.Int32" Output="true" /> 
     <MinorVersion ParameterType="System.Int32" Output="true" /> 
     <BuildVersion ParameterType="System.Int32" Output="true" /> 
    </ParameterGroup> 
    <Task> 
     <Using Namespace="System.Reflection" /> 
     <Code Type="Fragment" Language="cs"> 
     <![CDATA[ 
     Version v = AssemblyName.GetAssemblyName(this.AssemblyPath).Version; 

     this.MajorVersion = v.Major; 
     this.MinorVersion = v.Minor; 
     this.BuildVersion = v.Build;  
     ]]> 
     </Code> 
    </Task> 
    </UsingTask> 
    <Target Name="AfterBuild" Condition=" '$(Configuration)' == 'Release'"> 
    <Message Text="**** After-build process starting ****" /> 
    <Exec Command="nuget.exe pack -Properties &quot;Configuration=Release&quot; -Symbols $(ProjectName).csproj" /> 
    <GetVersionParts AssemblyPath="$(OutputPath)$(AssemblyName).dll"> 
     <Output TaskParameter="MajorVersion" PropertyName="MajorVersionNumber" /> 
     <Output TaskParameter="MinorVersion" PropertyName="MinorVersionNumber" /> 
     <Output TaskParameter="BuildVersion" PropertyName="BuildVersionNumber" /> 
    </GetVersionParts> 
    <Exec Command="nuget.exe add $(MSBuildProjectName).$(MajorVersionNumber).$(MinorVersionNumber).$(BuildVersionNumber).nupkg -source &quot;\\My feed server\Shared location&quot;" /> 
    <Exec Command="move *.symbols.nupkg &quot;\\My feed server\Shared location\Symbols&quot;" /> 
    <Message Text="**** After-build process completed ****" /> 
    </Target> 

これは機能しますが、私はそれがより簡単であると感じるのを助けることはできません。さらに

https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks https://docs.microsoft.com/en-us/visualstudio/msbuild/common-msbuild-project-properties https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference#add

関連する問題