-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Milestone
Description
Hi,
I use the following code to run C# scripts in my software. Everything is fine under .NET 5.0 when I publish the software without PublishSingleSingle
option.
ScriptOptions options = ScriptOptions.Default
.WithMetadataResolver(ScriptMetadataResolver.Default.WithSearchPaths(new[] { RuntimeEnvironment.GetRuntimeDirectory(), AppInfo.StartupFolder }))
.WithSourceResolver(new SourceFileResolver(ImmutableArray<string>.Empty, AppInfo.ScriptsFolder))
.AddReferences(Assembly.GetExecutingAssembly()); // Assembly.Location returns "" with PublishSingleFile option, but using Environment.GetCommandLineArgs()[0] instead Assembly.GetExecutingAssembly() doesn't work too
Script script = CSharpScript.Create(code, options, typeof(GlobalVariables));
//Script script = CSharpScript.Create(code, null, null); // using CSharpScript with default parameter doesn't work too
script.Compile();
But when I publish my software with the PublishSingleFile
option, the code doesn't work anymore and I get the error:
"can't create a metadata reference to an assembly without location".
Is there is a way to reference my main assembly and/or .NET 5.0 system assemblies embedded in the main executable?
Is there any code sample to use the CSharpScript
API when PublishSingleFile
is enabled?
Thanks for your help.
jamers99, freddyrios, Sergio1C, Viir, EliAaron and 3 more