Skip to content
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

Use .NET 8 AOT to produce much smaller distributables #41

Open
kasajian opened this issue May 17, 2024 · 2 comments
Open

Use .NET 8 AOT to produce much smaller distributables #41

kasajian opened this issue May 17, 2024 · 2 comments

Comments

@kasajian
Copy link

Currently, you have to ensure that .NET is installed on the target computer. You can't simple deliver the EXE, unless you do a self-contained EXE, in which case it'll be closer to a 100 MB. I tried the basic example, and it produced a stand-alone exe that's 94,175KB (not counting the 1,544KB webview.dll)

However, .NET AOT can produce tiny DLLs that just a few KB. The result DLLs are not .NET assemblies, but they are standard Windows DLLs that can be P/Invoked from any programming language that can call C functions in a DLL (i.e. every language)

This means, there can be an alternate version of webview_csharp which uses a very simple C++ based "Window" applications so that when it's launched it doesn't create a console, which then loads the webview_csharp created AOT DLL with the user's code. The resulting distributable will be relatively small. One would only need to distribute webview.dll, the shell EXE, and the user's AOT DLL(s), enabling a system where a user can write GUI applications with C# that have a very small distribution.

@kasajian
Copy link
Author

This proposal is different enough that it may make sense to have it be entirely different project to this, but probably many of the bindings can be reused.

@rthomasv3
Copy link

I've been trimming my projects to reduce the binary size. It works pretty well, and I can usually get a single executable between 20 and 50 MB depending on the project and trim mode.

dotnet publish -c Release -r win-x64 --self-contained true -p:PublishSingleFile=true -p:IncludeNativeLibrariesForSelfExtract=true -p:PublishTrimmed=True -p:TrimMode=link

If using things like reflection that don't play well with trimming you can use partial mode or do something like this in the csproj.

  <ItemGroup>
    <TrimmerRootAssembly Include="$(AssemblyName)" />
  </ItemGroup>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants