日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

.NET SDK-Style 项目(Core、Standard、.NET5)中的版本号

發(fā)布時間:2023/12/4 asp.net 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 .NET SDK-Style 项目(Core、Standard、.NET5)中的版本号 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

.NET SDK-Style 項目(Core、Standard、.NET5)中的版本號

獨立觀察員 2020 年 12 月 24 日

?

之前?.NET?Framework 時,項目版本號等信息是存儲在?AssemblyInfo.cs 文件中,通過程序集特性進行設置:

?

.NET?Core?之后,.NET 項目采用了新式的?SDK-Style?模式,將這些版本信息之類的也包含在項目文件里了,默認不再生成和使用?AssemblyInfo.cs 文件,而且如果你將這個文件添加上并填寫相關信息,會提示有重復,編譯不通過。雖然也有方法來恢復以前使用 AssemblyInfo.cs 的方式,但正所謂入鄉(xiāng)隨俗,既然人家改了模式,還是按規(guī)范來吧。

?

圖形操作上和以前差不多,在 屬性 - 打包 中有 “包版本”、“程序集版本” 和 “程序集文件版本”:

?

編輯后就會在項目文件中出現,項目文件可通過在項目上右鍵 - 編輯項目文件 打開(此操作也是?SDK-Style?的特色):

?

具體信息就是生成在 .csproj 的 PropertyGroup 節(jié)點內:

?

程序集版本(AssemblyVersion)和以前一樣(也支持通配符 *),包版本(Version)對應以前的程序集信息版本(AssemblyInformationalVersion),程序集文件版本(FileVersion)對應以前的(AssemblyFileVersion):

?

另外,這里是在 WPF 中綁定了程序集版本信息,方法如下,也就是引入命名空間和使用:

?

AssemblyHelper 如下:

using System.Reflection; /** 源碼己托管:http://gitee.com/dlgcy/dotnetcodes*/ namespace DotNet.Utilities {/// <summary>/// 程序集幫助類/// </summary>public class AssemblyHelper{#region 程序集特性訪問器/// <summary>/// 程序集標題/// </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;}}return System.IO.Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);}}/// <summary>/// 程序集版本/// </summary>public static string AssemblyVersion{get{return Assembly.GetExecutingAssembly().GetName().Version.ToString();}}/// <summary>/// 程序集清單的其他版本信息/// </summary>public static string AssemblyInformationalVersion{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyInformationalVersionAttribute)attributes[0]).InformationalVersion;}}/// <summary>/// Win32 文件版本/// </summary>public static string AssemblyFileVersion{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyFileVersionAttribute)attributes[0]).Version;}}/// <summary>/// 程序集的文本說明/// </summary>public static string AssemblyDescription{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyDescriptionAttribute)attributes[0]).Description;}}/// <summary>/// 程序集清單的產品名/// </summary>public static string AssemblyProduct{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyProductAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyProductAttribute)attributes[0]).Product;}}/// <summary>/// 程序集清單的版權/// </summary>public static string AssemblyCopyright{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyCopyrightAttribute)attributes[0]).Copyright;}}/// <summary>/// 程序集清單的公司名稱/// </summary>public static string AssemblyCompany{get{object[] attributes = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyCompanyAttribute), false);if (attributes.Length == 0){return "";}return ((AssemblyCompanyAttribute)attributes[0]).Company;}}#endregion} }

?

這個和以前是通用的。

?

最后祝大家平安夜快樂!

總結

以上是生活随笔為你收集整理的.NET SDK-Style 项目(Core、Standard、.NET5)中的版本号的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。