com.unity.ide.visualstudio@2.0.18

## [2.0.18] - 2023-03-17

Integration:

- Performance improvements with `EditorApplication.update` callbacks.

Project generation:

- Add extra compiler options for analyzers and source generators.
This commit is contained in:
Unity Technologies
2023-03-17 00:00:00 +00:00
parent 4893e3bfe7
commit ebe8973267
7 changed files with 78 additions and 28 deletions

View File

@@ -664,33 +664,50 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
}
private string[] GetAnalyzers(Assembly assembly, ResponseFileData[] responseFilesData, out string rulesetPath)
private void SetAnalyzerAndSourceGeneratorProperties(Assembly assembly, ResponseFileData[] responseFilesData, ProjectProperties properties)
{
rulesetPath = null;
if (m_CurrentInstallation == null || !m_CurrentInstallation.SupportsAnalyzers)
return Array.Empty<string>();
return;
// Analyzers provided by VisualStudio
List<string> analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
var analyzers = new List<string>(m_CurrentInstallation.GetAnalyzers());
var additionalFilePaths = new List<string>();
var rulesetPath = string.Empty;
var analyzerConfigPath = string.Empty;
#if UNITY_2020_2_OR_NEWER
// Analyzers + ruleset provided by Unity
analyzers.AddRange(assembly.compilerOptions.RoslynAnalyzerDllPaths);
rulesetPath = assembly
.compilerOptions
.RoslynAnalyzerRulesetPath
.MakeAbsolutePath()
.NormalizePathSeparators();
rulesetPath = assembly.compilerOptions.RoslynAnalyzerRulesetPath;
#endif
// Analyzers provided by csc.rsp
analyzers.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(new[] { "analyzer", "a" })));
#if UNITY_2021_3_OR_NEWER && !UNITY_2022_1 // we have support in 2021.3, 2022.2 but without a backport in 2022.1
additionalFilePaths.AddRange(assembly.compilerOptions.RoslynAdditionalFilePaths);
analyzerConfigPath = assembly.compilerOptions.AnalyzerConfigPath;
#endif
return analyzers
// Analyzers and additional files provided by csc.rsp
analyzers.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(new[] { "analyzer", "a" })));
additionalFilePaths.AddRange(GetOtherArguments(responseFilesData, new HashSet<string>(new[] { "additionalfile" })));
properties.RulesetPath = ToNormalizedPath(rulesetPath);
properties.Analyzers = ToNormalizedPaths(analyzers);
properties.AnalyzerConfigPath = ToNormalizedPath(analyzerConfigPath);
properties.AdditionalFilePaths = ToNormalizedPaths(additionalFilePaths);
}
private string ToNormalizedPath(string path)
{
return path
.MakeAbsolutePath()
.NormalizePathSeparators();
}
private string[] ToNormalizedPaths(IEnumerable<string> values)
{
return values
.Where(a => !string.IsNullOrEmpty(a))
.Select(a => a.MakeAbsolutePath().NormalizePathSeparators())
.Select(a => ToNormalizedPath(a))
.Distinct()
.ToArray();
}
@@ -702,7 +719,6 @@ namespace Microsoft.Unity.VisualStudio.Editor
)
{
var projectType = ProjectTypeOf(assembly.name);
var analyzers = GetAnalyzers(assembly, responseFilesData, out var rulesetPath);
var projectProperties = new ProjectProperties
{
@@ -711,10 +727,7 @@ namespace Microsoft.Unity.VisualStudio.Editor
AssemblyName = assembly.name,
RootNamespace = GetRootNamespace(assembly),
OutputPath = assembly.outputPath,
// Analyzers
RulesetPath = rulesetPath,
// RSP alterable
Analyzers = analyzers,
Defines = assembly.defines.Concat(responseFilesData.SelectMany(x => x.Defines)).Distinct().ToArray(),
Unsafe = assembly.compilerOptions.AllowUnsafeCode | responseFilesData.Any(x => x.Unsafe),
// VSTU Flavoring
@@ -724,6 +737,8 @@ namespace Microsoft.Unity.VisualStudio.Editor
FlavoringPackageVersion = VisualStudioIntegration.PackageVersion(),
};
SetAnalyzerAndSourceGeneratorProperties(assembly, responseFilesData, projectProperties);
GetProjectHeader(projectProperties, out headerBuilder);
}
@@ -830,6 +845,23 @@ namespace Microsoft.Unity.VisualStudio.Editor
}
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}
if (!string.IsNullOrEmpty(properties.AnalyzerConfigPath))
{
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
headerBuilder.Append(@" <EditorConfigFiles Include=""").Append(properties.AnalyzerConfigPath).Append(@""" />").Append(k_WindowsNewline);
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}
if (properties.AdditionalFilePaths.Any())
{
headerBuilder.Append(@" <ItemGroup>").Append(k_WindowsNewline);
foreach (var additionalFile in properties.AdditionalFilePaths)
{
headerBuilder.Append(@" <AdditionalFiles Include=""").Append(additionalFile).Append(@""" />").Append(k_WindowsNewline);
}
headerBuilder.Append(@" </ItemGroup>").Append(k_WindowsNewline);
}
}
private static string GetProjectFooter()

View File

@@ -13,6 +13,9 @@ namespace Microsoft.Unity.VisualStudio.Editor
// Analyzers
public string[] Analyzers { get; set; } = Array.Empty<string>();
public string RulesetPath { get; set; } = string.Empty;
public string AnalyzerConfigPath { get; set; } = string.Empty;
// Source generators
public string[] AdditionalFilePaths { get; set; } = Array.Empty<string>();
// RSP alterable
public string[] Defines { get; set; } = Array.Empty<string>();