编程知识 cdmana.com

Version number in. Net SDK style project (core, standard,. Net5)

.NET SDK-Style project (Core、Standard、.NET5) Version number in

.NET SDK-Style project (Core、Standard、.NET5) Version number in

Independent observers 2020 year 12 month 24 Japan

 

Before  .NET Framework when , Information such as project version number is stored in  AssemblyInfo.cs In file , Set through assembly properties :

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration

 

.NET Core  after ,.NET The project adopted a new type of  SDK-Style  Pattern , Include these version information in the project file , No longer generated and used by default  AssemblyInfo.cs file , And if you add this file and fill in the relevant information , It will prompt for repetition , Compile not pass . Although there are also ways to restore previously used  AssemblyInfo.cs The way , But as the saying goes, do as the Romans do , Now that people have changed their mode , Let's follow the rules .

 

It's almost the same as before , stay attribute - pack There is “ Package version ”、“ Assembly version ” and “ Assembly file version ”:

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration 1

 

After editing, it will appear in the project file , The project file can be accessed by right clicking on the project - Edit project files open ( This operation is also  SDK-Style  The characteristics of ):

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration 2

 

Specific information is generated in .csproj Of PropertyGroup In node :

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration 3

 

Assembly version (AssemblyVersion) Same as before ( Wildcard characters are also supported *), Package version (Version) Corresponding to previous assembly information version (AssemblyInformationalVersion), Assembly file version (FileVersion) Corresponding to the previous (AssemblyFileVersion):

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration 4

 

in addition , Here it is. WPF Assembly version information is bound in , The method is as follows , In other words, the introduction of the namespace and the use of :

.NET SDK-Style  project (Core、Standard、.NET5) Version number in illustration 5

 

AssemblyHelper as follows :

using System.Reflection;/* *  The source code has been hosted :*/namespace DotNet.Utilities{ /// <summary> ///  Assembly help class  /// </summary> public class AssemblyHelper {  #region  Assembly feature accessor   /// <summary>  ///  Assembly title   /// </summary>  public static string AssemblyTitle  {   get   {    object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyTitleAttribute), false);    if (attributes.Length > 0)    {     AssemblyTitleAttribute titleAttribute = (AssemblyTitleAttribute)attributes[0];     if (titleAttribute.Title != "")     {      return titleAttribute.Title;     .........

版权声明
本文为[Program ape Owen]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224170347943y.html

Scroll to Top