Search code examples
c#.net-coreroslyn.net-5.net-core-publishsinglefile

Is it possible to build Deterministic Single File assemblies in dotnet/roslyn?


I'm using .Net 5 (c#).

There is a roslyn flag Deterministic=true that given identical inputs (i.e. source code and some other environment stuff) will produce bit-for-bit identical assemblies.

When I do a normal build, and build multiple times this works as expected.

Deterministic Build

However that generates an output dir with 121 files (all the dependencies, e.g. System.*.dll files). I'd like to have a single exe file, which is what the PublishSingleFile flag does. But when I use the PublishSingleFile flag, I no longer get a deterministic output.

Single File Non-Deterministic

Any idea if there is a way to make this work? Or is the combination of these 2 flags not supported?


Solution

  • It's not currently supported. The current focus is mostly on generating reproducible IL and validation.

    https://github.com/dotnet/designs/blob/main/accepted/2020/reproducible-builds.md

    Building a managed binary involves many components, including ResX, XAML->BAML, strong naming, and MSBuild, that can be customized in countless different ways. This effort focuses only on the executable code, ignoring strong naming, resource generation, re-running source generators, etc.