Search code examples
linux.net-core.net-6.0

dotnet publish command in linux not taking into account file properties


I created a simple hello world net 6.0 application with the following csproj.

<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>

The following command does not seem to add file and product version (or any other properties for that matter) on the final executable when i run it on linux (tried on ubuntu linux 20.04 as well as a couble of mcr (Microsoft Container Registry) images on gitlab ci). On win 10 it seems to perform as expected.

dotnet publish -r win10-x64 -p:PublishSingleFile=true

linux and windows executable file properties

Any ideas as to what i am missing here or a way to add those information? Thank you

ps: The actual issue involves gitlab cicd, full production software, docker images etc but i believe if i understand what i am missing here the rest should fall in place.


Solution

  • So I'm struggling with this as well (Same situation setting up CI with a Linux based runner)

    From what I'm piecing together it's not good news, during dotnet publish with the correct flags set, the log output displays the following warning: 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).

    After doing some poking about I discovered this Github comment that confirmed my suspicion

    For Windows, the apphost can be customised to include the same Windows resources that your application dll contains: version information, icons, manifests, etc. Unfortunately the customisation currently relies on the Windows API to work, so it means that it can only take place on Windows.

    Unfortunately it looks like it's not possible, time to search for a third party tool.

    EDIT: Searched for a third party tool, and we're going to borrow the help from a nice wee tool Electron made yonks ago :) (Warning this is a bit jank and adds a couple of miniutes onto your pipe, for something that should be so simple) https://github.com/electron/rcedit

      before_script:
        - apt update && apt install npm wine -y
        - npm init -y && npm i [email protected]
      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"