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

预览和下载 (pc和微信小程序)

1.微信小程序 预览pdf 或者 图片等 //utils.js 文件//通过接口返回文件链接 打开文档 export default function previewFile({ downLinkUrl, tempFilePath }) {let url "https://" downLinkUrl.replace("http://", "").replace("https:…...

使用 DeepSpeed 微调 OPT 基础语言模型

文章目录 OPT 基础语言模型Using OPT with DeepSpeedmain.py 解析1、导入库和模块2、解析命令行参数3、main 函数3.1 设备与分布式初始化3.2 模型与数据准备3.3 定义评估函数3.4 优化器与学习率调度器设置3.5 使用 deepspeed 进行模型等初始化3.6 训练循环3.7 模型保存 4、dsch…...

BSM和BMS什么区别?

BSM BSM&#xff08;Battery System Manager&#xff09;是指用于管理和控制电动车辆的电池系统的设备&#xff0c;其功能包括监测电池状态、控制充放电过程、保护电池安全等。 BMS BMS&#xff08;Battery Management System&#xff09;是指用于监测、控制和保护电池组的设…...

使用Maven打包javaagent.jar

1、简介 javaagent 是 Java1.5 之后引入的新特性&#xff0c;其主要作用是在class被加载之前对其拦截&#xff0c;以插入我们的字节码。 java1.5 之前使用的是JVMTI&#xff08;jvm tool interface&#xff09;技术来实现对class的拦截&#xff0c;不过这个是用 C 编写的&#…...

R语言混合模型回归GBTM群组轨迹模型绘图可视化研究

全文链接&#xff1a;https://tecdat.cn/?p38581 在回归分析的广袤领域中&#xff0c;面对具有多条未知函数线的复杂数据时&#xff0c;传统方法常常捉襟见肘。混合模型作为一种强有力的分析手段应运而生&#xff0c;其在处理此类复杂情境时展现出独特的优势与潜力&#xff08…...

【毕业设计】A079-基于Java的影院订票系统的设计与实现

&#x1f64a;作者简介&#xff1a;在校研究生&#xff0c;拥有计算机专业的研究生开发团队&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的网站项目。 代码可以查看项目链接获取⬇️&#xff0c;记得注明来意哦~&#x1f339; 赠送计算机毕业设计600个选题ex…...

Vue.js前端框架教程11:Vue监听器watch和watchEffect

文章目录 监听器&#xff08;watchers&#xff09;基本用法deep: trueimmediate: true总结 watchEffect基本用法自动追踪依赖停止监听与 watch 的对比性能优化总结 监听器&#xff08;watchers&#xff09; 在 Vue 中&#xff0c;监听器&#xff08;watchers&#xff09;是一种…...

疾风大模型气象系统:精准预报,引领未来

精准预报,引领未来 在当今快速变化的世界中,天气预报已成为日常生活和社会运行中不可或缺的一部分。从规划日常出行到防范极端天气影响,高精准的气象服务正在重新定义我们的生活方式。而在这一领域,疾风大模型气象系统以其卓越的技术实力和领先的预测能力,正引领气象服务…...

U9应收单拉单生成时找不到退货单

财务说做应收单时抓不到一张退货单。2022年单据。这样的单据让人联想翩翩&#xff0c;胡思乱想。怎么复杂怎么想&#xff0c;钻了牛角尖。分析了1天也没有结果。不知道系统的逻辑&#xff0c;只能用猜想的形式去分析。 问过顾问之后&#xff0c;原来是单据类型错了。从而知道了…...

设计模式--单例模式【创建型模式】

设计模式的分类 我们都知道有 23 种设计模式&#xff0c;这 23 种设计模式可分为如下三类&#xff1a; 创建型模式&#xff08;5 种&#xff09;&#xff1a;单例模式、工厂方法模式、抽象工厂模式、建造者模式、原型模式。结构型模式&#xff08;7 种&#xff09;&#xff1…...