Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display project version in ASP.NET Core 1.0.0 web application

Tags:

None of what used to work in RC.x helps anymore.

I have tried these:

  1. PlatformServices.Default.Application.ApplicationVersion;

  2. typeof(Controller).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;

  3. Assembly.GetEntryAssembly().GetName().Version.ToString();

They all return 1.0.0.0 instead of 1.0.0-9 which should be after execution of the dotnet publish --version-suffix 9 having this in project.json: "version": "1.0.0-*"

Basically they give me "File version" from the attached picture instead of "Product version" which dotnet publish actually seems to change.

enter image description here

like image 244
rook Avatar asked Sep 22 '16 23:09

rook


People also ask

How do I know what version of NET Core My project is using?

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.

How can we set the version in the Web API controller?

The default versioning scheme is Query String Parameter Versioning. We've already set a name for the query string parameter (api-version) that we are going to use to send versioning information. We use the [ApiVersion("1.0")] attribute to set the version of the controller.

Is versioning possible in asp net web API?

Since ASP.NET Core 3.1, you have the ability to version your APIs using a Microsoft NuGet package. Learn how to use this package to version your APIs easily.


1 Answers

For version 1.x:

Assembly.GetEntryAssembly().GetCustomAttribute<AssemblyInformationalVersionAttribute>().InformationalVersion; 

For version 2.0.0 this attribute contains something ugly: 2.0.0 built by: dlab-DDVSOWINAGE041 so use this one:

typeof(RuntimeEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version; 
like image 60
rook Avatar answered Sep 21 '22 17:09

rook