batch-filemsbuildassemblyinfomsbuildextensionpack

AssemblyInfo not working when using variables for MSBuild


I have the following line that works great

<AssemblyInfo AssemblyInfoFiles="$(MSBuildProjectDirectory)\DesktopAgent\properties\AssemblyInfo.cs" 
              AssemblyCopyright="Copyright 2012 Alpine Access" 
              AssemblyVersion="1.0.0.56"
              AssemblyFileVersion="1.0.0.56">
</AssemblyInfo>

I try instead to feed in the line like this but this does not work

<AssemblyInfo AssemblyInfoFiles="$(MSBuildProjectDirectory)\DesktopAgent\properties\AssemblyInfo.cs" 
              AssemblyCopyright="Copyright 2012 Alpine Access" 
              AssemblyVersion="$(VersionNumber)"
              AssemblyFileVersion="$(VersionNumber)">
</AssemblyInfo>

The version number in my assemblyinfo file is 1.0.0.32 so in the first case, I actually see it change but the second case is not working :(.

I have a bat file that has this line in it

msbuild /property:version=%1;anotherProperty=value project.build

and I run the command like

build.bat 1.0.0.61

and it does not work :(. Any ideas why it breaks when using properties?


Solution

  • VersionNumber must be defined as a property in the project file:

      <PropertyGroup>
        <!-- properties -->
        <VersionNumber Condition="'$(VersionNumber)' == ''">1.0.0.0</VersionNumber>
      </PropertyGroup>
    

    Then the command must set the same property:

    msbuild your.csproj /property:VersionNumber=%1