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.

.NET 5 RC2 WPF self-contained, single exe publish fails if its using assets from another .net 5 wpf project

See original GitHub issue

When referring to a UserControl from another .net core 3.1 wpf project, the main project publish is successful.

When referring to a UserControl from another .net 5 wpf project, the main project publish fails, and outputs:

Could not copy the file “…\singlefilehost.exe” because it was not found.

Main project csproj:
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
  </PropertyGroup>
</Project>
Main project publish settings:
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net5.0-windows\publish\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net5.0-windows</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>False</PublishReadyToRun>
    <PublishTrimmed>False</PublishTrimmed>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
  </PropertyGroup>
</Project>


Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:7

github_iconTop GitHub Comments

2reactions
VictoriaRamirezCharlescommented, Feb 7, 2022

Ok this is not enough, it was a coincidence I guess.

The workaround was :

  • publish the first project as self contained single file x64
  • rename the \obj\Release\net5.0-windows\apphost.exe to singlefilehost.exe
  • publish the other project as self contained single file x64
  • compile my Inno Setup Script, picking the files in the respective \bin\Release\net5.0-windows\publish\ folder

Good answer!!

0reactions
geriwaldcommented, Jul 6, 2021

Ok this is not enough, it was a coincidence I guess.

The workaround was :

  • publish the first project as self contained single file x64
  • rename the \obj\Release\net5.0-windows\apphost.exe to singlefilehost.exe
  • publish the other project as self contained single file x64
  • compile my Inno Setup Script, picking the files in the respective \bin\Release\net5.0-windows\publish\ folder
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 >
Self-Contained Single-File does not produce a single file
Net 5 console application with no dependencies on third party components. I have set it up to publish as a self-contained single-file.
Read more >
Publish single executable not working for .NET 5 or .NET 6
If the exe is moved to another folder it cannot be started. Publishing the WPF application as a single executable works for .NET...
Read more >
Should I use self-contained or framework-dependent ...
In this post I compare the impact of the framework-dependent vs self-contained mode on Docker image size, taking layer caching into account.
Read more >
Breaking change in publish for .net 5 - Developer Community
NET 5, it is no longer possible to generate single file executable in dotnet publish using default configuration.
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