(Please excuse me if I get any terms mixed up here - I am a Java developer, new to .Net and C#. Please add/correct any tags on this question if need be.)

I am using an MSBuild script to build my project. One of the tasks is to write the assembly info:

<Target Name="UpdateAssemblyInfo">
    <Message Text="Updating assemblies to file version $(AssemblyVersion) ($(AssemblyFileVersion))" Importance="high"/>
    <AssemblyInfo CodeLanguage="CS"
                  OutputFile="SharedAssemblyInfo.cs" 
                  AssemblyVersion="$(AssemblyVersion)"
                  AssemblyFileVersion="$(AssemblyFileVersion)"
                  AssemblyProduct="SVN revision $(BUILD_NUMBER)"/>
</Target>

This converts SharedAssemblyInfo.cs from this:

[assembly: System.Reflection.AssemblyVersion("0.0.0")]

To this:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.18063
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[assembly: System.Reflection.AssemblyVersion("1.4.0")]
[assembly: System.Reflection.AssemblyFileVersion("1.4.0.85725")]
[assembly: System.Reflection.AssemblyProduct("SVN revision 85725")]

So far so good. Except I see the following message in the build log of TeamCity:

CSC warning CS1607: Assembly generation -- The version '1.4.0.85725' specified for the 'file version' is not in the normal 'major.minor.build.revision' format

Why am I getting this warning, when the format of the version appears to follow the format specified in the warning message?

2

There are 2 answers

1
Mihai Hantea On BEST ANSWER

The reason why you are getting the error is because the revision number is greater than 65534.

0
Richard On

Why am I getting this warning, when the format of the version appears to follow the format specified in the warning message?

Re-read that warning, with some added emphasis:

the normal 'major.minor.build.revision' format

.NET version numbers have FOUR parts, not three.

The System.Version type used for this will process versions of fewer types, but it is possible for code using System.Version to check and be stricter.

Additional, as noted by Mihai, elements of the version are limited to System.UInt16.MaxValue (65535): this is a Windows API limitation (in System.Version each element is a System.Int32) related to the native VS_FIXEDFILEINFO1 resource that the compiler inserts into the assembly from various assembly attributes. This allows tools like Windows Explorer to read the version.

Summary:

  • There should be four parts to the version.
  • Each part should be in the range [0, 65535].

1 The version is stored across two DWORD members: one for Major and Minor parts, the other for Build and Revision (albeit not given those names in Win32).