AssemblyInfo version information asterisks

C#.Net

C# Problem Overview


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?

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

[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".

Solution 3 - C#

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. :)

Solution 4 - C#

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.

Solution 5 - C#

I have using the '*' in the version to an easy control version, and for information to the customers. I have a small program that run in handhelds(PointOfSell), sometimes update happen. :-) In my code, I use:

Fragment from AssemblyInfo.cs

// 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 Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
// Need to comment this line, 
//[assembly: AssemblyFileVersion("1.0.0.0")]
//to avoid the following error:
// ...\Properties\AssemblyInfo.cs(36,32,36,39):
// warning CS7035: The specified version string does not conform to 
// the recommended format - major.minor.build.revision
// warning AL1053: The version '1.0.*' specified for 
// the 'file version' is not in the normal 'major.minor.build.revision' format

When check for update, I send a list of Version to client from a small web service.

void smsReceive1_OnCabUpdate(object sender, CabDataEventArgs e)
{
	try
	{
		var cabVer = e.CabVersion;
		var sms1 = (SmsService.SmsService)sender;
		SmsService.CabinetVersion progVer = null;
		var exeApp = Path.GetFileName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
		foreach (var item in cabVer)
		{
			if (string.Compare(item.FileName, exeApp, true) == 0)
			{
				progVer = item;
				break;
			}
		}

		var msgForm = new MessageBoxForm();
		if (!forceUpdate && !WillUpdateVersion(progVer))
		{
			Buzzer.Warning();
			sms1.StopReceive();
			msgForm.Message = "\r\nNewest Version!\r\n" +
				"Version\r\n" + progVer.AssemblyVersion.ToString() + "\r\n" +
				"Last Modified:\r\n" + progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm") + "\r\n" +
				"\r\nNo need to update";
			msgForm.OKShowDialog();
			return;
		}
		// 
		byte[] buffer = e.CabData;
		var filename = "\\ramdisk\\Setup.cab";
		if (File.Exists(filename))
		{
			File.Move(filename, string.Format("{0:yyMMdd_HHmmss}_Setup.cab"));
		}
		var fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
		fs.Write(buffer, 0, buffer.Length);
		fs.Flush();
		fs.Close();
		//
		Buzzer.Warning();
		//Stop SmsReceive
		sms1.StopReceive();
		msgForm.Message = "There is an update.\r\n" +
			"Version \r\n" + progVer.AssemblyVersion.ToString() + "\r\n" +
			"Last Modified:\r\n" + progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm") + "\r\n" +
			"※After the update\r\nIt will restart automatically";
		msgForm.SetSubMessage("Do you want to update?");
		var resp = msgForm.OKCancelShowDialog(true) == DialogResult.OK;
		if (resp)
		{
			CabFileUpdatePath = filename;
			UpdateApplication = true;
			Invoke((Action)(() => restartApplicationTimer.Enabled = true));
		}
		else
		{
			File.Delete(filename);
		}
	}
	finally
	{
		if (smsReceive1 != null) smsReceive1.ServicePaused = ServiceStatus.None;
	}
}

private bool WillUpdateVersion(SmartShooter.SmsService.CabinetVersion ver)
{
	var appVer = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
	if (ver.CompareToExe(appVer) > 0) return true;
	return false;
}

progVer.AssemblyVersion.ToDateTime().ToString("yy/MM/dd HH:mm")

Finally, this the reason because I have using ’*’ in the version.

public partial class MyVersion {
	
	public ushort Build { get; set; }
	
	public ushort Major { get; set; }
	
	public ushort Minor { get; set; }
	
	public ushort Revision { get; set; }
	

	public override string ToString()
	{
		return string.Format("{0}.{1}.{2}.{3}", Major, Minor, Build, Revision);
	}

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

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionmareView Question on Stackoverflow
Solution 1 - C#Adriano RepettiView Answer on Stackoverflow
Solution 2 - C#chamosView Answer on Stackoverflow
Solution 3 - C#We B MartiansView Answer on Stackoverflow
Solution 4 - C#fredView Answer on Stackoverflow
Solution 5 - C#antonioView Answer on Stackoverflow