Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the version number for .NET Core projects

What are the options for setting a project version with .NET Core / ASP.NET Core projects?

Found so far:

  • Set the version property in project.json. Source: DNX Overview, Working with DNX projects. This seems to set the AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion unless overridden by an attribute (see next point).

  • Setting the AssemblyVersion, AssemblyFileVersion, AssemblyInformationalVersion attributes also seems to work and override the version property specified in project.json.

    For example, including 'version':'4.1.1-*' in project.json and setting [assembly:AssemblyFileVersion("4.3.5.0")] in a .cs file will result in AssemblyVersion=4.1.1.0, AssemblyInformationalVersion=4.1.1.0 and AssemblyFileVersion=4.3.5.0

Is setting the version number via attributes, e.g. AssemblyFileVersion, still supported?

Have I missed something - are there other ways?

Context

The scenario I'm looking at is sharing a single version number between multiple related projects. Some of the projects are using .NET Core (project.json), others are using the full .NET Framework (.csproj). All are logically part of a single system and versioned together.

The strategy we used up until now is having a SharedAssemblyInfo.cs file at the root of our solution with the AssemblyVersion and AssemblyFileVersion attributes. The projects include a link to the file.

I'm looking for ways to achieve the same result with .NET Core projects, i.e. have a single file to modify.

like image 299
Ronald Zarīts Avatar asked Mar 17 '16 09:03

Ronald Zarīts


People also ask

What version of .NET core is my project?

Checking the Version of Your . Open your project's source folder and, in the address bar, type "cmd" and press Enter. It will open the command prompt with the project path. Execute the following command: dotnet --version . It will display your project's current SDK version,i.e., 2.1.


1 Answers

Another option for setting version info when calling build or publish is to use the undocumented /p option.

dotnet command internally passes these flags to MSBuild.

Example:

dotnet publish ./MyProject.csproj /p:Version="1.2.3" /p:InformationalVersion="1.2.3-qa" 

See here for more information: https://github.com/dotnet/docs/issues/7568

like image 156
Arnold Zokas Avatar answered Sep 28 '22 00:09

Arnold Zokas