当前位置: 首页 > 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寄存器的一种抽象模拟。它用于存储当前线程所执行的字节码指令的地址,即指…...

网络编程(Modbus进阶)

思维导图 Modbus RTU&#xff08;先学一点理论&#xff09; 概念 Modbus RTU 是工业自动化领域 最广泛应用的串行通信协议&#xff0c;由 Modicon 公司&#xff08;现施耐德电气&#xff09;于 1979 年推出。它以 高效率、强健性、易实现的特点成为工业控制系统的通信标准。 包…...

未来机器人的大脑:如何用神经网络模拟器实现更智能的决策?

编辑&#xff1a;陈萍萍的公主一点人工一点智能 未来机器人的大脑&#xff1a;如何用神经网络模拟器实现更智能的决策&#xff1f;RWM通过双自回归机制有效解决了复合误差、部分可观测性和随机动力学等关键挑战&#xff0c;在不依赖领域特定归纳偏见的条件下实现了卓越的预测准…...

应用升级/灾备测试时使用guarantee 闪回点迅速回退

1.场景 应用要升级,当升级失败时,数据库回退到升级前. 要测试系统,测试完成后,数据库要回退到测试前。 相对于RMAN恢复需要很长时间&#xff0c; 数据库闪回只需要几分钟。 2.技术实现 数据库设置 2个db_recovery参数 创建guarantee闪回点&#xff0c;不需要开启数据库闪回。…...

VB.net复制Ntag213卡写入UID

本示例使用的发卡器&#xff1a;https://item.taobao.com/item.htm?ftt&id615391857885 一、读取旧Ntag卡的UID和数据 Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Button15.Click轻松读卡技术支持:网站:Dim i, j As IntegerDim cardidhex, …...

Java多线程实现之Callable接口深度解析

Java多线程实现之Callable接口深度解析 一、Callable接口概述1.1 接口定义1.2 与Runnable接口的对比1.3 Future接口与FutureTask类 二、Callable接口的基本使用方法2.1 传统方式实现Callable接口2.2 使用Lambda表达式简化Callable实现2.3 使用FutureTask类执行Callable任务 三、…...

高等数学(下)题型笔记(八)空间解析几何与向量代数

目录 0 前言 1 向量的点乘 1.1 基本公式 1.2 例题 2 向量的叉乘 2.1 基础知识 2.2 例题 3 空间平面方程 3.1 基础知识 3.2 例题 4 空间直线方程 4.1 基础知识 4.2 例题 5 旋转曲面及其方程 5.1 基础知识 5.2 例题 6 空间曲面的法线与切平面 6.1 基础知识 6.2…...

如何为服务器生成TLS证书

TLS&#xff08;Transport Layer Security&#xff09;证书是确保网络通信安全的重要手段&#xff0c;它通过加密技术保护传输的数据不被窃听和篡改。在服务器上配置TLS证书&#xff0c;可以使用户通过HTTPS协议安全地访问您的网站。本文将详细介绍如何在服务器上生成一个TLS证…...

12.找到字符串中所有字母异位词

&#x1f9e0; 题目解析 题目描述&#xff1a; 给定两个字符串 s 和 p&#xff0c;找出 s 中所有 p 的字母异位词的起始索引。 返回的答案以数组形式表示。 字母异位词定义&#xff1a; 若两个字符串包含的字符种类和出现次数完全相同&#xff0c;顺序无所谓&#xff0c;则互为…...

EtherNet/IP转DeviceNet协议网关详解

一&#xff0c;设备主要功能 疆鸿智能JH-DVN-EIP本产品是自主研发的一款EtherNet/IP从站功能的通讯网关。该产品主要功能是连接DeviceNet总线和EtherNet/IP网络&#xff0c;本网关连接到EtherNet/IP总线中做为从站使用&#xff0c;连接到DeviceNet总线中做为从站使用。 在自动…...

多种风格导航菜单 HTML 实现(附源码)

下面我将为您展示 6 种不同风格的导航菜单实现&#xff0c;每种都包含完整 HTML、CSS 和 JavaScript 代码。 1. 简约水平导航栏 <!DOCTYPE html> <html lang"zh-CN"> <head><meta charset"UTF-8"><meta name"viewport&qu…...