Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Version from AssemblyInfo in MSBuild

I am trying to create/push nuget package through visual studio build process as explained here.

Building package is easy:

<Exec WorkingDirectory="$(ProjectDir)" Command="$(NuGetApp) pack $(ProjectFile) -OutputDirectory $(Deploy) -Verbose -Prop Configuration=Release"/>

I see .nupkg file in $(Deploy) folder.

But to be able to push it, I need $(AssemblyVersion) to use it in :

<Exec Command="$(NuGetApp) push $(ProjectName)$(AssemblyVersion) -s $(NugetServer) $(NugetKey)" />

I tried XMLRead to fetch the value, but value in NugetSpecFile is "$version$" instead of version from AssemblyInfo.cs.

<XmlRead XPath="/package/metadata/version" XmlFileName="$(NuSpecFile)">
      <Output TaskParameter="Value" PropertyName="AssemblyVersion" />
    </XmlRead>

How do I access version so I could use it in "nuget push"?

like image 527
NiTiN Avatar asked May 22 '12 20:05

NiTiN


1 Answers

This i'll do it:

<PropertyGroup>
    <MyAssemblies>somedll\the.dll</MyAssemblies>
  </PropertyGroup>

 <Target Name="RetrieveIdentities">
    <GetAssemblyIdentity
        AssemblyFiles="$(MyAssemblies)">
      <Output
          TaskParameter="Assemblies"
          ItemName="MyAssemblyIdentities"/>
    </GetAssemblyIdentity>

    <Message Text="Files: %(MyAssemblyIdentities.Version)"/>
  </Target>

Altered from here: MSBuild Task to read version of dll

like image 114
James Woolfenden Avatar answered Sep 30 '22 22:09

James Woolfenden