mare
mare

Reputation: 13083

AssemblyInfo version information asterisks

It says in AssemblyInfo.cs for C# projects that it's possible to specify version information with *

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

I changed it to this:

[assembly: AssemblyVersion("1.0.*.*")]
[assembly: AssemblyFileVersion("1.0.*.*")]

and this is the error I get from the compiler:

error CS0647: Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.*.*' is invalid'
warning CS1607: Assembly generation -- The version '1.0.*.*' specified for the 'file version' is not in the normal 'major.minor.build.revision' format

How does (does it even?) it work?

Upvotes: 56

Views: 39668

Answers (5)

AntonioHL
AntonioHL

Reputation: 718

I have using the '*' in the version for add more information about the application version, build(date) and revision(hours in day) In my code, I use:

Fragment from AssemblyInfo.cs

// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]

In constructor or load event

 Version? ver = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
 if (ver != null)
 {
     var dt = ver.ToDateTime();
     verLabel.Content = string.Format("ver.{0}.0.0.{1} ({2:yy/MM/dd HH:mm})", ver.Major, ver.Minor, dt);
 }

 public static class VersionExtension
 {
     public static DateTime ToDateTime(this Version ver)
     {
         var dt = new DateTime(2000, 1, 1, 0, 0, 0);
         //plus days
         dt = dt.AddDays(ver.Build);
         //plus seconds
         dt = dt.AddSeconds(ver.Revision * 2);
         return dt; 
     }
 }

I use 'Build' value to find the day that the project is compiled, and 'Revision' to get the precise hour.

For determinism, use this

<PropertyGroup>
    <Version>1.0.0</Version>
    <AssemblyVersion>1.0.*</AssemblyVersion>
    <Deterministic>False</Deterministic>
</PropertyGroup>

The right tag is Deterministic!

Upvotes: 0

We B Martians
We B Martians

Reputation: 375

So why does the supplied comment say

// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]

but builds generate CS8357? Somebody didn't get the memo.

Work around:

 1. Close all open documents
 2. In the Solution Explorer, right-click the Project and select Unload Project
 3. In the Solution Explorer, right-click the Project (now marked as unavailable) and select Edit to access the `.CSPROJ` file
 4. In the opened window, find `<Deterministic>true</Deterministic>` and change it to `<Deterministic>false</Deterministic>`
 5. Save the file and ensure that the edit window is closed
 6. In the Solution Explorer, right-click the Project and select Reload Project

Your build (should then) work. :)

Upvotes: 12

fred
fred

Reputation: 763

In my opinion, using [assembly: AssemblyVersion("x.y.z.*")], Patch shouldn't be automatically numbered. Eg:

[assembly: AssemblyVersion("1.2.3.*")]

Using '*' in AssemblyVersion is good, but follow seemver.org we should use * for the revision part from version structure <major version>.<minor version>.<build number>.<revision>).

Given a version number MAJOR.MINOR.PATCH, increment the:

MAJOR version when you make incompatible API changes,

MINOR version when you add functionality in a backwards-compatible manner, and

PATCH version when you make backwards-compatible bug fixes.

Upvotes: 6

Adriano Repetti
Adriano Repetti

Reputation: 67128

Syntax (see MSDN) for "automatic" build number can be:

[assembly: AssemblyVersion("1.0.0.*")]

or:

[assembly: AssemblyVersion("1.0.*")]

* means after this everything is automatic. You can't have automatic build number and fixed revision number then this syntax isn't correct:

[assembly: AssemblyVersion("1.0.*.0")]

For the AssemblyFileVersionAttribute you cannot use the * special character so you have to provide a full and valid version number. Please note that if you do not provide an AssemblyFileVersionAttribute then you'll get the right FileVersionInfo automatically (with the same version of AssemblyVersionAttribute). You need to specify that attribute only if you need to set a different version.

Upvotes: 75

chamos
chamos

Reputation: 351

[assembly: AssemblyVersion("1.0.*")] 
//[assembly: AssemblyFileVersion("1.0.*")] 

just remember to comment the AssemblyFileVersion line, otherwise the automatically generated assembly version will always be "1.0.0.0".

Upvotes: 35

Related Questions