How to manually install the build version

It gives me such a headache. We used things in the project's properties [assembly: AssemblyVersion("1.0.0.0")]. I am completely fine with the change, so I don't care where it is. I understand that they are going to set a new standard for versions, and are also completely beautiful.

Many documents out there point to a file project.jsonthat is clearly a waste, since it is no longer a legitimate file. In the later text, add the following to your file .csproj:

<PropertyGroup>
    <VersionPrefix>1.2.3</VersionPrefix>
    <VersionSuffix>alpha</VersionSuffix>
</PropertyGroup>

Also the total amount of waste. Just because I can't read it. The following always gives me 1.0.0.0.

PlatformServices.Default.Application.ApplicationVersion

Not to mention, when I right click in File Explorerand click Properties, then the tab Detailsalso always says 1.0.0.0.

So, how can I install a version of each assembly in my solution and then read it later at run time?

+4
source share
2 answers

Turns out it started working when .Net Core 2.0 came out . When you right-click on the Project , and then click Properties , an interface will be displayed for it, as shown below:

Project Properties User Interface

Package Version, Assembly Versionand Assembly File Versioncorrespond to the settings Version, AssemblyVersionand FileVersionin the file, .csprojrespectively:

<PropertyGroup>
  <Version>1.1.0</Version>
  <AssemblyVersion>1.1.0.9</AssemblyVersion>
  <FileVersion>1.1.0.9</FileVersion>
</PropertyGroup>

Then I created a utility method in each project of my solution, which performs the following actions:

public static VersionInformationModel GetVersionInformation() {
  var Result = new VersionInformationModel {
    Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(),
    BuildDate = System.IO.File.GetLastWriteTime(Assembly.GetExecutingAssembly().Location),
    Configuration = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyConfigurationAttribute>().Configuration,
    TargetFramework = Assembly.GetExecutingAssembly().GetCustomAttribute<System.Runtime.Versioning.TargetFrameworkAttribute>().FrameworkName,
  };

  return Result;
}

, , , , .

0

On :

<PropertyGroup>
    <Version>1.3.5.7</Version>
    <FileVersion>2.4.6.8</FileVersion>
</PropertyGroup>

:

var fileVersion = Assembly.GetEntryAssembly()
    .GetCustomAttribute<AssemblyFileVersionAttribute>()
    .Version;

var informationalVersion = Assembly.GetEntryAssembly()
    .GetCustomAttribute<AssemblyInformationalVersionAttribute>()
    .InformationalVersion;

, .csproj ( ) , AssemblyInfo.cs, - :

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Reflection;

//snip    
[assembly: System.Reflection.AssemblyFileVersionAttribute("2.4.6.8")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.2.3")]

// Generated by the MSBuild WriteCodeFragment class.
+3

Source: https://habr.com/ru/post/1683353/


All Articles