From 3c4aec22ac7f0747f29107a52525ba850696b25d Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 19 Sep 2025 14:38:51 -0600 Subject: [PATCH] Retarget to roslyn for VS 2022 Update 14 This drop support for VS 2019. --- Directory.Packages.Analyzers.props | 15 +++++++-------- Directory.Packages.props | 3 ++- Microsoft.Windows.CsWin32.sln | 5 +++-- azure-pipelines/integration-test.yml | 5 +---- .../AnalyzerReleases.Unshipped.md | 4 +++- src/Microsoft.Windows.CsWin32/BindingRedirects.cs | 2 ++ src/Microsoft.Windows.CsWin32/Docs.cs | 2 ++ src/Microsoft.Windows.CsWin32/MetadataCache.cs | 2 ++ src/Microsoft.Windows.CsWin32/MetadataFile.cs | 2 ++ src/Microsoft.Windows.CsWin32/MetadataIndex.cs | 2 ++ .../Microsoft.Windows.CsWin32.csproj | 4 +--- .../Microsoft.Windows.CsWin32.targets | 1 - src/Microsoft.Windows.CsWin32/SourceGenerator.cs | 7 +++++-- 13 files changed, 32 insertions(+), 22 deletions(-) diff --git a/Directory.Packages.Analyzers.props b/Directory.Packages.Analyzers.props index bd205612..4ca5a804 100644 --- a/Directory.Packages.Analyzers.props +++ b/Directory.Packages.Analyzers.props @@ -1,17 +1,16 @@ - 3.11.0 + 4.14.0 - + - - - - - - + + + + + diff --git a/Directory.Packages.props b/Directory.Packages.props index 71a28dbc..1e38aaac 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -10,12 +10,13 @@ 0.12.8-experimental 0.1.42-alpha - 4.13.0 + 4.14.0 + diff --git a/Microsoft.Windows.CsWin32.sln b/Microsoft.Windows.CsWin32.sln index ea608fee..2165d17d 100644 --- a/Microsoft.Windows.CsWin32.sln +++ b/Microsoft.Windows.CsWin32.sln @@ -1,13 +1,14 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.5.33110.383 +# Visual Studio Version 18 +VisualStudioVersion = 18.0.11018.11 main MinimumVisualStudioVersion = 15.0.26124.0 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1CE9670B-D5FF-46A7-9D00-24E70E6ED48B}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig Directory.Build.props = Directory.Build.props Directory.Build.targets = Directory.Build.targets + Directory.Packages.Analyzers.props = Directory.Packages.Analyzers.props Directory.Packages.props = Directory.Packages.props global.json = global.json nuget.config = nuget.config diff --git a/azure-pipelines/integration-test.yml b/azure-pipelines/integration-test.yml index 2c351945..0da314ae 100644 --- a/azure-pipelines/integration-test.yml +++ b/azure-pipelines/integration-test.yml @@ -1,13 +1,10 @@ jobs: -# Matrix over VS 2019 and VS 2022 +# Matrix over VS 2022 (and eventually VS 2026) - job: integrationtest displayName: 🧪 Integration tests strategy: matrix: - vs2019: - vmImage: windows-2019 - currentSdk: false vs2022: vmImage: windows-2022 currentSdk: true diff --git a/src/Microsoft.Windows.CsWin32/AnalyzerReleases.Unshipped.md b/src/Microsoft.Windows.CsWin32/AnalyzerReleases.Unshipped.md index 8fc794d2..371e06ce 100644 --- a/src/Microsoft.Windows.CsWin32/AnalyzerReleases.Unshipped.md +++ b/src/Microsoft.Windows.CsWin32/AnalyzerReleases.Unshipped.md @@ -12,4 +12,6 @@ PInvoke004 | Functionality | Warning | SourceGenerator PInvoke005 | Functionality | Warning | SourceGenerator PInvoke006 | Configuration | Warning | SourceGenerator PInvoke007 | Functionality | Error | SourceGenerator -PInvoke008 | Configuration | Error | SourceGenerator \ No newline at end of file +PInvoke008 | Configuration | Error | SourceGenerator +PInvoke009 | Configuration | Warning | SourceGenerator +PInvoke010 | Configuration | Error | SourceGenerator \ No newline at end of file diff --git a/src/Microsoft.Windows.CsWin32/BindingRedirects.cs b/src/Microsoft.Windows.CsWin32/BindingRedirects.cs index d5baa58d..679fb675 100644 --- a/src/Microsoft.Windows.CsWin32/BindingRedirects.cs +++ b/src/Microsoft.Windows.CsWin32/BindingRedirects.cs @@ -10,8 +10,10 @@ internal static class BindingRedirects static BindingRedirects() { +#pragma warning disable RS1035 // Do not use APIs banned for analyzers LocalAssemblies = new Lazy>( () => Directory.GetFiles(SourceGeneratorAssemblyDirectory, "*.dll").ToDictionary(Path.GetFileNameWithoutExtension, StringComparer.OrdinalIgnoreCase)); +#pragma warning restore RS1035 // Do not use APIs banned for analyzers } private static bool IsNetFramework => RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase); diff --git a/src/Microsoft.Windows.CsWin32/Docs.cs b/src/Microsoft.Windows.CsWin32/Docs.cs index 0deef2ab..f35ab0d8 100644 --- a/src/Microsoft.Windows.CsWin32/Docs.cs +++ b/src/Microsoft.Windows.CsWin32/Docs.cs @@ -40,7 +40,9 @@ public static Docs Get(string docsPath) } } +#pragma warning disable RS1035 // Do not use APIs banned for analyzers using FileStream docsStream = File.OpenRead(docsPath); +#pragma warning restore RS1035 // Do not use APIs banned for analyzers Dictionary? data = MessagePackSerializer.Deserialize>(docsStream, MsgPackOptions); var docs = new Docs(data); diff --git a/src/Microsoft.Windows.CsWin32/MetadataCache.cs b/src/Microsoft.Windows.CsWin32/MetadataCache.cs index 18073a13..c4d59996 100644 --- a/src/Microsoft.Windows.CsWin32/MetadataCache.cs +++ b/src/Microsoft.Windows.CsWin32/MetadataCache.cs @@ -19,7 +19,9 @@ internal MetadataFile GetMetadataFile(string path) lock (this.metadataFiles) { MetadataFile? metadataFile; +#pragma warning disable RS1035 // Do not use APIs banned for analyzers DateTime lastWriteTimeUtc = File.GetLastWriteTimeUtc(path); +#pragma warning restore RS1035 // Do not use APIs banned for analyzers if (this.metadataFiles.TryGetValue(path, out metadataFile)) { if (metadataFile.LastWriteTimeUtc == lastWriteTimeUtc) diff --git a/src/Microsoft.Windows.CsWin32/MetadataFile.cs b/src/Microsoft.Windows.CsWin32/MetadataFile.cs index 3aee831b..a3275bb7 100644 --- a/src/Microsoft.Windows.CsWin32/MetadataFile.cs +++ b/src/Microsoft.Windows.CsWin32/MetadataFile.cs @@ -19,7 +19,9 @@ internal class MetadataFile : IDisposable internal MetadataFile(string path) { this.Path = path; +#pragma warning disable RS1035 // Do not use APIs banned for analyzers this.LastWriteTimeUtc = File.GetLastWriteTimeUtc(path); +#pragma warning restore RS1035 // Do not use APIs banned for analyzers // When using FileShare.Delete, the OS will allow the file to be deleted, but it does not disrupt // our ability to read the file while our handle is open. diff --git a/src/Microsoft.Windows.CsWin32/MetadataIndex.cs b/src/Microsoft.Windows.CsWin32/MetadataIndex.cs index 1297c928..88857ee7 100644 --- a/src/Microsoft.Windows.CsWin32/MetadataIndex.cs +++ b/src/Microsoft.Windows.CsWin32/MetadataIndex.cs @@ -21,7 +21,9 @@ namespace Microsoft.Windows.CsWin32; [DebuggerDisplay("{" + nameof(DebuggerDisplay) + ",nq}")] internal class MetadataIndex { +#pragma warning disable RS1035 // Do not use APIs banned for analyzers private static readonly int MaxPooledObjectCount = Math.Max(Environment.ProcessorCount, 4); +#pragma warning restore RS1035 // Do not use APIs banned for analyzers private readonly MetadataFile metadataFile; diff --git a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj index c82289ae..66137120 100644 --- a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj +++ b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.csproj @@ -11,6 +11,7 @@ true $(NoWarn);NU5128;NU5127;NU5104 Microsoft.Windows.CsWin32.nuspec + true @@ -26,8 +27,6 @@ - - @@ -50,7 +49,6 @@ - diff --git a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.targets b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.targets index 210f161b..8e7ee14f 100644 --- a/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.targets +++ b/src/Microsoft.Windows.CsWin32/Microsoft.Windows.CsWin32.targets @@ -35,7 +35,6 @@ - diff --git a/src/Microsoft.Windows.CsWin32/SourceGenerator.cs b/src/Microsoft.Windows.CsWin32/SourceGenerator.cs index d6b290c5..0726ce73 100644 --- a/src/Microsoft.Windows.CsWin32/SourceGenerator.cs +++ b/src/Microsoft.Windows.CsWin32/SourceGenerator.cs @@ -1,6 +1,9 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +#pragma warning disable RS1035 // Do not use APIs banned for analyzers (old style source generator) +#pragma warning disable RS1042 // Deprecated interface + using System.Text.Json; using Microsoft.CodeAnalysis.Text; @@ -172,7 +175,7 @@ public void Execute(GeneratorExecutionContext context) return; } - GeneratorOptions options; + GeneratorOptions? options; AdditionalText? nativeMethodsJsonFile = context.AdditionalFiles .FirstOrDefault(af => string.Equals(Path.GetFileName(af.Path), NativeMethodsJsonAdditionalFileName, StringComparison.OrdinalIgnoreCase)); if (nativeMethodsJsonFile is object) @@ -180,7 +183,7 @@ public void Execute(GeneratorExecutionContext context) string optionsJson = nativeMethodsJsonFile.GetText(context.CancellationToken)!.ToString(); try { - options = JsonSerializer.Deserialize(optionsJson, JsonOptions); + options = JsonSerializer.Deserialize(optionsJson, JsonOptions) ?? new(); } catch (JsonException ex) {