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.
Related
In a C# project built with VS2013, I could put this in the AssemblyInfo.cs file:
[assembly: AssemblyInformationalVersion("7.1.0.0 Private (Debug build)")]
When I used the FileVersionInfo.GetVersionInfo .NET API against the executable from within another project, I found these values reported:
Product version: 7.1.0.0 Private (Debug build)
ProductMajorPart: 7
ProductMinorPart: 1
When I use the same attribute and string value in a C# project built with VS2015, the ProductMajorPart and ProductMinorPart properties are reported as zero!
Does anyone know if the behaviour change is intentional?
I have examined the binary file version information found within the executables, and whilst the string values within the version information are as expected in both files, the VS2015 executable has zero values within the VS_FIXEDFILEINFO.dwProductVersionMS and VS_FIXEDFILEINFO.dwProductVersionLS fields.
I can confirm the change in behavior for this case, with the observation that if the AssemblyInformationalVersion is in canonical format, for example "7.1.0.0" then it works as expected in all versions i.e. the Product version major/minor/build/revision fields are filled in.
For background, the docs for AssemblyInformationalVersion do in fact specify that:
The attribute defined by this class attaches additional version information to an assembly. If this attribute is applied to an assembly, the string it specifies can be obtained at run time by using the Application.ProductVersion property.
[...] Although you can specify any text, a warning message appears on compilation if the string is not in the format used by the assembly version number [...]
From the above:
there is no formal guarantee other than that the string itself can be retrieved;
there is a warning against using free-format strings.
You may, or even should, file a bug report on VS connect though my feeling is that MS sees free-format strings in AssemblyInformationalVersion as an unsupported "accidental" feature, and might not consider a change in undocumented behavior to be a "bug" proper.
Not directly related, but this VS 2010 bug report Localized build with free form AssemblyInformationalVersion causes ALINK warning AL1053 has been closed by MS as won't fix.
Also the accepted answer at Why is warning CS1607 “The version specified for the 'product version' is not in the normal 'major.minor.build.revision' format” generated? basically advises that once you deviate from the standard major.minor.build.revision format, you are pretty much on your own.
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
the title probably doesn't make much sense as to what I am trying to achieve, its kind of difficult to explain in a brief bit of text.
I have created a project both in C# for Windows/Mono projects and an Android version of the library.
When I upload the library to my server for users to download and use in their own projects I want the library to have the following sort of name
MyLibrary_Version.1.0.dll for Windows
MyLibrary_Version.1.0.jar for Android
When the project is built and the library is referenced it is referenced using the name MyLibrary.dll or MyLibrary.jar.
I'm not sure how I can ensure that each project that is referenced by my library can work OK when it has a different name, i.e. include the version number.
This must be possible, as other companies who provide library do the same sort of thing but I can't see anyway how this can be done.
Thanks for any help you can provide.
Not sure this is the response your looking for, but here goes...
in your c# project in the properties folder, edit your assemblyinfo.cs file and add a version numberin there like..
[assembly: AssemblyVersion("1.2.1.*")]
[assembly: AssemblyFileVersion("1.0.0.0")]
The * will increment the count by 1 each time you build.
When your app consumes the dll, you should be able to specify the matching version of the dll, in the assembly declaration for that dll in the app.config. (if using provider model)
Or through reflection in your code to return an error if the incorrect DLL is included in with App release.
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.