Skip to content

Commit 39da6dd

Browse files
authored
Nit Compatiblity tools improvements (#45685)
1 parent daa12f2 commit 39da6dd

File tree

12 files changed

+25
-15
lines changed

12 files changed

+25
-15
lines changed

exclusion.dic

+2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
awaiter
22
crossgen
3+
csharp
34
cshtml
45
deserializer
56
msbuild
67
nuget
78
nupkg
89
nuspec
10+
roslyn
911
sdk
1012
sdks
1113
tfm

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ApiCompatServiceProvider.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ public ApiCompatServiceProvider(Func<ISuppressionEngine, ISuppressibleLog> logFa
3232

3333
// The attribute data symbol filter is a composite that contains both the accessibility
3434
// symbol filter and the doc id symbol filter.
35-
CompositeSymbolFilter attributeDataSymbolFilter = new CompositeSymbolFilter()
36-
.Add(accessibilitySymbolFilter);
35+
CompositeSymbolFilter attributeDataSymbolFilter = new(accessibilitySymbolFilter);
3736
if (excludeAttributesFiles is not null)
3837
{
3938
attributeDataSymbolFilter.Add(new DocIdSymbolFilter(excludeAttributesFiles));

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class RegexStringTransformer
1919
/// <param name="replacementString">The replacement string that contains the capture group markers (i.e. $1).</param>
2020

2121
public RegexStringTransformer(string captureGroupPattern, string replacementString)
22-
: this(new (string, string)[] { (captureGroupPattern, replacementString) })
22+
: this([(captureGroupPattern, replacementString)])
2323
{
2424
}
2525

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ public void Unregister()
6464
private Assembly? LoadRoslyn(AssemblyName name, Func<string, Assembly> loadFromPath)
6565
{
6666
const string codeAnalysisName = "Microsoft.CodeAnalysis";
67-
const string codeAnalysisCsharpName = "Microsoft.CodeAnalysis.CSharp";
67+
const string codeAnalysisCSharpName = "Microsoft.CodeAnalysis.CSharp";
6868

69-
if (name.Name == codeAnalysisName || name.Name == codeAnalysisCsharpName)
69+
if (name.Name == codeAnalysisName || name.Name == codeAnalysisCSharpName)
7070
{
7171
Assembly asm = loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{name.Name}.dll"));
7272
Version? resolvedVersion = asm.GetName().Version;
@@ -78,7 +78,7 @@ public void Unregister()
7878
// Being extra defensive but we want to avoid that we accidentally load two different versions of either
7979
// of the roslyn assemblies from a different location, so let's load them both on the first request.
8080
if (name.Name == codeAnalysisName)
81-
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCsharpName}.dll"));
81+
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCSharpName}.dll"));
8282
else
8383
loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisName}.dll"));
8484

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ private static IEnumerable<string> GetFilesFromPath(string path)
165165
}
166166
}
167167

168-
return new string[] { path };
168+
return [path];
169169
}
170170
}
171171
}

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
<ItemGroup>
3535
<PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="Runtime" />
3636
<PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="Runtime" />
37-
<ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" />
38-
<ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" />
3937
<!-- We carry NuGet as part of the package in case the package is used with an older SDKs or with full framework MSBuild. -->
4038
<PackageReference Include="NuGet.Packaging" PrivateAssets="All" Publish="true" />
4139
<!-- The ApiCompatibility/PackageValidation stuff depends on CodeAnalysis.CSharp at the version that is
@@ -47,6 +45,9 @@
4745
it should never share types with this assembly. Within this task, the RoslynResolver should provide a good
4846
closure of references. -->
4947
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" ExcludeAssets="Runtime" PrivateAssets="all" />
48+
49+
<ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" />
50+
<ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" />
5051
</ItemGroup>
5152

5253
<ItemGroup>

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Microsoft.DotNet.ApiCompat.Tool.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<IsShippingPackage>true</IsShippingPackage>
88
<PackAsTool>true</PackAsTool>
99
<ToolCommandName>apicompat</ToolCommandName>
10+
<RollForward>Major</RollForward>
1011
<PackageDescription>Tool to perform api compatibility checks on assemblies and packages.</PackageDescription>
1112
</PropertyGroup>
1213

src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Logging/SuppressionEngine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class SuppressionEngine(string? noWarn = null, bool baselineAllErrors = f
1717
protected const string DiagnosticIdDocumentationComment = " https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids ";
1818
private readonly HashSet<Suppression> _baselineSuppressions = [];
1919
private readonly HashSet<Suppression> _suppressions = [];
20-
private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new HashSet<string>(noWarn!.Split(';'));
20+
private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new(noWarn!.Split(';'));
2121

2222
/// <inheritdoc/>
2323
public bool BaselineAllErrors { get; } = baselineAllErrors;

src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Package.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ public static Package Create(string? packagePath, IReadOnlyDictionary<NuGetFrame
230230
{
231231
NuGetFramework assemblyReferencesFramework = tfmQueue.Dequeue();
232232

233-
NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat(new NuGetFramework[] { framework }), assemblyReferencesFramework, (key) => key);
233+
NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat([framework]), assemblyReferencesFramework, (key) => key);
234234
if (bestAssemblyReferencesFramework == framework)
235235
{
236236
return AssemblyReferences[assemblyReferencesFramework];

src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Validators/CompatibleTFMValidator.cs

+8-1
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,22 @@ private static Dictionary<NuGetFramework, HashSet<NuGetFramework>> InitializeTfm
100100
{
101101
Dictionary<NuGetFramework, HashSet<NuGetFramework>> packageTfmMapping = [];
102102

103-
// creating a map framework in package => frameworks to test based on default compatibilty mapping.
103+
// creating a map framework in package => frameworks to test based on default compatibility mapping.
104104
foreach (OneWayCompatibilityMappingEntry item in DefaultFrameworkMappings.Instance.CompatibilityMappings)
105105
{
106106
NuGetFramework forwardTfm = item.SupportedFrameworkRange.Max;
107107
NuGetFramework reverseTfm = item.TargetFrameworkRange.Min;
108+
#if NET
109+
if (packageTfmMapping.TryGetValue(forwardTfm, out HashSet<NuGetFramework>? value))
110+
{
111+
value.Add(reverseTfm);
112+
}
113+
#else
108114
if (packageTfmMapping.ContainsKey(forwardTfm))
109115
{
110116
packageTfmMapping[forwardTfm].Add(reverseTfm);
111117
}
118+
#endif
112119
else
113120
{
114121
packageTfmMapping.Add(forwardTfm, [ reverseTfm ]);

src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/CompositeSymbolFilter.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace Microsoft.DotNet.ApiSymbolExtensions.Filtering
99
/// Implements the composite pattern, group the list of <see cref="ISymbol"/> and interact with them
1010
/// the same way as a single instance of a <see cref="ISymbol"/> object.
1111
/// </summary>
12-
public sealed class CompositeSymbolFilter : ISymbolFilter
12+
public sealed class CompositeSymbolFilter(params IEnumerable<ISymbolFilter> filters) : ISymbolFilter
1313
{
1414
/// <summary>
1515
/// List on inner filters.
1616
/// </summary>
17-
public List<ISymbolFilter> Filters { get; } = [];
17+
public List<ISymbolFilter> Filters { get; } = new(filters);
1818

1919
/// <summary>
2020
/// Determines whether the <see cref="ISymbol"/> should be included.

src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/SymbolExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static IEnumerable<ITypeSymbol> GetAllBaseTypes(this ITypeSymbol type)
5656
}
5757

5858
/// <summary>
59-
/// Determines if a symbol was generated by the compiler by checking for the presense of the CompilerGeneratedAttribute.
59+
/// Determines if a symbol was generated by the compiler by checking for the presence of the CompilerGeneratedAttribute.
6060
/// </summary>
6161
/// <param name="symbol">Symbol to check</param>
6262
/// <returns>True if the attribute was found.</returns>

0 commit comments

Comments
 (0)