From 5953f765dcdde71c821c67dbd49481fe29428824 Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Mon, 26 Feb 2024 13:25:04 +0800 Subject: [PATCH] Fixes for compiling multi contracts in single csproj (#953) --- src/Neo.Compiler.CSharp/CompilationEngine.cs | 3 ++- src/Neo.Compiler.CSharp/Program.cs | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/Neo.Compiler.CSharp/CompilationEngine.cs b/src/Neo.Compiler.CSharp/CompilationEngine.cs index 9d46344a6..951a57b5e 100644 --- a/src/Neo.Compiler.CSharp/CompilationEngine.cs +++ b/src/Neo.Compiler.CSharp/CompilationEngine.cs @@ -172,8 +172,9 @@ public Compilation GetCompilation(string csproj) { string folder = Path.GetDirectoryName(csproj)!; string obj = Path.Combine(folder, "obj"); + string binSc = Path.Combine(Path.Combine(folder, "bin"), "sc"); HashSet sourceFiles = Directory.EnumerateFiles(folder, "*.cs", SearchOption.AllDirectories) - .Where(p => !p.StartsWith(obj)) + .Where(p => !p.StartsWith(obj) && !p.StartsWith(binSc)) .GroupBy(Path.GetFileName) .Select(g => g.First()) .ToHashSet(StringComparer.OrdinalIgnoreCase); diff --git a/src/Neo.Compiler.CSharp/Program.cs b/src/Neo.Compiler.CSharp/Program.cs index 8738fd365..355c4dd6c 100644 --- a/src/Neo.Compiler.CSharp/Program.cs +++ b/src/Neo.Compiler.CSharp/Program.cs @@ -138,7 +138,22 @@ private static int ProcessSources(Options options, string folder, string[] sourc private static int ProcessOutputs(Options options, string folder, List contexts) { - return contexts.Select(p => ProcessOutput(options, folder, p)).Any(p => p != 1) ? 0 : 1; + int result = 0; + List exceptions = new(); + foreach (CompilationContext context in contexts) + try + { + if (ProcessOutput(options, folder, context) != 0) + result = 1; + } + catch (Exception e) + { + result = 1; + exceptions.Add(e); + } + foreach (Exception e in exceptions) + Console.Error.WriteLine(e.ToString()); + return result; } private static int ProcessOutput(Options options, string folder, CompilationContext context)