adoconnection / RazorEngineCore

.NET6 Razor Template Engine
MIT License
576 stars 85 forks source link

-p:PublishTrimmed=true and Microsoft.CSharp assembly. #56

Closed chaos072 closed 2 years ago

chaos072 commented 3 years ago

The "-p:PublicTrimmed=true" option causes an error that the Microsoft.CSharp assembly cannot be found.

The full command to publish executable is as follows:

"C:\Program Files\dotnet\dotnet.exe" publish -c Release -r win-x64 --self-contained true -p:PublishReadyToRun=false -p:PublishSingleFile=true -p:PublishTrimmed=true -p:IncludeNativeLibrariesForSelfExtract=true -o publish\release\win-x64

The error that occurs is as follows:

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

File name: 'Microsoft.CSharp, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly.InternalLoad(ObjectHandleOnStack assemblyName, ObjectHandleOnStack requestingAssembly, StackCrawlMarkHandle stackMark, Boolean throwOnFileNotFound, ObjectHandleOnStack assemblyLoadContext, ObjectHandleOnStack retAssembly) at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName assemblyName, RuntimeAssembly requestingAssembly, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, AssemblyLoadContext assemblyLoadContext) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at RazorEngineCore.RazorEngineCompilationOptions..ctor() at RazorEngineCore.RazorEngineCompilationOptionsBuilder..ctor(RazorEngineCompilationOptions options) at RazorEngineCore.RazorEngine.Compile(String content, Action`1 builderAction)

If I do not use the "-p:PublicTrimmed=true" option, errors will not occur and work well. However, if I do not use the "-p:PublicTrimmed=true" option, the executable size will increase from 50MB to 80MB.

adoconnection commented 3 years ago

Hi! I think its due to trimming is still exerimental so I would not count on trimming much :)

adoconnection commented 2 years ago

closing this issue since this is a compiler problem