From 005710aa37ac67ef390b5e90d8e680bb4f436da9 Mon Sep 17 00:00:00 2001 From: Tareq Imbasher Date: Sun, 29 Oct 2023 01:15:22 +0200 Subject: [PATCH] Allows unsafe code --- src/Core/NetPad.Compilation/CSharp/CSharpCodeCompiler.cs | 4 ++-- .../NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Core/NetPad.Compilation/CSharp/CSharpCodeCompiler.cs b/src/Core/NetPad.Compilation/CSharp/CSharpCodeCompiler.cs index a3169a74..00d30731 100644 --- a/src/Core/NetPad.Compilation/CSharp/CSharpCodeCompiler.cs +++ b/src/Core/NetPad.Compilation/CSharp/CSharpCodeCompiler.cs @@ -22,7 +22,6 @@ public CSharpCodeCompiler(IDotNetInfo dotNetInfo) public CompilationResult Compile(CompilationInput input) { - // TODO write a unit test to test assembly name string assemblyName = "NetPad_CompiledAssembly"; if (input.OutputAssemblyNameTag != null) @@ -60,7 +59,8 @@ private CSharpCompilation CreateCompilation(CompilationInput input, string assem var compilationOptions = new CSharpCompilationOptions(input.OutputKind) .WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) .WithOptimizationLevel(OptimizationLevel.Debug) - .WithOverflowChecks(true); + .WithOverflowChecks(true) + .WithAllowUnsafe(true); return CSharpCompilation.Create(assemblyName, new[] { parsedSyntaxTree }, diff --git a/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs b/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs index 40cc563f..0e96c208 100644 --- a/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs +++ b/src/Plugins/NetPad.Plugins.OmniSharp/Services/AppOmniSharpServer.cs @@ -76,10 +76,14 @@ public AppOmniSharpServer( public async Task StartAsync() { _logger.LogDebug("Initializing script project for script: {Script}", _environment.Script); + await Project.CreateAsync( _environment.Script.Config.TargetFrameworkVersion, ProjectOutputType.Executable, true); + + await Project.SetProjectPropertyAsync("AllowUnsafeBlocks", "true"); + await Project.RestoreAsync(); InitializeEventHandlers();