From 356651c58ba75df40219e5f7bac9247bd6b4f802 Mon Sep 17 00:00:00 2001 From: LPeter1997 Date: Sat, 21 Oct 2023 18:25:45 +0200 Subject: [PATCH] Added Basic conditionally to CLI --- src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj | 1 + src/Draco.Compiler.Cli/Program.cs | 16 ++++++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj b/src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj index 77469804f..3062a806c 100644 --- a/src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj +++ b/src/Draco.Compiler.Cli/Draco.Compiler.Cli.csproj @@ -18,5 +18,6 @@ + diff --git a/src/Draco.Compiler.Cli/Program.cs b/src/Draco.Compiler.Cli/Program.cs index badbe653d..8461e0dc5 100644 --- a/src/Draco.Compiler.Cli/Program.cs +++ b/src/Draco.Compiler.Cli/Program.cs @@ -110,9 +110,7 @@ private static void CompileCommand(FileInfo[] input, FileInfo output, DirectoryI var (path, name) = ExtractOutputPathAndName(output); var compilation = Compilation.Create( syntaxTrees: syntaxTrees, - metadataReferences: references - .Select(r => MetadataReference.FromPeStream(r.OpenRead())) - .ToImmutableArray(), + metadataReferences: GetMetadataReferences(references), rootModulePath: rootModule?.FullName, outputPath: path, assemblyName: name); @@ -131,9 +129,7 @@ private static void RunCommand(FileInfo[] input, DirectoryInfo? rootModule, File var syntaxTrees = GetSyntaxTrees(input); var compilation = Compilation.Create( syntaxTrees: syntaxTrees, - metadataReferences: references - .Select(r => MetadataReference.FromPeStream(r.OpenRead())) - .ToImmutableArray(), + metadataReferences: GetMetadataReferences(references), rootModulePath: rootModule?.FullName); var execResult = ScriptingEngine.Execute(compilation); if (!EmitDiagnostics(execResult, msbuildDiags)) @@ -193,6 +189,14 @@ private static ImmutableArray GetSyntaxTrees(params FileInfo[] input return result.ToImmutable(); } + private static ImmutableArray GetMetadataReferences(FileInfo[] references) => references + .Select(r => MetadataReference.FromPeStream(r.OpenRead())) +#if DEBUG + .Concat(Basic.Reference.Assemblies.Net70.ReferenceInfos.All + .Select(r => MetadataReference.FromPeStream(new MemoryStream(r.ImageBytes)))) +#endif + .ToImmutableArray(); + private static bool EmitDiagnostics(EmitResult result, bool msbuildDiags) { if (result.Success) return false;