Skip to content

Commit fb7dfbc

Browse files
sailroGitHub Enterprise
authored andcommitted
Merge pull request #165 from unity/fix-patch-release-api-2021.3
Fix access to missing properties, only introduced in a 2021.3 patch release
2 parents a369a75 + 404c410 commit fb7dfbc

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

Packages/com.unity.ide.visualstudio/Editor/ProjectGeneration/ProjectGeneration.cs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -674,16 +674,25 @@ private void SetAnalyzerAndSourceGeneratorProperties(Assembly assembly, Response
674674
var additionalFilePaths = new List<string>();
675675
var rulesetPath = string.Empty;
676676
var analyzerConfigPath = string.Empty;
677+
var compilerOptions = assembly.compilerOptions;
677678

678679
#if UNITY_2020_2_OR_NEWER
679680
// Analyzers + ruleset provided by Unity
680-
analyzers.AddRange(assembly.compilerOptions.RoslynAnalyzerDllPaths);
681-
rulesetPath = assembly.compilerOptions.RoslynAnalyzerRulesetPath;
681+
analyzers.AddRange(compilerOptions.RoslynAnalyzerDllPaths);
682+
rulesetPath = compilerOptions.RoslynAnalyzerRulesetPath;
682683
#endif
683684

684-
#if UNITY_2021_3_OR_NEWER && !UNITY_2022_1 // we have support in 2021.3, 2022.2 but without a backport in 2022.1
685-
additionalFilePaths.AddRange(assembly.compilerOptions.RoslynAdditionalFilePaths);
686-
analyzerConfigPath = assembly.compilerOptions.AnalyzerConfigPath;
685+
// We have support in 2021.3, 2022.2 but without a backport in 2022.1
686+
#if UNITY_2021_3
687+
// Unfortunately those properties were introduced in a patch release of 2021.3, so not found in 2021.3.2f1 for example
688+
var scoType = compilerOptions.GetType();
689+
var afpProperty = scoType.GetProperty("RoslynAdditionalFilePaths");
690+
var acpProperty = scoType.GetProperty("AnalyzerConfigPath");
691+
additionalFilePaths.AddRange(afpProperty?.GetValue(compilerOptions) as string[] ?? Array.Empty<string>());
692+
analyzerConfigPath = acpProperty?.GetValue(compilerOptions) as string ?? analyzerConfigPath;
693+
#elif UNITY_2022_2_OR_NEWER
694+
additionalFilePaths.AddRange(compilerOptions.RoslynAdditionalFilePaths);
695+
analyzerConfigPath = compilerOptions.AnalyzerConfigPath;
687696
#endif
688697

689698
// Analyzers and additional files provided by csc.rsp

0 commit comments

Comments
 (0)