当前位置: 首页 > news >正文

VS项目,在生成的时候自动修改版本号

demo示例:https://gitee.com/chenheze90/L28_AutoVSversion
可通过下载demo运行即可。
原理:通过csproject项目文件中的Target标签,实现在项目编译之前对项目版本号进行修改,避免手动修改;

1.基础版

效果图如下
在这里插入图片描述
在这里插入图片描述

部分脚本如下:

<Project>
<PropertyGroup><PreBuildEvent></PreBuildEvent></PropertyGroup><Target Name="SetAssemblyVersion" BeforeTargets="BeforeBuild"><PropertyGroup><Year>$([System.DateTime]::Now.ToString("yy"))</Year><MonthDay>$([System.DateTime]::Now.ToString("MMdd"))</MonthDay></PropertyGroup><Message Text="Setting AssemblyVersion to 1.0.$(Year).$(MonthDay)" Importance="high" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="//using System.Reflection;" Overwrite="true" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyTitle(&quot;MyAPPTitle&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyDescription(&quot;2021.03.29&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyConfiguration(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCompany(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyProduct(&quot;MyPro&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCopyright(&quot;Copyright ?  CCC&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyTrademark(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCulture(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Runtime.InteropServices.ComVisible(false)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyVersion(&quot;01.00.00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyFileVersion(&quot;01.00.00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyInformationalVersion(&quot;01.00.00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /></Target>
</Project>

2.进阶版

部分项目要自定义生成版本号,可通过自定义类的方式来实现。
1.新建项目ClassLibrary1
2.引用系统类库sing Microsoft.Build.Framework;;using Microsoft.Build.Utilities;
3.新建类GenerateVersionTask

public class GenerateVersionTask : Task{[Output]public int Version { get; set; }public override bool Execute(){// 生成版本号的逻辑Version = GetVisitCount();return true;}private const string DataFilePath = "visit_counter.dat";public static int GetVisitCount(){// 读取存储的数据int visitCount = 0; DateTime lastVisitDate = DateTime.Now;ReadData(ref visitCount, ref lastVisitDate);// 获取当前日期DateTime today = DateTime.Today;// 检查是否是新的一天if (lastVisitDate < today){// 重置访问次数visitCount = 0;lastVisitDate = today;}// 增加访问次数visitCount++;// 保存数据SaveData(visitCount, lastVisitDate);// 返回访问次数return visitCount;}private static void ReadData(ref int count, ref DateTime countdate){if (File.Exists(DataFilePath)){string[] lines = File.ReadAllLines(DataFilePath);if (lines.Length == 2){int visitCount = int.Parse(lines[0]);DateTime lastVisitDate = DateTime.Parse(lines[1]);count = visitCount; countdate = lastVisitDate;}}else{File.Create(DataFilePath);count = 0; countdate = DateTime.Now;}}private static void SaveData(int visitCount, DateTime lastVisitDate){string[] lines = { visitCount.ToString(), lastVisitDate.ToString() };File.WriteAllLines(DataFilePath, lines);}}

4.增加脚本

<UsingTask TaskName="GenerateVersionTask" AssemblyFile="$(TargetDir)\ClassLibrary1.dll" />

    <GenerateVersionTask><Output TaskParameter="Version" PropertyName="MyVersion" /></GenerateVersionTask>

效果如图所示

  <UsingTask TaskName="GenerateVersionTask" AssemblyFile="$(TargetDir)\ClassLibrary1.dll" /><Target Name="SetAssemblyVersion" BeforeTargets="BeforeBuild"><PropertyGroup><Year>$([System.DateTime]::Now.ToString("yy"))</Year><MonthDay>$([System.DateTime]::Now.ToString("MMdd"))</MonthDay></PropertyGroup><GenerateVersionTask><Output TaskParameter="Version" PropertyName="MyVersion" /></GenerateVersionTask><Message Text="Generated Version: $(MyVersion)" Importance="high" /><Message Text="Setting AssemblyVersion to 01.0$(MyVersion).00$(Year).$(MonthDay)" Importance="high" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="//using System.Reflection;" Overwrite="true" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyTitle(&quot;MyAPPTitle&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyDescription(&quot;2021.03.29&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyConfiguration(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCompany(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyProduct(&quot;MyPro&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCopyright(&quot;Copyright ?  CCC&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyTrademark(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyCulture(&quot;&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Runtime.InteropServices.ComVisible(false)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Windows.ThemeInfo(System.Windows.ResourceDictionaryLocation.None, System.Windows.ResourceDictionaryLocation.SourceAssembly)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyVersion(&quot;01.0$(MyVersion).00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyFileVersion(&quot;01.0$(MyVersion).00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /><WriteLinesToFile File="$(MSBuildThisFileDirectory)Properties\AssemblyInfo.cs" Lines="[assembly: System.Reflection.AssemblyInformationalVersion(&quot;01.0$(MyVersion).00$(Year).$(MonthDay)&quot;)]" Overwrite="false" /></Target>
</Project>

相关文章:

VS项目,在生成的时候自动修改版本号

demo示例&#xff1a;https://gitee.com/chenheze90/L28_AutoVSversion 可通过下载demo运行即可。 原理&#xff1a;通过csproject项目文件中的Target标签&#xff0c;实现在项目编译之前对项目版本号进行修改&#xff0c;避免手动修改&#xff1b; 1.基础版 效果图如下 部…...

【蓝桥杯】43699-四平方和

四平方和 题目描述 四平方和定理&#xff0c;又称为拉格朗日定理&#xff1a; 每个正整数都可以表示为至多 4 个正整数的平方和。如果把 0 包括进去&#xff0c;就正好可以表示为 4 个数的平方和。 比如&#xff1a; 502021222 712121222; 对于一个给定的正整数&#xff0c;可…...

我的“双胞同体”发布模式的描述与展望

当被“激情”晕染&#xff0c;重创标题、摘要探索“吸睛”。 (笔记模板由python脚本于2024年12月19日 15:23:44创建&#xff0c;本篇笔记适合喜欢编撰csdn博客的coder翻阅) 【学习的细节是欢悦的历程】 Python 官网&#xff1a;https://www.python.org/ Free&#xff1a;大咖免…...

flask_socketio 以继承 Namespace方式实现一个网页聊天应用

点击进入上一篇&#xff0c;可作为参考 实验环境 python 用的是3.11.11 其他环境可以通过这种方式一键安装&#xff1a; pip install flask3.1.0 Flask-SocketIO5.4.1 gevent-websocket0.10.1 -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple pip list 详情如下&am…...

go mod tidy 命令

go mod tidy 是 Go 语言的命令&#xff0c;用于清理和更新 go.mod 和 go.sum 文件。它主要有以下功能&#xff1a; 移除未使用的依赖项&#xff1a;从 go.mod 文件中删除那些在代码中不再使用的依赖项。 添加缺失的依赖项&#xff1a;添加代码中使用但尚未记录在 go.mod 文件中…...

(11)YOLOv9算法基本原理

一、YOLOv9 的结构 YOLOv9 引入了可编程梯度信息&#xff08;PGI&#xff09;&#xff0c;以及基于梯度路径规划的新型轻量级网络架构&#xff0c;为目标检测领域带来了突破性的成果。 Yolov9 网络模型主要由BackBone&#xff08;主干网络&#xff09;、Neck&#xff08;颈层&…...

python学opencv|读取图像(十七)认识alpha通道

【1】引言 前序学习进程中&#xff0c;我们已经掌握了RGB和HSV图像的通道拆分和合并&#xff0c;获得了很多意想不到的效果&#xff0c;相关链接包括且不限于&#xff1a; python学opencv|读取图像&#xff08;十二&#xff09;BGR图像转HSV图像-CSDN博客 python学opencv|读…...

中小学教室多媒体电脑安全登录解决方案

中小学教室多媒体电脑面临学生随意登录的问题&#xff0c;主要涉及到设备使用、网络安全、教学秩序等多个方面。以下是对这一问题的详细分析&#xff1a; 一、设备使用问题 1. 设备损坏风险 学生随意登录可能导致多媒体电脑设备过度使用&#xff0c;增加设备损坏的风险。不当…...

Redis篇之Redis高可用模式参数调优,提高Redis性能

1. Redis高可用模式核心 Redis高可用模式的核心是使用主从复制和自动故障转移机制来确保系统在某些节点发生故障时仍然可以正常工作。 常用的高可用架构包括Redis Sentinel模式和Redis Cluster模式&#xff0c;其中Sentinel模式是为了提供高可用性而专门设计的解决方案。 在Re…...

linux-----进程execl簇函数

execl函数族概述 在Linux中&#xff0c;execl函数族用于在一个进程中加载并执行一个新的程序&#xff0c;它会替换当前进程的地址空间&#xff08;代码段、数据段、堆和栈等&#xff09;。这个函数族包括execl、execlp、execle、execv、execvp和execvpe&#xff0c;它们的主要功…...

Vue + ECharts 实现山东地图展示与交互

这篇文章中&#xff0c;我将逐步介绍如何使用 Vue 和 ECharts 实现一个互动式的地图展示组件&#xff0c;其中支持返回上一层地图、点击查看不同城市的详细信息&#xff0c;以及根据数据动态展示不同的统计信息。 效果图&#xff1a;玩转山东地图&#xff1a;用Echarts打造交互…...

【Verilog】UDP用户原语

User-defined primitives 概述基本语法组合逻辑的UDP时序逻辑的UDPUDP 符号表 Verilog HDL&#xff08;简称 Verilog &#xff09;是一种硬件描述语言&#xff0c;用于数字电路的系统设计。可对算法级、门级、开关级等多种抽象设计层次进行建模。 Verilog 不仅定义了语法&…...

问题小记-达梦数据库报错“字符串转换出错”处理

最近遇到一个达梦数据库报错“-6111: 字符串转换出错”的问题&#xff0c;这个问题主要是涉及到一条sql语句的执行&#xff0c;在此分享下这个报错的处理过程。 问题表现为&#xff1a;一样的表结构和数据&#xff0c;执行相同的SQL&#xff0c;在Oracle数据库中执行正常&…...

MyBatis入门的详细应用实例

目录 MyBatis第一章&#xff1a;代理Dao方式的CRUD操作1. 代理Dao方式的增删改查 第二章&#xff1a;MyBatis参数详解1. parameterType2. resultType 第三章&#xff1a;SqlMapConfig.xml配置文件1. 定义properties标签的方式管理数据库的信息2. 类型别名定义 MyBatis 第一章&…...

Sequelize ORM sql 语句工具

Sequelize ORM sql 语句工具 初始化配置 Sequelize orm 配置文章落日沉溺于海 在命令行中全局安装 npm i -g sequelize-clisequelize 执行需要匹配 mysql2 对应的依赖&#xff08;安装 mysql2&#xff09; npm i sequelize mysql2初始化项目 sequelize init熟悉初始化项目后…...

增强LabVIEW与PLC通信稳定性

在工业自动化系统中&#xff0c;上位机与PLC之间的通信稳定性至关重要&#xff0c;尤其是在数据采集和控制任务的实时性要求较高的场景中。LabVIEW作为常用的上位机开发平台&#xff0c;通过合理优化通信协议、硬件接口、数据传输方式以及系统容错机制&#xff0c;可以大大提升…...

UDP系统控制器_音量控制、电脑关机、文件打开、PPT演示、任务栏自动隐藏

UDP系统控制器(ShuiYX) 帮助文档 概述 本程序设计用于通过UDP协议接收指令来远程控制计算机的音量、执行特定命令和其他功能。为了确保程序正常工作&#xff0c;请确认防火墙和网络设置允许UDP通信&#xff0c;并且程序启动后会最小化到托盘图标。 命令格式及说明 音量控制…...

NK细胞杀伐功能如何实现?

在人体的免疫系统中&#xff0c;自然杀伐细胞&#xff08;Natural Killer Cells&#xff0c;简称NK细胞&#xff09;是一类完全自然的免疫激活力量。它们为人体提供了快速反应能力&#xff0c;不依赖类元的特定识别力&#xff0c;但能直接寻找和毁灭毒病感染细胞和肿瘤细胞。那…...

Ubuntu搭建ES8集群+加密通讯+https访问

目录 写在前面 一、前期准备 1. 创建用户和用户组 2. 修改limits.conf文件 3. 关闭操作系统swap功能 4. 调整mmap上限 二、安装ES 1.下载ES 2.配置集群间安全访问证书密钥 3.配置elasticsearch.yml 4.修改jvm.options 5.启动ES服务 6.修改密码 7.启用外部ht…...

PC寄存器(Program Counter Register)jvm

在JVM(Java虚拟机)中,PC寄存器(Program Counter Register)扮演着至关重要的角色。以下是对JVM中PC寄存器的详细解释: 一、定义与功能 定义: JVM中的PC寄存器,也被称为程序计数器,是对物理PC寄存器的一种抽象模拟。它用于存储当前线程所执行的字节码指令的地址,即指…...

深度学习在微纳光子学中的应用

深度学习在微纳光子学中的主要应用方向 深度学习与微纳光子学的结合主要集中在以下几个方向&#xff1a; 逆向设计 通过神经网络快速预测微纳结构的光学响应&#xff0c;替代传统耗时的数值模拟方法。例如设计超表面、光子晶体等结构。 特征提取与优化 从复杂的光学数据中自…...

CVPR 2025 MIMO: 支持视觉指代和像素grounding 的医学视觉语言模型

CVPR 2025 | MIMO&#xff1a;支持视觉指代和像素对齐的医学视觉语言模型 论文信息 标题&#xff1a;MIMO: A medical vision language model with visual referring multimodal input and pixel grounding multimodal output作者&#xff1a;Yanyuan Chen, Dexuan Xu, Yu Hu…...

python/java环境配置

环境变量放一起 python&#xff1a; 1.首先下载Python Python下载地址&#xff1a;Download Python | Python.org downloads ---windows -- 64 2.安装Python 下面两个&#xff0c;然后自定义&#xff0c;全选 可以把前4个选上 3.环境配置 1&#xff09;搜高级系统设置 2…...

深入浅出:JavaScript 中的 `window.crypto.getRandomValues()` 方法

深入浅出&#xff1a;JavaScript 中的 window.crypto.getRandomValues() 方法 在现代 Web 开发中&#xff0c;随机数的生成看似简单&#xff0c;却隐藏着许多玄机。无论是生成密码、加密密钥&#xff0c;还是创建安全令牌&#xff0c;随机数的质量直接关系到系统的安全性。Jav…...

【位运算】消失的两个数字(hard)

消失的两个数字&#xff08;hard&#xff09; 题⽬描述&#xff1a;解法&#xff08;位运算&#xff09;&#xff1a;Java 算法代码&#xff1a;更简便代码 题⽬链接&#xff1a;⾯试题 17.19. 消失的两个数字 题⽬描述&#xff1a; 给定⼀个数组&#xff0c;包含从 1 到 N 所有…...

高频面试之3Zookeeper

高频面试之3Zookeeper 文章目录 高频面试之3Zookeeper3.1 常用命令3.2 选举机制3.3 Zookeeper符合法则中哪两个&#xff1f;3.4 Zookeeper脑裂3.5 Zookeeper用来干嘛了 3.1 常用命令 ls、get、create、delete、deleteall3.2 选举机制 半数机制&#xff08;过半机制&#xff0…...

Cloudflare 从 Nginx 到 Pingora:性能、效率与安全的全面升级

在互联网的快速发展中&#xff0c;高性能、高效率和高安全性的网络服务成为了各大互联网基础设施提供商的核心追求。Cloudflare 作为全球领先的互联网安全和基础设施公司&#xff0c;近期做出了一个重大技术决策&#xff1a;弃用长期使用的 Nginx&#xff0c;转而采用其内部开发…...

【JVM】Java虚拟机(二)——垃圾回收

目录 一、如何判断对象可以回收 &#xff08;一&#xff09;引用计数法 &#xff08;二&#xff09;可达性分析算法 二、垃圾回收算法 &#xff08;一&#xff09;标记清除 &#xff08;二&#xff09;标记整理 &#xff08;三&#xff09;复制 &#xff08;四&#xff…...

NPOI Excel用OLE对象的形式插入文件附件以及插入图片

static void Main(string[] args) {XlsWithObjData();Console.WriteLine("输出完成"); }static void XlsWithObjData() {// 创建工作簿和单元格,只有HSSFWorkbook,XSSFWorkbook不可以HSSFWorkbook workbook new HSSFWorkbook();HSSFSheet sheet (HSSFSheet)workboo…...

MinIO Docker 部署:仅开放一个端口

MinIO Docker 部署:仅开放一个端口 在实际的服务器部署中,出于安全和管理的考虑,我们可能只能开放一个端口。MinIO 是一个高性能的对象存储服务,支持 Docker 部署,但默认情况下它需要两个端口:一个是 API 端口(用于存储和访问数据),另一个是控制台端口(用于管理界面…...