diff --git a/exclusion.dic b/exclusion.dic index 4d01352f2d6b..3073f4e5eeea 100644 --- a/exclusion.dic +++ b/exclusion.dic @@ -1,11 +1,13 @@ awaiter crossgen +csharp cshtml deserializer msbuild nuget nupkg nuspec +roslyn sdk sdks tfm diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ApiCompatServiceProvider.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ApiCompatServiceProvider.cs index 1a42c556c840..b5d95dd8debd 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ApiCompatServiceProvider.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ApiCompatServiceProvider.cs @@ -32,8 +32,7 @@ public ApiCompatServiceProvider(Func<ISuppressionEngine, ISuppressibleLog> logFa // The attribute data symbol filter is a composite that contains both the accessibility // symbol filter and the doc id symbol filter. - CompositeSymbolFilter attributeDataSymbolFilter = new CompositeSymbolFilter() - .Add(accessibilitySymbolFilter); + CompositeSymbolFilter attributeDataSymbolFilter = new(accessibilitySymbolFilter); if (excludeAttributesFiles is not null) { attributeDataSymbolFilter.Add(new DocIdSymbolFilter(excludeAttributesFiles)); diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs index fe6eac20f94d..5ee9dc82a3f2 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RegexStringTransformer.cs @@ -19,7 +19,7 @@ internal class RegexStringTransformer /// <param name="replacementString">The replacement string that contains the capture group markers (i.e. $1).</param> public RegexStringTransformer(string captureGroupPattern, string replacementString) - : this(new (string, string)[] { (captureGroupPattern, replacementString) }) + : this([(captureGroupPattern, replacementString)]) { } diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs index 7fc2e6036498..baf7cab32af6 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/RoslynResolver.cs @@ -64,9 +64,9 @@ public void Unregister() private Assembly? LoadRoslyn(AssemblyName name, Func<string, Assembly> loadFromPath) { const string codeAnalysisName = "Microsoft.CodeAnalysis"; - const string codeAnalysisCsharpName = "Microsoft.CodeAnalysis.CSharp"; + const string codeAnalysisCSharpName = "Microsoft.CodeAnalysis.CSharp"; - if (name.Name == codeAnalysisName || name.Name == codeAnalysisCsharpName) + if (name.Name == codeAnalysisName || name.Name == codeAnalysisCSharpName) { Assembly asm = loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{name.Name}.dll")); Version? resolvedVersion = asm.GetName().Version; @@ -78,7 +78,7 @@ public void Unregister() // Being extra defensive but we want to avoid that we accidentally load two different versions of either // of the roslyn assemblies from a different location, so let's load them both on the first request. if (name.Name == codeAnalysisName) - loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCsharpName}.dll")); + loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisCSharpName}.dll")); else loadFromPath(Path.Combine(_roslynAssembliesPath!, $"{codeAnalysisName}.dll")); diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs index 30d47f85e86e..5ca7266c730c 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Shared/ValidateAssemblies.cs @@ -165,7 +165,7 @@ private static IEnumerable<string> GetFilesFromPath(string path) } } - return new string[] { path }; + return [path]; } } } diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj index 82e5f75ed2e6..d8ff37c6e19d 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Task/Microsoft.DotNet.ApiCompat.Task.csproj @@ -34,8 +34,6 @@ <ItemGroup> <PackageReference Include="Microsoft.Build.Framework" ExcludeAssets="Runtime" /> <PackageReference Include="Microsoft.Build.Utilities.Core" ExcludeAssets="Runtime" /> - <ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" /> - <ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" /> <!-- We carry NuGet as part of the package in case the package is used with an older SDKs or with full framework MSBuild. --> <PackageReference Include="NuGet.Packaging" PrivateAssets="All" Publish="true" /> <!-- The ApiCompatibility/PackageValidation stuff depends on CodeAnalysis.CSharp at the version that is @@ -47,6 +45,9 @@ it should never share types with this assembly. Within this task, the RoslynResolver should provide a good closure of references. --> <PackageReference Include="Microsoft.CodeAnalysis.CSharp" ExcludeAssets="Runtime" PrivateAssets="all" /> + + <ProjectReference Include="..\Microsoft.DotNet.PackageValidation\Microsoft.DotNet.PackageValidation.csproj" /> + <ProjectReference Include="..\Microsoft.DotNet.ApiCompatibility\Microsoft.DotNet.ApiCompatibility.csproj" /> </ItemGroup> <ItemGroup> diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Microsoft.DotNet.ApiCompat.Tool.csproj b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Microsoft.DotNet.ApiCompat.Tool.csproj index af6c966325a2..90ad0f726269 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Microsoft.DotNet.ApiCompat.Tool.csproj +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompat.Tool/Microsoft.DotNet.ApiCompat.Tool.csproj @@ -7,6 +7,7 @@ <IsShippingPackage>true</IsShippingPackage> <PackAsTool>true</PackAsTool> <ToolCommandName>apicompat</ToolCommandName> + <RollForward>Major</RollForward> <PackageDescription>Tool to perform api compatibility checks on assemblies and packages.</PackageDescription> </PropertyGroup> diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Logging/SuppressionEngine.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Logging/SuppressionEngine.cs index b2951284a6cf..fef506d21bbf 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Logging/SuppressionEngine.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.ApiCompatibility/Logging/SuppressionEngine.cs @@ -17,7 +17,7 @@ public class SuppressionEngine(string? noWarn = null, bool baselineAllErrors = f protected const string DiagnosticIdDocumentationComment = " https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids "; private readonly HashSet<Suppression> _baselineSuppressions = []; private readonly HashSet<Suppression> _suppressions = []; - private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new HashSet<string>(noWarn!.Split(';')); + private readonly HashSet<string> _noWarn = string.IsNullOrEmpty(noWarn) ? [] : new(noWarn!.Split(';')); /// <inheritdoc/> public bool BaselineAllErrors { get; } = baselineAllErrors; diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Package.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Package.cs index 4546f3678647..1f9934048a73 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Package.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Package.cs @@ -230,7 +230,7 @@ public static Package Create(string? packagePath, IReadOnlyDictionary<NuGetFrame { NuGetFramework assemblyReferencesFramework = tfmQueue.Dequeue(); - NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat(new NuGetFramework[] { framework }), assemblyReferencesFramework, (key) => key); + NuGetFramework? bestAssemblyReferencesFramework = NuGetFrameworkUtility.GetNearest(tfmQueue.Concat([framework]), assemblyReferencesFramework, (key) => key); if (bestAssemblyReferencesFramework == framework) { return AssemblyReferences[assemblyReferencesFramework]; diff --git a/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Validators/CompatibleTFMValidator.cs b/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Validators/CompatibleTFMValidator.cs index bae28f39fb79..3082dea0317f 100644 --- a/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Validators/CompatibleTFMValidator.cs +++ b/src/Compatibility/ApiCompat/Microsoft.DotNet.PackageValidation/Validators/CompatibleTFMValidator.cs @@ -100,15 +100,22 @@ private static Dictionary<NuGetFramework, HashSet<NuGetFramework>> InitializeTfm { Dictionary<NuGetFramework, HashSet<NuGetFramework>> packageTfmMapping = []; - // creating a map framework in package => frameworks to test based on default compatibilty mapping. + // creating a map framework in package => frameworks to test based on default compatibility mapping. foreach (OneWayCompatibilityMappingEntry item in DefaultFrameworkMappings.Instance.CompatibilityMappings) { NuGetFramework forwardTfm = item.SupportedFrameworkRange.Max; NuGetFramework reverseTfm = item.TargetFrameworkRange.Min; +#if NET + if (packageTfmMapping.TryGetValue(forwardTfm, out HashSet<NuGetFramework>? value)) + { + value.Add(reverseTfm); + } +#else if (packageTfmMapping.ContainsKey(forwardTfm)) { packageTfmMapping[forwardTfm].Add(reverseTfm); } +#endif else { packageTfmMapping.Add(forwardTfm, [ reverseTfm ]); diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/CompositeSymbolFilter.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/CompositeSymbolFilter.cs index d72684e8a552..d1b8cf29f899 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/CompositeSymbolFilter.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/Filtering/CompositeSymbolFilter.cs @@ -9,12 +9,12 @@ namespace Microsoft.DotNet.ApiSymbolExtensions.Filtering /// Implements the composite pattern, group the list of <see cref="ISymbol"/> and interact with them /// the same way as a single instance of a <see cref="ISymbol"/> object. /// </summary> - public sealed class CompositeSymbolFilter : ISymbolFilter + public sealed class CompositeSymbolFilter(params IEnumerable<ISymbolFilter> filters) : ISymbolFilter { /// <summary> /// List on inner filters. /// </summary> - public List<ISymbolFilter> Filters { get; } = []; + public List<ISymbolFilter> Filters { get; } = new(filters); /// <summary> /// Determines whether the <see cref="ISymbol"/> should be included. diff --git a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/SymbolExtensions.cs b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/SymbolExtensions.cs index 025cf0d8d853..8e7e44b929bc 100644 --- a/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/SymbolExtensions.cs +++ b/src/Compatibility/Microsoft.DotNet.ApiSymbolExtensions/SymbolExtensions.cs @@ -56,7 +56,7 @@ public static IEnumerable<ITypeSymbol> GetAllBaseTypes(this ITypeSymbol type) } /// <summary> - /// Determines if a symbol was generated by the compiler by checking for the presense of the CompilerGeneratedAttribute. + /// Determines if a symbol was generated by the compiler by checking for the presence of the CompilerGeneratedAttribute. /// </summary> /// <param name="symbol">Symbol to check</param> /// <returns>True if the attribute was found.</returns>