【问题标题】:dotnet publish command in linux not taking into account file propertieslinux 中的 dotnet publish 命令不考虑文件属性
【发布时间】:2023-01-31 00:05:00
【问题描述】:
我使用以下 csproj 创建了一个简单的 hello world net 6.0 应用程序。
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>hello_world</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Version>1.0.1-dev</Version>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
</PropertyGroup>
</Project>
当我在 linux 上运行它时(在 ubuntu linux 20.04 以及一对 mcr(Microsoft Container Registry)图像上试过),以下命令似乎没有在最终可执行文件上添加文件和产品版本(或任何其他相关属性)在 gitlab ci 上)。在 win 10 上,它似乎按预期执行。
dotnet publish -r win10-x64 -p:PublishSingleFile=true
关于我在这里缺少什么或添加这些信息的方法有什么想法吗?
谢谢
ps:实际问题涉及 gitlab cicd、完整的生产软件、docker 图像等,但我相信如果我明白我在这里缺少什么,其余的应该就位。
【问题讨论】:
标签:
linux
.net-core
.net-6.0
【解决方案1】:
所以我也在为此苦苦挣扎(使用基于 Linux 的运行器设置 CI 的情况相同)
从我拼凑的内容来看,这不是好消息,在 dotnet publish 期间设置了正确的标志,日志输出显示以下警告:
usr/share/dotnet/sdk/6.0.404/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.targets(554,5): warning NETSDK1074: The application host executable will not be customized because adding resources requires that the build be performed on Windows (excluding Nano Server).
在做了一些探索之后,我发现了这个 Github comment 证实了我的怀疑
对于 Windows,可以自定义 apphost 以包含您的应用程序 dll 包含的相同 Windows 资源:版本信息、图标、清单等。不幸的是,自定义目前依赖于 Windows API 才能工作,因此这意味着它只能发生在 Windows 上。
不幸的是,这似乎是不可能的,是时候搜索第三方工具了。
编辑:搜索了第三方工具,我们将借用 Electron 在 yonks 之前制作的一个不错的小工具的帮助 :)简单)https://github.com/electron/rcedit
before_script:
- apt update && apt install npm wine -y
- npm init -y && npm i rcedit@3.0.1
script:
# pack your dotnet and whatever else you like
after_script:
- wine node_modules/rcedit/bin/rcedit-x64.exe ./my_app.exe --set-product-version "$Semver"