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

.NET构建后EXE的Product Version出现多余字符的技术问题求助

解决.NET Core 3.1 WinExe Product Version带Git哈希后缀的问题

解决方案

在项目的<PropertyGroup>中添加以下任意一种配置即可解决问题:

方案1:显式指定InformationalVersion

直接设置InformationalVersion为纯版本号,覆盖SDK自动生成的带后缀值:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <AssemblyVersion>1.8.9.28</AssemblyVersion>
    <FileVersion>1.8.9.28</FileVersion>
    <Version>1.8.9.28</Version>
    <InformationalVersion>1.8.9.28</InformationalVersion> <!-- 新增配置 -->
    <PackageIcon>icon.ico</PackageIcon>
    <PackageIconUrl />
    <ApplicationIcon>icon.ico</ApplicationIcon>
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

方案2:禁用Git哈希自动追加

通过配置关闭SDK将Git提交哈希追加到版本号的行为:

<PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>true</UseWindowsForms>
    <AssemblyVersion>1.8.9.28</AssemblyVersion>
    <FileVersion>1.8.9.28</FileVersion>
    <Version>1.8.9.28</Version>
    <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion> <!-- 新增配置 -->
    <PackageIcon>icon.ico</PackageIcon>
    <PackageIconUrl />
    <ApplicationIcon>icon.ico</ApplicationIcon>
    <ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>

问题原因

.NET Core 3.x及以上版本的SDK,当检测到项目处于Git仓库中时,会自动将当前提交的Git哈希值追加到InformationalVersion属性值后(格式为版本号+哈希)。而Windows文件属性中的Product Version默认映射的就是InformationalVersion的值,因此出现了带后缀的版本字符串。

由于.NET的Version类仅支持解析纯四段式版本号(如1.8.9.28),无法识别带+后缀的格式,导致更新检查逻辑无法正常实例化Version对象。

上述两种方案均可让Product Version保持为纯四段式版本号,确保符合更新检查的需求。

内容的提问来源于stack exchange,提问作者Joao Paulo Salles Beraldo

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.05 00:27:04