Publish single file
josago97 opened this issue · 11 comments
I tried to publish my project with the single file option enabled and the executable is created with the separate www folder. Is there a way, without having to resort to third-party programs, to have everything embedded in an .exe?
Thanks.
@josago97 We honestly don't know. We haven't any experience with creating single file outputs. Maybe someone in the community can chime in?
If you are using blazor, thats not how it works, create an executale or bat file and use the dotned command to start your app. I dont think blazor apps can be compiled to single executable, but i cant swear to that.
I am using Blazor, which, when publishing, generates a www folder separate from the .exe file. In Electron it has the same behavior by default, it generates some folders separate from the executable. However, there appears to be an Electron plugin that allows you to publish to a single file as a portable application (https://github.com/rabbit-hole-syndrome/electron-forge-maker-portable). I don't know how it will work inside, but it would be nice to have some option, if possible, to achieve the same effect in Photino since having everything in a single .exe is very convenient.
to embed wwwroot all you need is:
csproj:
<ItemGroup>
<EmbeddedResource Include="wwwroot\**" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="8.0.0" /> <-- ADD THIS
<PackageReference Include="Microsoft.AspNetCore.Components.WebView" Version="8.0.0" />
</ItemGroup>
<PropertyGroup>
...
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
program.cs:
...
var appBuilder = PhotinoBlazorAppBuilder.CreateDefault(args);
appBuilder.Services
.AddLogging()
.AddSingleton<IFileProvider>(_ =>
new ManifestEmbeddedFileProvider(
typeof(Program).Assembly,
"wwwroot"));
...
then in your publish folder just delete the wwwroot
folder and it will work.
EDIT:
with native aot we should be able to get single exe but currently because of a bug with .net 8 we cant load it correctly:
about the other dlls, we can statically build the photino.native.dll into a static library and compile it with native aot using NativeLibrary
directive in the csproj. im not really sure with the other dll though.
The html works but the styles are not applied.
that could be because you are using generated css that is not included in the wwwroot. you might be able to follow this post to embed the generated css file: https://stackoverflow.com/questions/69366052/how-to-embed-the-scoped-css-bundle-file-generated-by-razor-class-library
@josago97 Does this solve your issue?
What user ivanjx has been talking about is to make a single file application that works well with CSS files that are inside the wwwroot. However, the css files that Blazor automatically generates are not caught by Blazor. The stackoverflow forum discussion explains how to fix it via a patch. That patch consists of creating a Razor library and putting the logic there, linking it with the main project and then including everything in the executable. Honestly, it is not the solution I was looking for at first, it would be better if it could be done without the need for patches or external projects.
@philippjbauer is planning on creating some documentation around distribution strategies on all 3 platforms. One approach is using .NET's publish to single file capability where you can include these runtime files in the single file executable. It would be very helpful if you could create a simple example and share the github repo so we can test with your example.
while using .net's single file publish is good for most, it would be great to also incorporate the idea around native aot single file publishing (by leveraging native static library). not only it will reduce the size greatly, it will also perform better.
Closing this since #94 (comment) solves the issue. The AOT capability is tracked in #106