You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过dotnet CLI主动修改.csproj文件的语义化版本

dotnet CLI修改项目版本号的实现方案

.NET CLI没有内置和npm version、mvn versions:set完全对等的原生命令,有以下几种成熟方案可以直接修改.csproj文件中的版本节点:

  • 方案1:使用第三方全局工具dotnet-version-cli(最接近npm version的使用体验)
    1. 首先安装工具:dotnet tool install --global dotnet-version-cli
    2. 直接指定新版本:dotnet version 1.2.3.4,执行后会直接修改.csproj文件中的<Version>节点
    3. 也支持按版本位递进升级:
      • 升级主版本:dotnet version --major
      • 升级次版本:dotnet version --minor
      • 升级补丁版本:dotnet version --patch
  • 方案2:使用脚本手动修改(无需额外安装工具)
    Windows PowerShell参考脚本:
    $csprojPath = "替换为你的项目.csproj路径"
    $newVersion = "1.2.3.4"
    $xml = [Xml](Get-Content $csprojPath)
    $xml.Project.PropertyGroup.Version = $newVersion
    $xml.Save($csprojPath)
    
    Linux/macOS Bash参考脚本:
    # 需要提前安装xmlstarlet工具
    csprojPath="替换为你的项目.csproj路径"
    newVersion="1.2.3.4"
    xmlstarlet edit -L -u "/Project/PropertyGroup/Version" -v "$newVersion" "$csprojPath"
    

内容的提问来源于stack exchange,提问作者Vivere

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 23:48:02