'WPF app broken binding when publishing with gitlab CI/CD

I have a WPF application which works perfectly fine when publishing via Visual Studio 2022. I have created autodeploy gitlab script which builds, publishes and deploy the application. Script works as expected, but the application it builds has a lot of broken bindings in it. I have also noticed that broken application is 8kB smaller.

My script is using msbuild located at Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\msbuild. Whole publish script looks as follows & "$env:MSBUILD_PATH" -t:Restore,Clean,Build,Publish -p:PublishProfile=profile.pubxml "$env:CS_PROJ_PATH". It is using the same PublishProfile that I'm using when publishing via VS22.

The gitlab runner is running as user service at the same desktop with this configuration:

[[runners]]
  name = "name"
  url = "https://git.example.cz"
  token = "hashed_token"
  executor = "shell"
  shell = "powershell"
  [runners.custom_build_dir]
  [runners.cache]
    [runners.cache.s3]
    [runners.cache.gcs]
    [runners.cache.azure]

The publish profile configuration:

<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net6.0-windows\publishOneFile</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net6.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishReadyToRun>false</PublishReadyToRun>
  </PropertyGroup>
</Project>

The csproj file:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <RootNamespace>MyRootNamespace</RootNamespace>
    <UseWPF>true</UseWPF>
    <Platforms>AnyCPU;x86</Platforms>
      <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
  </PropertyGroup>

  <ItemGroup>
    <Page Remove="Theme\GeneralTheme.xaml" />
  </ItemGroup>

  <ItemGroup>
    <Resource Include="Theme\GeneralTheme.xaml" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="FontAwesome.WPF" Version="4.7.0.9" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="AutoMapper" Version="10.1.1" />
    <PackageReference Include="MvvmLight" Version="5.4.1.1" />
    <PackageReference Include="MvvmLightLibs" Version="5.4.1.1" />
    <PackageReference Include="Ninject" Version="3.3.4" />
    <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="6.0.0" />
    <PackageReference Include="PDFiumCore" Version="98.0.4706" />
    <PackageReference Include="PropertyChanged.Fody" Version="3.4.0" />
    <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
    <PackageReference Include="System.Linq.Dynamic.Core" Version="1.2.15" />
    <PackageReference Include="System.Windows.Interactivity.WPF" Version="2.0.20525" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\Shared\Shared.csproj" />
  </ItemGroup>

</Project>

Things I have already tried:

  1. Manually running the publishing command in the powershell console - builds fine.
  2. The 1. item but in the build folder which gitlab runner creates.
  3. Ensuring that publish script is using the publish profile configuration.
  4. Not using publish profile config file. I have instead used -p:Configuration=Release and similiar configs.
  5. Not publishing the application as single file.
  6. Changing configuration to build as only x64 or x86.
  7. Ensuring that output in CI/CD console is the same as runnig it manually in console.


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source