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.

PublishSingleFile=true does not include Content files

See original GitHub issue

I am working with a (non-web) .NET Core 3.0 console application and I am trying to use PublishSingleFile=true. While the single-file aspect does indeed work (I get one executable file), my application always crashes due to missing appsettings.json files. I’ve tried setting the files to Content/None, Copy Always/Newest. I also tried adding <CopyToPublishDirectory>true</CopyToPublishDirectory> and yet nothing seems to work.

If I create a brand new fresh Web-SDK project, the single file publish works and the content files are dropped right next to the published executable. I tried comparing the starter web project to my console application and I don’t see a difference.

The easiest reproduction I have is to create a blank console application project, add a text file to the project (as content or none) and then publish with the PublishSingleFile=true. The output does not contain the content files.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <PublishSingleFile>true</PublishSingleFile>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="MyContentFile.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Always</CopyToPublishDirectory>
    </Content>
  </ItemGroup>
</Project>

Is this supposed to work for non-Web projects?

.NET Core SDK (reflecting any global.json): Version: 3.0.100 Commit: 04339c3a26

Runtime Environment: OS Name: Windows OS Version: 10.0.18362 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support): Version: 3.0.0 Commit: 95a0a61858

.NET Core SDKs installed: 3.0.100-rc1-014190 [C:\Program Files\dotnet\sdk] 3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed: Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
swaroop-sridharcommented, Oct 21, 2019

Hi @pinkfloydx33 for in the case of PublishSingleFile all published content is bundled into the single-file. If we need files to be left behind in the publish directory, we need to set the ExcludeFromSingleFile property. In your example:

    <Content Include="MyContentFile.txt">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Always</CopyToPublishDirectory>
     <ExcludeFromSingleFile>true</ExcludeFromSingleFile> 
    </Content>

For more details, please see: https://github.com/dotnet/designs/blob/master/accepted/single-file/design.md#build-system-interface

Dup of https://github.com/dotnet/core-setup/issues/7738

0reactions
mohamedhamza7commented, Jul 4, 2021

Dears, Is there is a way to excluded Package Reference DLLs from being bundled in single file application? I am working on WPF application .NET 5.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

PublishSingleFile does not produce a single executable
I have a .Net Core 3 console application that i'm trying to publish as a self contained single executable. I've been able to...
Read more >
Self-Contained Single-File does not produce a single file
I have set it up to publish as a self-contained single-file. However, in the publish directory is the EXE file and four DLLs....
Read more >
Too many dlls when publishing dotnet
Hi. I'm developing a game in c# using sfml on linux. I wanted to give it to a person on windows, so I...
Read more >
Building with PublishSingleFile on 3.8.1 doesn't create a ...
Hey all, I upgraded my project to 3.8.1, and now, when I try to publish using msbuild's PublishSingleFile parameter, I get many files,...
Read more >
Publishing A Single EXE File In .NET Core 3.0
I tried explicitly specifying the –self-contained param after the -p:PublishSingleFile=true param. It still doesn't work. Also, the SingleFile/ReadyToRun ...
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