question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WPF apps, published with dotnet publish with arguments -p:PublishTrimmed=true or /p:IncludeAllContentInSingleFile=true fails to run

See original GitHub issue
  • .NET Core Version: 3.0.103; 3.1.401; 5.0.100-preview.7
  • Windows version: Windows 10 Pro x64, 2004 (19041.450)
  • Does the bug reproduce also in WPF for .NET Framework 4.8?: No
  • Is this bug related specifically to tooling in Visual Studio (e.g. XAML Designer, Code editing, etc…)?: No

Problem description: WPF apps, published with dotnet publish with arguments -p:PublishTrimmed=true or /p:IncludeAllContentInSingleFile=true (not always, please, read below) fails to run.

Actual behavior: Nothing happens after trying to run the app.

Expected behavior: New window opens.

Minimal repro:

Here’s a simple pwsh script to create a sample wpf-app and publish it. Some of apps runs (as expected), but some not, they’re noted in sript with comments.

dotnet new wpf -o test
Set-Location test

# Runs correctly

dotnet publish -c Release -r win-x64 -o Publish/5/Simple -f net5.0
dotnet publish -c Release -r win-x64 -o Publish/5/Include -f net5.0 /p:IncludeAllContentInSingleFile=true
dotnet publish -c Release -r win-x64 -o Publish/5/R2R -f net5.0 -p:PublishReadyToRun=true
dotnet publish -c Release -r win-x64 -o Publish/5/R2RSingle -f net5.0 -p:PublishReadyToRun=true -p:PublishSingleFile=true
dotnet publish -c Release -r win-x64 -o Publish/5/R2RSingleSelfC -f net5.0 -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true

# Publishes, but not runs

dotnet publish -c Release -r win-x64 -o Publish/5/Trim -f net5.0 -p:PublishTrimmed=true
dotnet publish -c Release -r win-x64 -o Publish/5/R2RSingleSelfCInclude -f net5.0 -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true /p:IncludeAllContentInSingleFile=true
dotnet publish -c Release -r win-x64 -o Publish/5/R2RSingleSelfCTrim -f net5.0 -p:PublishReadyToRun=true -p:PublishSingleFile=true --self-contained true -p:PublishTrimmed=true

Additional info: I must also say, that I’ve tested this script for netcoreapp3.0 and netcoreapp3.1 (with adding TargetFrameworks to .csproj and removing of /p:IncludeAllContentInSingleFile=true, since it appeared in net5.0) and the app still fails to run in same cases. I’ve also tested this for dotnet new console (Hello world) app and it seems to run correctly for all cases.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

11reactions
Fabicommented, Nov 16, 2020

I got the same problem, my app uses the following in the constructor of the App.xaml.cs file:

    public App()
    {
        ProfileOptimization.SetProfileRoot("TheBasePath");
        ProfileOptimization.StartProfile("Startup.Profile");
    }

ProfileOptimization is inside System.Runtime and for some reason executing the following command: dotnet publish Desktop.csproj -c Release -r win-x64 -p:PublishTrimmed=true removes the System.Runtime dll from the publish folder.

I tried to preserve it by using this attribute [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(ProfileOptimization))] but nothing, then I tried using an xml file with the following content:

<linker> <assembly fullname="System.Runtime" preserve="all" /> </linker>

and still nothing…

Is there any way I can preserve this thing ? (Disabling trimming is not an option)

as base you use System.Runtime usually but it doesnt hurt do add these 2 others.

    <ItemGroup>
        <TrimmerRootAssembly Include="System.Runtime" />
        <TrimmerRootAssembly Include="System.Diagnostics.Debug" />
        <TrimmerRootAssembly Include="System.Runtime.Extensions" />
    </ItemGroup>

this will make most normal WPF apps to work

1reaction
Fabicommented, Oct 6, 2020

I’m seeing the same thing with RC1: image

It wasnt merged at the release of RC1. Try https://dotnetcli.blob.core.windows.net/dotnet/Sdk/release/5.0.1xx/dotnet-sdk-latest-win-x64.exe or any other later version than RC1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Single File publish doesn't work with a WPF app
There's no error, it just doesn't start. When I deploy the app without the "single file" option, the app works fine. I'm using...
Read more >
Publish single executable not working for .NET 5 or .NET 6
Solved: Publishing a WPF application as a single executable does not work for .NET 5 (using ArcGIS Runtime 100.12) or .
Read more >
Deploy an app - WPF .NET Framework
Explore the deployment technologies that Windows and the .NET Framework use for Windows Presentation Foundation (WPF) applications.
Read more >
3 Ways to Deploy a WinForms or WPF .NET Core Application
It is very easy. Just call dotnet publish --self-contained true in your working directory and you are almost done. To configure the deployment ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found