adoconnection / RazorEngineCore

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

dotnet7 single file #126

Closed yuzd closed 9 months ago

yuzd commented 1 year ago

when i publish to single file , Complie method get this errors:

 ---> System.IO.FileNotFoundException:
File name: 'System.Runtime, Culture=neutral, PublicKeyToken=null'
   at System.Reflection.RuntimeAssembly.<InternalLoad>g____PInvoke|47_0(NativeAssemblyNameParts*, ObjectHandleOnStack, StackCrawlMarkHandle, Int32, ObjectHandleOnStack, ObjectHandleOnStack)
   at System.Reflection.RuntimeAssembly.InternalLoad(NativeAssemblyNameParts*, ObjectHandleOnStack, StackCrawlMarkHandle, Boolean , ObjectHandleOnStack, ObjectHandleOnStack)
   at System.Reflection.RuntimeAssembly.InternalLoad(AssemblyName, StackCrawlMark&, AssemblyLoadContext , RuntimeAssembly , Boolean )
   at System.Reflection.Assembly.Load(AssemblyName)
   at RazorEngineCore.RazorEngineCompilationOptions..ctor()
   at RazorEngineCore.RazorEngineCompilationOptionsBuilder..ctor(RazorEngineCompilationOptions )
   at RazorEngineCore.RazorEngine.Compile(String, Action`1 )
adoconnection commented 1 year ago

thanks for reporting. Apparently something might have changed with single files in dotnet7

A9G-Data-Droid commented 9 months ago

I have seen a similar error. If you have any native libraries in your project, you need to take a look at the documentation on single file publishing

Try turning on IncludeNativeLibrariesForSelfExtract either in the FolderProfile.pubxml with:

<IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>

OR

If you're using a build pipeline you can pass the command-line parameter:

dotnet publish -c Release -r win-arm64 -p:IncludeNativeLibrariesForSelfExtract=true

EXPLANATION: The single file packer only includes managed libraries by default. When you run a single file application it is unpacking all the files at startup. It then can't fine the native binary and throws a file not found. If you put a copy of the native dll in the same folder as the single file package it will run but then it's not a single file anymore...

adoconnection commented 9 months ago

I did a quick test: changed framework of ExampleAppCore to NET7 and executed dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained false -c Release

it worked

yuzd commented 9 months ago

thanks , it worked....