Jump to content

AssemblyVersion in .NET Core

Posted on:October 16, 2018 at 02:00 AM

Assembly Info in .NET Core

In .NET Core the way you specify AssemblyInfo attributes has changed. .NET Core allows you to specify assembly attributes in .csproj. You can do that by adding following properties:

<PropertyGroup>
  <Company>ACME Corp.</Company>
  <Authors>Chuck Norris</Authors>
  <PackageId>TexasRanger</PackageId>
  <Version>1.0.0</Version>
  <AssemblyVersion>10.0.0.0</AssemblyVersion>
  <FileVersion>10.0.0.0</FileVersion>
</PropertyGroup>

Problem

The problem stars if you want to use old AssemblyInfo.cs files. When you compile a project .NET Core with AssemblyInfo.cs you will get errors like e.g.: CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute.

Solution

In that case you should add to your .csproj following setting:

<PropertyGroup>
   <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

Extra

Here are some extra tips with related to AssemblyVersion.

NuGet

Quite often we would like to change assembly version in nuget package. NuGet uses .nuspec for that by default, but the property can be overwritten in command-line:

nuget.exe pack sample.nuspec -Version 1.0.%BUILD_NUMBER%.0

In the above example %BUILD_NUMBER%~ is taken from Jenkins

.NET Core AssemblyInfo Generation details

If you are interested how assemblies are generated in .NET Core here are the details: Microsoft.NET.GenerateAssemblyInfo.targets