使用 dotnet 发布时设置 exe 文件版本
Setup exe file version when publishing with dotnet
我有一个net core consoleapp项目,如下(VS 2017风格):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Version>2.0.0</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>4.0.0.0</FileVersion>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
我可以毫无问题地构建项目,我可以使用 dotnet publish -r win10-x64 发布它,它会生成一个 exe 文件和 dll 文件。我的问题是 exe 文件有一些奇怪的 FileVersion 和 ProductVersion 字段(在我的例子中 FileVersion = 1.0.1.4500 和 ProductVersion 1.0.1.cee57 ...(一些 guid))。此外,其余文件详细信息(名称、版权)与 dotnet 有关,而不是我自己的项目。
有什么方法可以控制发布时的exe细节吗?
不,您项目的主要构建输出仍然是一个 .dll
文件,.exe(或 linux、mac 可执行文件)文件是复制并重命名的 dotnet.exe
(或者在即将推出的 2.0 版本中,apphost.exe
将 dll 名称嵌入 运行)。
exe 文件只是引导 运行 时间然后加载您的 dll 的助手。但是,您可以尝试使用editbin.exe
(VS C++ Tools) 等二进制编辑工具在发布后修改文件。
Dotnet 核心 3.0 添加了在发布期间对 shim exe 进行版本控制的功能,就像 OP 所期望的那样。它现在应该开箱即用。但是,如果 运行 构建在基于 Nanoserver 的 docker 环境中,该功能将不起作用。
warning NETSDK1074: The application host executable will not be
customized because adding resources requires that the build be
performed on Windows (excluding Nano Server)
我有一个net core consoleapp项目,如下(VS 2017风格):
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.1</TargetFramework>
<Version>2.0.0</Version>
<AssemblyVersion>3.0.0.0</AssemblyVersion>
<FileVersion>4.0.0.0</FileVersion>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<RuntimeFrameworkVersion>1.0.4</RuntimeFrameworkVersion>
</PropertyGroup>
</Project>
我可以毫无问题地构建项目,我可以使用 dotnet publish -r win10-x64 发布它,它会生成一个 exe 文件和 dll 文件。我的问题是 exe 文件有一些奇怪的 FileVersion 和 ProductVersion 字段(在我的例子中 FileVersion = 1.0.1.4500 和 ProductVersion 1.0.1.cee57 ...(一些 guid))。此外,其余文件详细信息(名称、版权)与 dotnet 有关,而不是我自己的项目。
有什么方法可以控制发布时的exe细节吗?
不,您项目的主要构建输出仍然是一个 .dll
文件,.exe(或 linux、mac 可执行文件)文件是复制并重命名的 dotnet.exe
(或者在即将推出的 2.0 版本中,apphost.exe
将 dll 名称嵌入 运行)。
exe 文件只是引导 运行 时间然后加载您的 dll 的助手。但是,您可以尝试使用editbin.exe
(VS C++ Tools) 等二进制编辑工具在发布后修改文件。
Dotnet 核心 3.0 添加了在发布期间对 shim exe 进行版本控制的功能,就像 OP 所期望的那样。它现在应该开箱即用。但是,如果 运行 构建在基于 Nanoserver 的 docker 环境中,该功能将不起作用。
warning NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server)