-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support Single-File Apps in .NET 5 #36590
Comments
Tagging subscribers to this area: @swaroop-sridhar |
Single-File deployment support for |
Any chance of implementing this to be single file app for windows? |
@YZahringer Loading single-file apps out-of-proc by IIS should be supported. However, loading single-file apps in-proc is not planned for .net 5. In a single-file app, since host-components (
|
Here's the Table of supported host configuration, thanks to @vitek-karas FD = Framework Dependent
|
@psmulovics: Are you asking about Asp.net/IIS issue, or Windows single-file apps in general? |
@swaroop-sridhar thank you for the answer and the details. This is not blocking, but the structure of the deployed files is not very "clean" at the moment. When deployed in It might be |
@YZahringer unfortunately IIS in process doesn't support single file. Out of process does. |
Is it supposed that all runtimes (Alpine as well) will support PublishReadyToRun flag? |
@Lonli-Lokli did you mean to ask about |
@swaroop-sridhar yep, you are right, it was a typo.
PublishReadyToRun should be supported as well for all runtimes, otherwise SFA cannot be verified for all runtimes. |
This commit implements the following changes for single-file apps: * When publishing self-contained single-file apps: * Use `SingleFileHost` instead of `apphost` * Trim the native components of the runtime published for the app. * Fixes dotnet#11567. * Implements the [optional additional settings](https://github.com/dotnet/designs/blob/master/accepted/2020/single-file/design.md#optional-settings) for .net 5 `PublishSingleFile`. * dotnet/runtime#36590
* Use SingleFileHost This commit implements the following changes for single-file apps: * When publishing self-contained single-file apps: * Use `SingleFileHost` instead of `apphost` * Trim the native components of the runtime published for the app. * Fixes #11567. * Implements the [optional additional settings](https://github.com/dotnet/designs/blob/master/accepted/2020/single-file/design.md#optional-settings) for .net 5 `PublishSingleFile`. * dotnet/runtime#36590 * Address feedback from @dplaisted. * Update global.json (To include update from runtime) * Updating stage0 caused crossgen2 tests to fail because of missing dependencies in the corssgen2 package. Therefore two tests are disabled until dotnet/runtime#37196 is fixed.
I would personally like to see a single-file distribution option that uses a file format that can be associated with the |
Obviously not suggesting this for .NET 5 or anything. Just for the future in general, it would be nice to have a file format that any user with .NET installed can open, without worrying about having a matching native loader. |
Judging by the reactions I guess that isn't a popular idea. To be honest I would be happy even if it weren't a single file, but just a small text file or something that points to an entry point in a DLL, and maybe holds some dependency information and stuff like that. Just anything nicer than a shell script as a portable solution for launching a program. If it's not single-file it starts to be a bit off-topic for this issue though, so let me know if I should open something somewhere else. EDIT: Reading my previous comment I also realize that it made it sound like I was saying I wanted that instead of single native executables. That's not what I meant and I see why ready-to-run self-contained binaries are useful. |
Oh wow, looks like I've found and commented in that issue before, and then forgotten about it. Alright, thanks, I'll be on my way over there. |
@vitek-karas Can you use Assembly.Load on a read-to-run byte[]? |
Is there a #define that is turned on when single file publishing is active? |
Re Re define: There is no define, because single-file is a publish option - so post-build. I can publish the same app multiple times with different settings without rebuilding the app. |
Thanks for the response. Is there any call at runtime I could make to reliably determine the exe is single file, short of a define of my own in the build process? |
If you need to know about a specific assembly, I'd check if |
Mostly agree with @agocke - try to make your decisions based on local knowledge as much as possible. |
Not the original person to ask the question but I can think of a scenario. Various 3rd party libraries and internal solutions for self-updating applications don't clean up unused files from previous updates; only overwrite existing ones and add new files. If the application were to update from for example self contained to single file (with native dependencies); you probably wouldn't want an entire unused second copy of the runtime (assuming no trimming was used). Edit: I implemented this the other day in one of my applications; though FDD Single File WPF applications broke due to dotnet/wpf#3516 in .NET 5 RC1 (this is a regression) so I'm holding out for a bit. I did it by checking if |
This is one of my use cases - automatic software updates and cleaning out non self contained stuff. This code will all be in a shared library. If the new version is self contained, I want to clean out the non-self contained files. |
It seems like dotnet 5.0.100-rc.1.20452.10 produces |
Per the design: https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#user-experience The property was renamed to |
Thank you, @Sewer56, I missed that. I was about to look to see if there was a rename when I see your response. |
While this is marked as closed I'm getting "Including symbols in a single file bundle is not supported when publishing for .NET5 or higher" while using the following publish file:
Issue has no mention that publish files are not supported and I tried to exlude them via setting Debugging Information to None in advanced build settings to no avail. Could someone please clarify if this issue is really closed and if single-file publish is supported in .NET 5? |
@alexb5dh it's likely that somewhere in your project file you have |
Thanks @vitek-karas, that was the case. For those looking for a way to embed pdb - you probably need to set DebugType to embedded, as |
Bundling PDBs would be "weird" in .NET 5 since the assemblies ( |
I just tried to migrate my windows service to .NET 5.0 (entity framework dependency too) and publish a single file exactly as I was doing it before with .NET core 3.1. However, my publish directory contains more than single file as it used to, most importantly |
We've changed single-file to do proper load-from-memory instead of extracting to a temporary directory. Unfortunately we didn't get the runtime all the way down to one file in .NET 5, and native libraries (Microsoft.Data.SqlClient.SNI) cannot be loaded from memory. We're aiming to get the runtime down to one file for 6.0. If you need exactly one file in 5.0 you can extract only the native libraries using |
@agocke thank you for the useful info. The main reason for us to migrate to 5.0 was that binaries will no longer have to be extracted to temp location as we were experiencing a known issue where extracted files were getting deleted randomly from there (I know there is a workaround). So using |
We do not plan to solve the single-file problem with native assets of 3rd party libraries in .NET 6. I expect that |
Out of curiosity. Is this a technical challenge (and if so what) or simple planning/resources reason? |
It is technical and ecosystem challenge. We would need to:
|
The alternative is for NuGet package authors to eliminate unmanaged dependencies by rewriting them in C#. In fact, it is where Microsoft.Data.SqlClient is heading with |
Not quite. Only extracting the native files is significantly less than before, so it may still be a net improvement |
@agocke I meant it is going to be the same because there are going to be more files in the temp folder than just one exe and these files can again get randomly purged, as it is happening. That's why it is "the same" for us, while I of course agree the process was overally improved quite a bit. |
We've also implemented some fixes to validate that the proper files are present whenever the app is started, but you're right: there's still an inherent race condition risk with the file system, and these changes only reduce risk, not eliminate it. |
The goal of this effort is enable .Net-Core apps to be published and distributed as a single executable.
Goals
The .Net 5.0 single file solution should be:
User Experience
Here's the overall experience for publishing a HelloWorld single-file app in .net 5:
Framework-dependent
dotnet publish -r win-x64 --self-contained=false /p:PublishSingleFile=true
HelloWorld.exe
,HelloWorld.pdb
Self-contained (Linux)
dotnet publish -r linux-x64 /p:PublishSingleFile=true
HelloWorld
,HelloWorld.pdb
Self-contained (Windows):
dotnet publish -r win-x64 /p:PublishSingleFile=true
HelloWorld.exe
,HelloWorld.pdb
,coreclr.dll
,clrjit.dll
,clrcompression.dll
,mscordaccore.dll
Self-contained (Windows) with bundled native components:
dotnet publish -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesInSingleFile=true
HelloWorld.exe
,HelloWorld.pdb
Design Document
A detailed discussion of the goals, non-goals, related-work, options, design decisions, and implementation details of supporting single-file apps is available in this design document
Tracking Progress
PublishSingleFile
. Single-File: Update Bundler Invocation. sdk#11586deps.json
andruntimeconfig.json
files directly from bundle. Single-File: Process bundles in the framework #34274SingleFileHost
withAppHost
,HostFxr
, andHostPolicy
statically linked. Single-File: Implement statically linked apphost #32823 Build an apphost with hostfxr and hostpolicy linked in #36230SingleFileHost
with host and runtime components statically linked.CoreCLR
andClrJIT
withSingleFileHost
Single-File: Implement Linux SingleFileHost with statically linked runtime #37119 Host with coreclr linked in #36847SingleFileHost
SingleFile: Statically link core native libraries to Linux SingleFileHost #38304AppContext.BaseDirectory
should return the location of the single-file executable Single-File: Process bundles in the framework #34274The text was updated successfully, but these errors were encountered: