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

独立观察员 2020 年 12 月 24 日

之前 .NET Framework 时,项目版本号等信息是存储在 AssemblyInfo.cs 文件中,通过程序集特性进行设置:

.NET Core 之后,.NET 项目采用了新式的 SDK-Style 模式,将这些版本信息之类的也包含在项目文件里了,默认不再生成和使用 AssemblyInfo.cs 文件,而且如果你将这个文件添加上并填写相关信息,会提示有重复,编译不通过。虽然也有方法来恢复以前使用 AssemblyInfo.cs 的方式,但正所谓入乡随俗,既然人家改了模式,还是按规范来吧。

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

编辑后就会在项目文件中出现,项目文件可通过在项目上右键 - 编辑项目文件 打开(此操作也是 SDK-Style 的特色):

具体信息就是生成在 .csproj 的 PropertyGroup 节点内:

程序集版本(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)中的版本号相关推荐

  1. 将 Net 项目升级 Core项目经验:(一)迁移Net项目为Net Core\Standard项目

    迁移Net项目为Net Core\Standard项目 背景: 我们公司内部有自己ORM开发框架,最新因为需要将系统迁移到国产服务器上,所以首先需要将最基础的ORM框架改造可以运行在国产服务器上.对于 ...

  2. 迁移Net项目为Net Core\Standard项目

    背景: 我们公司内部有自己ORM开发框架,最新因为需要将系统迁移到国产服务器上,所以首先需要将最基础的ORM框架改造可以运行在国产服务器上.对于我们Net来说,优选Net Core.在迁移的过程中,将 ...

  3. 使用Http-Repl工具测试ASP.NET Core 2.2中的Web Api项目

    今天,Visual Studio中没有内置工具来测试WEB API.使用浏览器,只能测试http GET请求.您需要使用Postman,SoapUI,Fiddler或Swagger等第三方工具来执行W ...

  4. 如何使用EF Core在Blazor中创建级联的DropDownList

    介绍 (Introduction) In this article, we are going to create a cascading dropdown list in Blazor using ...

  5. 解决.NET Core/Standard 2.0编译时报“CS0579: Duplicate 'Assem

    一.缘由 当创建 .NET Core/Standard 2.0项目时,VS不会像.NET Framework项目一样自动生成AssemblyInfo.cs文件. 而且,若是手工在项目中加入以前写好的 ...

  6. android umeng,GitHub - umeng/umeng_community_android: 友盟微社区Android SDK开源项目

    友盟微社区 Android SDK 该项目是友盟微社区的开源部分代码,根目录下的工程为集成友盟微社区SDK的demo,umeng_comm_android_ui为友盟微社区开源UI代码,里面包含了友盟 ...

  7. .NET Core 3.0 中的新变化

    译者:楚人Leo 译文:http://www.cnblogs.com/leolion/p/10585834.html 原文:https://msdn.microsoft.com/en-us/magaz ...

  8. 将终结点图添加到你的ASP.NET Core应用程序中

    在本文中,我将展示如何使用DfaGraphWriter服务在ASP.NET Core 3.0应用程序中可视化你的终结点路由.上面文章我向您演示了如何生成一个有向图(如我上篇文章[译]使用DOT语言和G ...

  9. IHostingEnvironment VS IHostEnvironment - .NET Core 3.0中的废弃类型

    原文:https://andrewlock.net/ihostingenvironment-vs-ihost-environment-obsolete-types-in-net-core-3/ 作者: ...

最新文章

  1. Laravel 5.6 中文文档翻译完成,译者 60 人,耗时 10 天
  2. 机器学习:选对时机直线超车
  3. HTML5的 input:file上传类型控制
  4. Qt实现截屏并保存(转载)
  5. 如何检出SVN老版本代码
  6. SpringBoot2 整合 Zookeeper组件,管理架构中服务协调
  7. linux下dds软件,【数据库】Linux 单实例环境下实现Oracle数据库和DDS软件的开机自动重启...
  8. 标准模板库(STL)学习探究之Multimap容器
  9. ORM框架 之 Entity Framework
  10. Feature Scaling(特征缩放)的一些方法和使用选择
  11. HDU 3966 dfs序+LCA+树状数组
  12. maven 加入第三方库_项目pom里引入第三方库的四个方法
  13. 汽车如何打蜡 汽车打蜡有什么要注意的地方
  14. cousera视频无法加载
  15. Ajax+GridView+Xml的简易留言薄
  16. 动态动作系统——一种全新的游戏人物动作制作思路
  17. 用Java实现网易云音乐爬虫(非selenium)
  18. 流量分析(安恒八月月赛)
  19. 中国农业会计杂志中国农业会计杂志社中国农业会计编辑部2022年第12期目录
  20. 《三峡好人》,《黄金甲》所折射的电影学意义

热门文章

  1. WPF 绘制对齐像素的清晰显示的线条
  2. Windows下Visual studio 2013 编译 Audacity
  3. Swift数据类型简介(二)
  4. jQuery.extend与jQuery.fn.extend的区别分析与实例
  5. 从零开始学习jQuery (九) jQuery工具函数 【转】
  6. html仿微信滑动删除,使用Vue实现移动端左滑删除效果附源码
  7. 了解cron以及使用cron定时备份MySQL
  8. mailing list的原理
  9. TypeError: 'MongoClient' object is not callable
  10. Photoshop脚本 使用ExtendScript编写Ps脚本