In AssemblyInfo.cs:
[assembly: AssemblyVersion("1.0.*")]
Will generates a 1.0.x.x four digits version number.
Which, if I use this nuspec metadata:
<version>$version$-test</version>
generates an error when packing:
The version « 1.0.5431.31092-test » does not follow semantic version control instructions
Is there a simple way around this?
Not possible, an assembly's version is stored in the System.Version class, that consists of Major, Minor, Build and Revision.
EDIT: I was a bit to hasty to answer. When you use the AssemblyVersionAttribute's constructor with a string containing an asterix, all four properties of a version will be generated. The only way to cause a version with lesser numbers is to specify the exact version number, without asterix, i.e "1.0.1". See: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute(v=vs.110).aspx
What you could do, if you want lesser numbers in the version and also generated version numbers, is to use an external tool altering version numbers in the pre-build step.
No post processing is necessary, NuGet is using [assembly: AssemblyInformationalVersion("")] as a package version, set it to whatever number of componets you please and be done with it.
P.S I strongly encourage you to also set AssemblyVersion as this is the one .NET actually uses, at least set it to auto increment
Some reading available here
Full example
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyInformationalVersion("1.0")]
Will generate a package Lib.1.0.nupkg containing assembly with 1.0.x.x version, version you will be dealing with is 1.0
Whenever you want to change nuget version, just change AssemblyInformationalVersion, not touch AssemblyVersion at all
Related
I'm creating a .NuSpec file with
<metadata>
<version>$version$</version>
<!-- ... -->
</metadata>
Unfortunately, that returns the assembly's version in Major.Minor.Build.Revision format. I need to trim this down to 3 parts only (Major.Minor.Build) for compatibility with SemVersion as used by Squirrel.
Is there any way to do this? I'd prefer not having to put in the version number by hand for each release.
Is there any way to do this? I'd prefer not having to put in the version number by hand for each release
If you do not want to modify the version number by hand for each release, you probably don't need .nuspec. You can run nuget pack with the project file directly:
nuget pack MyProject.csproj
According to the Replacement tokens, when we pack the .csprojdirectly, the value source of $version$ comes from file AssemblyInfo.cs or AssemblyInfo.vb:
So nuget will use the value of AssemblyInformationalVersion if present, otherwise AssemblyVersion. It is removed by default, because they don’t apply to semantic versioning. when we add it to the AssemblyInfo.cs file:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("2.0.0")]
Nuget will actually apply whatever is in that string as the package version.
Notice that the informational version only contains three numbers. So it compatibility with SemVersion as used by Squirrel.
Source:How to Version Assemblies Destined for Nuget
Hope this helps.
Here is the help file I am using. It states that it still applies to version 4.6.
Yet, when I try to use the built-in calculations, with the following code:
[assembly: AssemblyVersion("2015.7.*.*")]
[assembly: AssemblyFileVersion("2015.7.*.*")]
I get syntax errors on the asterisk, and the solution won't compile. I am not sure what is going on. According to the help file, it should be working.
You don't need two * just one is enough.
[assembly: AssemblyVersion("2015.7.*")]
From your link
Examples of valid version strings include:
1
1.1
1.1.*
1.1.1
1.1.1.*
1.1.1.1
Remove the AssemblyFileVersion.
If the AssemblyFileVersionAttribute is not supplied, the
AssemblyVersionAttribute is used for the Win32 file version that is
displayed on the Version tab of the Windows file properties dialog.
Bit of an odd one maybe, but currently looking into if it is possible to implement a custom format for the Assembly Information for a project.
In the Assembly information you are given the option of a 4 number system, so major.minor.build.revision
I have been asked to try and change this to a 5 number system, so something like 1.2.34.556.1234 and wondering whether this is even possible.
I have simply tried just modifying it programmatically, but that just returns the error:
Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.2.34.556.1234' is invalid'
For that purpose, I prefer using the AssemblyFileVersion instead of the AssemblyVersion.
The former has an open format and can accommodate virtually any additional information, whereas the latter, AssmeblyVersion is intended for use by the .NET framework and enforces a strict numbering scheme that yields compiler errors if infracted.
[assembly: AssemblyVersion("4.0.*")] //Strict Format, for framework use
[assembly: AssemblyFileVersion("4.0.20.110708")] //Flexible Format more suitable for product versions
Update:
Per OP comment, here is how one can access this attribute easily via reflection:
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
This will not work because the constructor for AssemblyVersionAttribute takes up to 4 values in the string.:
The format of the version string is: major. minor. build. revision.
MSDN Link
AssemblyVersionAttribute is converted to the Version class.
It has only the major,minor,build,revision number: you cannot use 5 numbers.
If you want to use more numbers you can use the AssemblyInformationalVersion
It is not a Version Class but a string for a more descriptive assembly versioning:
[assembly: AssemblyInformationalVersion("1.12.0.3050.1234 Release - Any CPU")]
But you should provide anyway AssemblyVersion and/or AssemblyFileVersion without the 5th number
If you go to:
Solution Explorer -- > Properties -- >(double click) Assembly Info
you will see some information about assemblies for your project. At the end of it there are some different versions for each assemblies that they are:
Major Version
Minor Version
Build Number
Revision
And I Understood that These are numbers of these:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
but I don't understand the meaning.
When the project is built those values are baked into the dll so that when you view the dll's properties via the Windows File System you will see that version number.
Managing those numbers is a bit of a pain in the ass. In older projects you'll often see some ugly build scripts that do things like check out the files then increment the number then check them in then continue with the build... The most elegant solution I've seen is implemented by TeamCity (though there are probably similar products); it basically copies all of the projects files to your build server, then it edits it's local copy with values it maintains (you can alter or reset them in UI), then builds the project. This allows it to never touch source control while giving you good control over dll versioning.
They are whatever you want them to mean. You are free to use your own definitions for each section of the version number; beyond the fact that different numbers are different, there is no functionality driven off of this by the language.
AssemblyVersion is used in the strong name of the assembly(signing).
AssemblyFileVersion is displayed by Windows in the Version tab on the file properties.
AssemblyInformationalVersion is used in the assembly manifest for things like NuGet.
As far as how to version, I recommend Semantic Versioning, which uses a 3-part version number:
Given a version number MAJOR.MINOR.PATCH, increment the:
1. MAJOR version when you make incompatible API changes,
2. MINOR version when you add functionality in a backwards-compatible manner, and
3. PATCH version when you make backwards-compatible bug fixes.
AssemblyVersion used for strong name of the assembly with sn.exe, but
AssemblyFileVersion display the version on the file properties.
I'm trying to find a more meaningful way to handle versioning for my app and I came acrossed this KB article
http://support.microsoft.com/kb/556041
Basically it's recommending that the Assembly version be fixed, and the File Version be imcremented for each build. Now this makes perfect sense to me but for the life of me I can't seem to implement it.
The below snippet auto increments both Assembly version and FileVersion.
[assembly: AssemblyVersion("1.0.*")]
While this next one seems to set a fixed Assembly version of 1.0.0.0 and a fixed File Version of 1.0.*.
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.*")]
Incidentally, the Product Version in Details tab of the file properties reads 1.0.* now as well. Now I can fix the Product Version in the file properties with this...
[assembly: AssemblyInformationalVersion("1.0")]
But that doesn't help with my original task. Out of curiosity I tried the below and the File version changed to 2.0.*, so it is at least using it. It's just not auto incrementing.
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("2.0.*")]
So from what I can gather the only version number that auto increments is the Assembly Version, but on the off chance you haven't specified a File Version it gets set to the same as the Assembly Version.
Does anyone know of a way to auto increment the File Version while leaving the Assembly Version fixed?
Yes it's a bit silly, Microsoft seems to have got it the wrong way round. AssemblyVersion is used in the .NET assembly versioning system, so you should never auto-increment it, but AssemblyFileVersion is written to the file version entry in the file's version resource, so you might reasonably expect it to always auto-increment by default.
I'm sure that there are some 3rd party build systems out there that can do this for you, but I just wrote a little command line C# app to do it, and it gets run on every project as part of our build process. It's very straightforward:
Read the AssemblyInfo.cs file line by line.
Do a RegEx search for the AssemblyFileVersion line, capturing all four version parts into separate capture groups. You could parse it yourself, but a regex will do all the detecting and parsing in one go, so it seems silly not to take advantage.
Once you have the four integers, implement your own incrementing logic as you see fit.