From a5ec759c9c4505fe29303a68171bbb000dd41983 Mon Sep 17 00:00:00 2001 From: neuecc Date: Wed, 2 Nov 2022 21:40:06 +0900 Subject: [PATCH] configure for unit test --- .../MemoryPack.Generator.Roslyn3.csproj | 2 +- src/MemoryPack.Generator.Roslyn3/MemoryPackGenerator.cs | 7 ++++++- .../Properties/launchSettings.json | 4 ++-- .../MemoryPack.Tests.Roslyn3.csproj | 7 +++++++ 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/MemoryPack.Generator.Roslyn3/MemoryPack.Generator.Roslyn3.csproj b/src/MemoryPack.Generator.Roslyn3/MemoryPack.Generator.Roslyn3.csproj index e47b4414..64972ab6 100644 --- a/src/MemoryPack.Generator.Roslyn3/MemoryPack.Generator.Roslyn3.csproj +++ b/src/MemoryPack.Generator.Roslyn3/MemoryPack.Generator.Roslyn3.csproj @@ -1,4 +1,4 @@ - + netstandard2.0 diff --git a/src/MemoryPack.Generator.Roslyn3/MemoryPackGenerator.cs b/src/MemoryPack.Generator.Roslyn3/MemoryPackGenerator.cs index 2f95042a..0b803f05 100644 --- a/src/MemoryPack.Generator.Roslyn3/MemoryPackGenerator.cs +++ b/src/MemoryPack.Generator.Roslyn3/MemoryPackGenerator.cs @@ -30,6 +30,11 @@ public void Execute(GeneratorExecutionContext context) var compiation = context.Compilation; var generateContext = new GeneratorContext(context); + if (context.AnalyzerConfigOptions.GlobalOptions.TryGetValue("build_property.MemoryPackGenerator_DebugNonUnityMode", out var nonUnity)) + { + generateContext.IsForUnity = !bool.Parse(nonUnity); + } + foreach (var syntax in receiver.ClassDeclarations) { Generate(syntax, compiation, logPath, generateContext); @@ -82,7 +87,7 @@ public GeneratorContext(GeneratorExecutionContext context) public bool IsNet7OrGreater => false; // No IncrementalGenerator is always not NET7 - public bool IsForUnity => true; + public bool IsForUnity { get; set; } = true; public void AddSource(string hintName, string source) { diff --git a/src/MemoryPack.Generator.Roslyn3/Properties/launchSettings.json b/src/MemoryPack.Generator.Roslyn3/Properties/launchSettings.json index 030db181..6e922050 100644 --- a/src/MemoryPack.Generator.Roslyn3/Properties/launchSettings.json +++ b/src/MemoryPack.Generator.Roslyn3/Properties/launchSettings.json @@ -2,7 +2,7 @@ "profiles": { "MemoryPack.Generator.Roslyn3.11": { "commandName": "DebugRoslynComponent", - "targetProject": "..\\..\\sandbox\\SandboxNet6\\SandboxNet6.csproj" + "targetProject": "..\\..\\tests\\MemoryPack.Tests.Roslyn3\\MemoryPack.Tests.Roslyn3.csproj" } } -} +} \ No newline at end of file diff --git a/tests/MemoryPack.Tests.Roslyn3/MemoryPack.Tests.Roslyn3.csproj b/tests/MemoryPack.Tests.Roslyn3/MemoryPack.Tests.Roslyn3.csproj index 035c9d99..0ca11248 100644 --- a/tests/MemoryPack.Tests.Roslyn3/MemoryPack.Tests.Roslyn3.csproj +++ b/tests/MemoryPack.Tests.Roslyn3/MemoryPack.Tests.Roslyn3.csproj @@ -20,6 +20,13 @@ + + + + + true + +