0

When using [assembly: AssemblyVersion("1.1.*")] in AssemblyInfo.cs I know that the build and revision number gets replaced by meaningful values. However is there a way to obtain these values somewhere else? I would like to keep the AssemblyVersion stable but still be able to have these values somewhere burned into the assembly.

I've found topics of extracting data from the PE Header but I would prefer something less intrusive.

Samuel
  • 6,126
  • 35
  • 70

2 Answers2

1

The approach I've normally used is to treat AssemblyInfo.cs as the endpoint of such version numbers, not the start point.

So I'd start with a file that gets auto-generated or modified by the build process (eg by your CI system), eg

public static class BuildNumber
{
    public const string Build = "<<git branch>>";
    public const string Revision = "<<CI build number>>";
}

Then I have a versions class that holds all the version info:

public static class Versions
{
    public static int Major { get { return Convert.ToInt32(MajorString); } }
    public static int Minor { get { return Convert.ToInt32(MinorString); } }
    public static int Build { get { return Convert.ToInt32(BuildNumber.Build); } }
    public static int Revision { get { return Convert.ToInt32(BuildNumber.Revision); } }

    public const string AssemblyVersion = MajorString + "." + MinorString + "." +
        BuildNumber.Build + ". " + BuildNumber.Revision;

    private const string MajorString = "1";
    private const string MinorString = "2";
}

Finally, you put the following in your AssemblyInfo.cs files:

[assembly: AssemblyVersion(Versions.AssemblyVersion)]

That way, the version info is then available within your code too, eg for displaying the version info in an about box.

David Arno
  • 42,717
  • 16
  • 86
  • 131
0

AssemblyFileVersion - see Microsoft KB at http://support.microsoft.com/kb/556041

It is used the same way as AssemblyVersion:

[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")] 

AssemblyVersion is used by the GAC for strong naming etc., while AssemblyFileVersion is not.

lgaud
  • 2,430
  • 20
  • 30
  • AssemblyFileVersion does not support the build and revision number asterisk I need. You get a warning by doing that. see http://stackoverflow.com/questions/4359597/whats-wrong-with-my-visual-studio-auto-incrementing-build-number-syntax – Samuel Oct 29 '13 at 13:47
  • Ah, sorry - we have our version bumping in TFS, didn't realize it didn't work in VS. – lgaud Oct 29 '13 at 13:54
  • Can you hint me how TFS applies a version to the FileVersion? I wasn't aware it differed from the use of asterisk. Or does TFS not complain about the asterisk in the FileVersion attribute? – Samuel Oct 29 '13 at 14:17