Fork me on GitHub

Assembly version

Gentoo Mono Handbook
Using versionator to cut version
$PVPackage version (excluding revision, if any), for example 6.3. It should reflect the upstream versioning scheme.

loresoft/msbuildtasks

https://github.com/loresoft/msbuildtasks/blob/master/Documentation/TaskDocs.md#AssemblyInfo

For own project

1. Modify .csproj file, insert the following code:
   <Import Project="$(MSBuildExtensionsPath)\MSBuild.Community.Tasks.Targets" />
   <Target Name="BeforeBuild">
		<PropertyGroup Condition=" '$(VersionNumber)' == '' ">
		    <VersionNumber>1.0.0.0</VersionNumber>
		</PropertyGroup>
		<AssemblyInfo CodeLanguage="C#"
			OutputFile="Properties/AssemblyVersion.cs" 
            AssemblyVersion="$(VersionNumber)" 
            AssemblyFileVersion="$(VersionNumber)"
		/>
   </Target>

2. Modify AssemblyInfo.cs to remove version attributes duplication
3. Add .AssemblyVersion.cs into .gitignore
4. Make a commit to sources repository, make new digest for new archive
5. Add
DEPEND=">=dev-dotnet/msbuildtasks-1.5.0.240"
6. Insert these lines into ebuild:
ASSEMBLY_VERSION="${PV}"
exbuild /p:VersionNumber="${ASSEMBLY_VERSION}"

example of change:
in sources
in ebuild

For external project

1. Make patch for .csproj file
2. Insert eapply into ebuild
then preform steps 5. and 6 from above

How to do the same without msbuildtasks

http://stackoverflow.com/questions/8446693/specify-assembly-version-number-as-a-command-line-argument-in-msbuild
http://stackoverflow.com/questions/10980249/msbuild-task-for-setting-custom-attribute-in-assemblyinfo-cs
  <Target Name="BeforeBuild">
    <PropertyGroup Condition=" '$(VersionNumber)' == '' ">
      <VersionNumber>1.0.0.0</VersionNumber>
    </PropertyGroup>
    <ItemGroup>
      <AssemblyAttributes Include="AssemblyVersion">
        <_Parameter1>$(VersionNumber)</_Parameter1>
      </AssemblyAttributes>
      <AssemblyAttributes Include="AssemblyFileVersion">
        <_Parameter1>$(VersionNumber)</_Parameter1>
      </AssemblyAttributes>
      <AssemblyAttributes Include="AssemblyInformationalVersion">
        <_Parameter1>$(VersionNumber)</_Parameter1>
      </AssemblyAttributes>   
      </ItemGroup>
    <WriteCodeFragment Language="C#" OutputFile="Properties/AssemblyVersion.cs" AssemblyAttributes="@(AssemblyAttributes)" />
  </Target>

mikefourie/MSBuildExtensionPack

https://github.com/mikefourie/MSBuildExtensionPack

    http://stackoverflow.com/questions/3585444/how-can-i-change-assemblyproduct-assemblytitle-using-msbuild

Maximum of version part is 65534

Properties/AssemblyInfo.cs(11,30): error CS7034: The specified version string `4.3.11.65536' does not conform to the required format - major[.minor[.build[.revision]]]
https://blogs.msdn.microsoft.com/msbuild/2007/01/03/why-are-build-numbers-limited-to-65535/
http://stackoverflow.com/questions/37941195/the-specified-version-string-does-not-conform-to-the-required-format-major-mi
for 65535 it gives another error:
Mono.CSharp.InternalErrorException: Failed to import assembly `System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.ArgumentException: Value does not fall within the expected range.
				  at IKVM.Reflection.Fusion.CompareAssemblyIdentityPure (System.String assemblyIdentity1, System.Boolean unified1, System.String assemblyIdentity2, System.Boolean unified2, IKVM.Reflection.AssemblyComparisonResult& result) [0x000e3] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Universe.CompareAssemblyIdentity (System.String assemblyIdentity1, System.Boolean unified1, System.String assemblyIdentity2, System.Boolean unified2, IKVM.Reflection.AssemblyComparisonResult& result) [0x0001c] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticLoader.AssemblyReferenceResolver (System.Object sender, IKVM.Reflection.ResolveEventArgs args) [0x0004b] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Universe.Load (System.String refname, IKVM.Reflection.Module requestingModule, System.Boolean throwOnError) [0x00060] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveAssemblyRefImpl (IKVM.Reflection.Metadata.AssemblyRefTable+Record& rec) [0x00095] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveAssemblyRef (System.Int32 index) [0x0002e] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveType (System.Int32 metadataToken, IKVM.Reflection.IGenericContext context) [0x000d2] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.TypeDefImpl.get_BaseType () [0x0002f] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.MetadataImporter.CreateType (IKVM.Reflection.Type type, Mono.CSharp.TypeSpec declaringType, Mono.CSharp.MetadataImporter+DynamicTypeReader dtype, System.Boolean canImportBaseType) [0x0037f] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.MetadataImporter.ImportTypes (IKVM.Reflection.Type[] types, Mono.CSharp.Namespace targetNamespace, System.Boolean importExtensionTypes) [0x0005a] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticImporter.ImportAssembly (IKVM.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x0000f] in <65ad872b0e564119b94b07e7497063eb>:0 
				   --- End of inner exception stack trace ---
				  at Mono.CSharp.StaticImporter.ImportAssembly (IKVM.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00054] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticLoader.LoadReferences (Mono.CSharp.ModuleContainer module) [0x0009a] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.Driver.Compile () [0x0022e] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.Driver.Main (System.String[] args) [0x00052] in <65ad872b0e564119b94b07e7497063eb>:0 
				[ERROR] FATAL UNHANDLED EXCEPTION: Mono.CSharp.InternalErrorException: Failed to import assembly `System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.ArgumentException: Value does not fall within the expected range.
				  at IKVM.Reflection.Fusion.CompareAssemblyIdentityPure (System.String assemblyIdentity1, System.Boolean unified1, System.String assemblyIdentity2, System.Boolean unified2, IKVM.Reflection.AssemblyComparisonResult& result) [0x000e3] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Universe.CompareAssemblyIdentity (System.String assemblyIdentity1, System.Boolean unified1, System.String assemblyIdentity2, System.Boolean unified2, IKVM.Reflection.AssemblyComparisonResult& result) [0x0001c] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticLoader.AssemblyReferenceResolver (System.Object sender, IKVM.Reflection.ResolveEventArgs args) [0x0004b] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Universe.Load (System.String refname, IKVM.Reflection.Module requestingModule, System.Boolean throwOnError) [0x00060] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveAssemblyRefImpl (IKVM.Reflection.Metadata.AssemblyRefTable+Record& rec) [0x00095] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveAssemblyRef (System.Int32 index) [0x0002e] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.ModuleReader.ResolveType (System.Int32 metadataToken, IKVM.Reflection.IGenericContext context) [0x000d2] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at IKVM.Reflection.Reader.TypeDefImpl.get_BaseType () [0x0002f] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.MetadataImporter.CreateType (IKVM.Reflection.Type type, Mono.CSharp.TypeSpec declaringType, Mono.CSharp.MetadataImporter+DynamicTypeReader dtype, System.Boolean canImportBaseType) [0x0037f] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.MetadataImporter.ImportTypes (IKVM.Reflection.Type[] types, Mono.CSharp.Namespace targetNamespace, System.Boolean importExtensionTypes) [0x0005a] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticImporter.ImportAssembly (IKVM.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x0000f] in <65ad872b0e564119b94b07e7497063eb>:0 
				   --- End of inner exception stack trace ---
				  at Mono.CSharp.StaticImporter.ImportAssembly (IKVM.Reflection.Assembly assembly, Mono.CSharp.RootNamespace targetNamespace) [0x00054] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.StaticLoader.LoadReferences (Mono.CSharp.ModuleContainer module) [0x0009a] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.Driver.Compile () [0x0022e] in <65ad872b0e564119b94b07e7497063eb>:0 
				  at Mono.CSharp.Driver.Main (System.String[] args) [0x00052] in <65ad872b0e564119b94b07e7497063eb>:0 
				Tool /usr/lib64/mono/4.5/mcs.exe execution finished.
/usr/lib64/mono/xbuild/14.0/bin/Microsoft.CSharp.targets: error : Compiler crashed with code: 1.
https://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.aspx