Sdk: Is there a mechanism to control the AssemblyFileVersion independently from AssemblyVersion in MsBuild?

Created on 25 Jul 2017  路  5Comments  路  Source: dotnet/sdk

Hi

We are trying to save consumer frameworks and users the hassle of having to add assembly binding redirects when they upgrade minor/patch versions of Castle Core used as transitive dependencies. The issue where we are exploring this is here.

In summary this is what we landed on:

@stakx -> This line in Microsoft.NET.GenerateAssemblyInfo.targets suggests that it might be possible to add a <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute> to the .csproj, then define that attribute manually. I haven't tried it myself, though. (If that doesn't work, then try the much coarser-grained <GenerateAssemblyInfo>false</GenerateAssemblyInfo>. I've used this before and it works, but it means you might then have to keep certain attributes in Castle.Core.csproj and AssemblyInfo.cs in sync manually.)

Is there a tidy way we can achieve this without adding an AssemblyInfo.cs?

Thanks

Most helpful comment

Yes each attribute can be controlled individually by setting

<PropertyGroup>
  <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>

The pattern is Generate{AttributeName}Attribute, if you don't mind reading msbuild code the full list is here.

All 5 comments

You can set the properties AssemblyVersion (=> AssemblyVersionAttribute) and FileVersion (=> AssemblyFileVersionAttribute) in the project file to control the value of each generated attribute.

So a sample project file could contain for example:

<PropertyGroup>
  <!-- Set VersionPrefix instead of Version to allow a suffix to be added by CI builds -->
  <VersionPrefix>1.2.3</VersionPrefix>
  <AssemblyVersion>1.2.0</AssemblyVersion>
  <FileVersion>$(VersionPrefix)</FileVersion>
</PropertyGroup>

@dasMulli - Many thanks :)

Is it possible to disable the generation only of some parameters (those winch control versions) since a separate AssemblyInfo.cs is generated as part of my build? So I'm either turning off the generation of all attributes (those which control names) or I have only versions and rest are blank.

Yes each attribute can be controlled individually by setting

<PropertyGroup>
  <GenerateAssemblyInformationalVersionAttribute>false</GenerateAssemblyInformationalVersionAttribute>
</PropertyGroup>

The pattern is Generate{AttributeName}Attribute, if you don't mind reading msbuild code the full list is here.

Awesome, thanks!

Was this page helpful?
0 / 5 - 0 ratings