Automaticaly update the nuspec version tag

Topics: General
Apr 17, 2013 at 11:05 AM
Dear all,

I'm looking for a way to automatically update the version tag in a .nuspec file with the assembly version produced during a VS project build.

I am thinking about putting some kind of VS variable into my nuspec file that might be evaluated at compile time like :
<version>$(ASSEMBLY_VERSION)</version>
I'm not sure if VS support that, or if a such variable is provided.

An alternative could be the TFS changeset like $Revision$ for svn
Does somebody already did that? Or someone kind enough to help me out?

Also is there any reasons why I should not do that?

Thank you
Apr 17, 2013 at 2:03 PM
Edited Apr 17, 2013 at 2:03 PM
I ended up by writing a custom a target responsible to substitute the string "$version$" in a nuspec template and output the whole thing in a new file. I really like being lazy :p
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
    <GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    <Exec Command="echo %(AssemblyVersion.Version)" />
    <Message Text="Released %(AssemblyVersion.Version)" Importance="high" />
    <PropertyGroup>
      <ToFind>$version$</ToFind>
      <ToReplace>%(AssemblyVersion.Version)</ToReplace>
    </PropertyGroup>
    <ReadLinesFromFile File="Sample.dll.nuspec.template">
      <Output TaskParameter="Lines" ItemName="ItemsFromFile" />
    </ReadLinesFromFile>
    <WriteLinesToFile File="Sample.dll.nuspec" Lines="@(ItemsFromFile-&gt;Replace($(ToFind),$(ToReplace)))" Overwrite="true" Encoding="Unicode" />
  </Target>
Apr 18, 2013 at 12:15 AM
The nuget.exe pack command supports the so-called replacement token. You can use this syntax:
<version>$version$</version> 
in your nuspec file.

See this page for more information: http://docs.nuget.org/docs/reference/nuspec-reference.
Apr 18, 2013 at 8:27 AM
Oh crap I feel stupid ....

Well thank you for the instructive reply. I will have to read the doc now. I'm kind of lost when I can't man things :)