From e855a47c356a78e9a54bdfd249f3ec6452d3dccf Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 29 Jul 2024 14:28:50 +0200 Subject: [PATCH 1/9] Add analyzer redirecting proposal --- documentation/general/analyzer-redirecting.md | 129 ++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 documentation/general/analyzer-redirecting.md diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md new file mode 100644 index 000000000000..ff40be6df078 --- /dev/null +++ b/documentation/general/analyzer-redirecting.md @@ -0,0 +1,129 @@ +# Redirecting analyzers in SDK to VS + +We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue. +Only major versions will be redirected because different major versions of the same analyzer are not compatible. +So this applies to a situation like: +- Having an analyzer in SDK 9.0.1 referencing Roslyn 4.12. That gets deployed to VS 17.12. +- Having an analyzer in SDK 9.0.7 referencing Roslyn 4.13. +- User loads project with SDK 9.0.7 in VS 17.12. + Previously the analyzers would fail to load as they reference newer Roslyn version (4.13) than what is part of VS (4.12). + Now we will redirect the analyzers to those from SDK 9.0.1 that are deployed as part of VS and reference the matching Roslyn (4.12). + +Loading analyzers with older major version should not be a problem because they must reference an older version of Roslyn. + +Loading analyzers with newer major version in an old VS will result in an error like: + +> error NETSDK1045: The current .NET SDK does not support targeting .NET 10.0. Either target .NET 9.0 or lower, or use a version of the .NET SDK that supports .NET 10.0. Download the .NET SDK from +https://aka.ms/dotnet/download + +## Overview + +- The SDK will contain [a mapping file][file-format] listing the analyzers that want to [dual-insert][dual-insert] into VS. + +- Those analyzers will be deployed with VS in some `{VS-analyzers}` folder + (to be determined, could be something like `C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\DotNetAnalyzers`). + + - This will happen as part of the SDK being inserted into VS. + + - The mapping file [will be used][vs-insertions] to automatically gather all the analyzers. + + - The mapping file will be deployed there as well (at `{VS-analyzers}\mapping.txt`) so Roslyn can read it. + + - If multiple SDKs are inserted into VS, the most recent version wins. + The mapping file should be backwards-compatible (we should not remove patterns from it). + +- Roslyn [will use][roslyn-redirecting] the mapping file to redirect analyzer loads from SDK to VS. + + - If the file is not found at `{VS-analyzers}\mapping.txt`, analyzer loading continues normally from SDK. + + - If a DLL load is requested which matches a mapping, it is redirected via the [IAnalyzerAssemblyResolver][analyzer-assembly-resolver] infrastructure. + +## Mapping file format +[file-format]: #mapping-file-format + +The mapping file v1 is a simple list of directory "patterns". For example: + +``` +packs/Microsoft.NETCore.App.Ref/*/analyzers/dotnet/cs +sdk/*/Sdks/Microsoft.NET.Sdk/analyzers +sdk/*/Sdks/Microsoft.NET.Sdk.Web/analyzers/cs +``` + +Each pattern can contain a single asterisk `*` where a version is expected. + +Lines starting with `#` are ignored (can be used as comments). + +### Inserting analyzers into VS +[vs-insertions]: #inserting-analyzers-into-vs + +The file is used to copy analyzers into VS. +The paths start at the dotnet root. +Only the major version from the `*` part is preserved. +Rest of the path is preserved in the destination. +So for example given the following pattern + +``` +packs/Microsoft.NETCore.App.Ref/*/analyzers +``` + +we copy + +``` +{dotnet-root}\packs\Microsoft.NETCore.App.Ref\8.0.7\analyzers\** +``` + +into + +``` +{VS-analyzers}\packs\Microsoft.NETCore.App.Ref\8\analyzers\** +``` + +If multiple SDKs are inserted into VS, +they should have different major versions, +but if there are two SDKs trying to copy the same pattern with the same major version, +only the more recent SDK should win. + +### Redirecting analyzer loads in Roslyn +[roslyn-redirecting]: #redirecting-analyzer-loads-in-roslyn + +The file is used to redirect DLL loads in Roslyn. +We do not rely on knowledge of `{dotnet-root}`, we simply try to match any path containing the pattern. +For example the following pattern + +``` +packs/Microsoft.NETCore.App.Ref/*/analyzers +``` + +matches + +``` +C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\analyzers\dotnet\cs\Microsoft.Interop.ComInterfaceGenerator.dll +``` + +and redirects load of that DLL into load of + +``` +{VS-analyzers}\packs\Microsoft.NETCore.App.Ref\8\analyzers\dotnet\cs\Microsoft.Interop.ComInterfaceGenerator.dll +``` + +Analyzers that cannot be matched will continue to be loaded from the SDK +(and will fail to load if they reference Roslyn that is newer than the VS). + +### Future extensibility + +If needed, the format can be extended/changed in the future together with the Roslyn redirecting implementation. +Since Roslyn and SDK (which contains the file) are inserted into VS approximately together, +there should be no problems with the file and the implementation that reads it being incompatible. +We could add a version into the file name (like `mapping.v2.txt`) so it is simply ignored +in the short transition period when a different SDK is inserted into VS than Roslyn +(relevant only to internal preview VS builds). + +## Alternatives + +- The file could live in the Roslyn repo, deployed together with Roslyn into VS. + That would make updating the format and the implementation easier if needed. + The SDK would have to extract it from a Roslyn transport package to use it for inserting the analyzer DLLs. + +[torn-sdk]: https://github.com/dotnet/sdk/issues/42087 +[dual-insert]: https://github.com/dotnet/sdk/blob/8a2a7d01c3d3f060d5812424a9de8a00d70b3061/documentation/general/torn-sdk.md#net-sdk-in-box-analyzers-dual-insert +[analyzer-assembly-resolver]: https://github.com/dotnet/roslyn/blob/dabd07189684b5cda34b3072326a12b18301a012/src/Compilers/Core/Portable/DiagnosticAnalyzer/IAnalyzerAssemblyResolver.cs#L12 From 192a7c5e7dc903ce5a11c167a3ce826060ac9241 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 5 Aug 2024 14:32:16 +0200 Subject: [PATCH 2/9] Improve wording --- documentation/general/analyzer-redirecting.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index ff40be6df078..69ec1fb68ee5 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -1,7 +1,7 @@ # Redirecting analyzers in SDK to VS We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue. -Only major versions will be redirected because different major versions of the same analyzer are not compatible. +Only major versions will be redirected because different major versions of the same analyzer cannot be assumed to be compatible. So this applies to a situation like: - Having an analyzer in SDK 9.0.1 referencing Roslyn 4.12. That gets deployed to VS 17.12. - Having an analyzer in SDK 9.0.7 referencing Roslyn 4.13. @@ -11,7 +11,7 @@ So this applies to a situation like: Loading analyzers with older major version should not be a problem because they must reference an older version of Roslyn. -Loading analyzers with newer major version in an old VS will result in an error like: +Targeting an SDK (and hence also loading analyzers) with newer major version in an old VS already results in an error like: > error NETSDK1045: The current .NET SDK does not support targeting .NET 10.0. Either target .NET 9.0 or lower, or use a version of the .NET SDK that supports .NET 10.0. Download the .NET SDK from https://aka.ms/dotnet/download From 5306d3b455b19b6e76df751008a62cfcfd8c215c Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 5 Aug 2024 14:33:37 +0200 Subject: [PATCH 3/9] Change clash to an error --- documentation/general/analyzer-redirecting.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 69ec1fb68ee5..d921ec2f5859 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -81,7 +81,7 @@ into If multiple SDKs are inserted into VS, they should have different major versions, but if there are two SDKs trying to copy the same pattern with the same major version, -only the more recent SDK should win. +an error will be reported (can be changed later to have only the more recent SDK win if needed). ### Redirecting analyzer loads in Roslyn [roslyn-redirecting]: #redirecting-analyzer-loads-in-roslyn From f2f6f9f919d35c2d97acb0f2f23a2e086c54467c Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 12 Aug 2024 15:18:19 +0200 Subject: [PATCH 4/9] Fix formatting --- documentation/general/analyzer-redirecting.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index d921ec2f5859..96190b938413 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -13,8 +13,9 @@ Loading analyzers with older major version should not be a problem because they Targeting an SDK (and hence also loading analyzers) with newer major version in an old VS already results in an error like: -> error NETSDK1045: The current .NET SDK does not support targeting .NET 10.0. Either target .NET 9.0 or lower, or use a version of the .NET SDK that supports .NET 10.0. Download the .NET SDK from -https://aka.ms/dotnet/download +> error NETSDK1045: The current .NET SDK does not support targeting .NET 10.0. +> Either target .NET 9.0 or lower, or use a version of the .NET SDK that supports .NET 10.0. +> Download the .NET SDK from https://aka.ms/dotnet/download ## Overview From ed6b89ccd83943415ab15cd6604f8d2b4c5f641c Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 16 Aug 2024 14:50:00 +0200 Subject: [PATCH 5/9] Simplify by moving the resolver to SDK --- documentation/general/analyzer-redirecting.md | 112 ++++-------------- 1 file changed, 24 insertions(+), 88 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 96190b938413..426761cbdd22 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -1,6 +1,6 @@ # Redirecting analyzers in SDK to VS -We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue. +We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue at design time. Only major versions will be redirected because different major versions of the same analyzer cannot be assumed to be compatible. So this applies to a situation like: - Having an analyzer in SDK 9.0.1 referencing Roslyn 4.12. That gets deployed to VS 17.12. @@ -19,112 +19,48 @@ Targeting an SDK (and hence also loading analyzers) with newer major version in ## Overview -- The SDK will contain [a mapping file][file-format] listing the analyzers that want to [dual-insert][dual-insert] into VS. +- The SDK will contain a VSIX with the analyzer DLLs and an MEF-exported implementation of `IAnalyzerAssemblyResolver`. + Implementations of this interface are imported by Roslyn and can intercept analyzer DLL loading. -- Those analyzers will be deployed with VS in some `{VS-analyzers}` folder - (to be determined, could be something like `C:\Program Files\Microsoft Visual Studio\2022\Preview\Common7\IDE\DotNetAnalyzers`). +- Our `IAnalyzerAssemblyResolver` will redirect any analyzer DLL matching some pattern + to the corresponding DLL installed from the VSIX. + Details of this process are described below. - - This will happen as part of the SDK being inserted into VS. - - - The mapping file [will be used][vs-insertions] to automatically gather all the analyzers. +## Details - - The mapping file will be deployed there as well (at `{VS-analyzers}\mapping.txt`) so Roslyn can read it. - - - If multiple SDKs are inserted into VS, the most recent version wins. - The mapping file should be backwards-compatible (we should not remove patterns from it). - -- Roslyn [will use][roslyn-redirecting] the mapping file to redirect analyzer loads from SDK to VS. - - - If the file is not found at `{VS-analyzers}\mapping.txt`, analyzer loading continues normally from SDK. - - - If a DLL load is requested which matches a mapping, it is redirected via the [IAnalyzerAssemblyResolver][analyzer-assembly-resolver] infrastructure. - -## Mapping file format -[file-format]: #mapping-file-format - -The mapping file v1 is a simple list of directory "patterns". For example: +The VSIX contains some analyzers, for example: ``` -packs/Microsoft.NETCore.App.Ref/*/analyzers/dotnet/cs -sdk/*/Sdks/Microsoft.NET.Sdk/analyzers -sdk/*/Sdks/Microsoft.NET.Sdk.Web/analyzers/cs +AspNetCoreAnalyzers\9.0.0-preview.5.24306.11\analyzers\dotnet\cs\Microsoft.AspNetCore.App.Analyzers.dll +NetCoreAnalyzers\9.0.0-preview.5.24306.7\analyzers\dotnet\cs\System.Text.RegularExpressions.Generator.dll +WindowsDesktopAnalyzers\9.0.0-preview.5.24306.8\analyzers\dotnet\System.Windows.Forms.Analyzers.dll +SDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll +WebSDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Analyzers.dll ``` -Each pattern can contain a single asterisk `*` where a version is expected. - -Lines starting with `#` are ignored (can be used as comments). - -### Inserting analyzers into VS -[vs-insertions]: #inserting-analyzers-into-vs +Given an analyzer assembly load going through our `IAnalyzerAssemblyResolver`, +we will redirect it if the original path of the assembly being loaded +matches the path of a VSIX-deployed analyzer - only segments of these paths starting after the version segment are compared, +plus the major component of the versions must match. -The file is used to copy analyzers into VS. -The paths start at the dotnet root. -Only the major version from the `*` part is preserved. -Rest of the path is preserved in the destination. -So for example given the following pattern +For example, analyzer ``` -packs/Microsoft.NETCore.App.Ref/*/analyzers +C:\Program Files\dotnet\sdk\9.0.100-preview.5.24307.3\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll ``` -we copy +will be redirected to ``` -{dotnet-root}\packs\Microsoft.NETCore.App.Ref\8.0.7\analyzers\** +{VSIX}\SDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll ``` -into - -``` -{VS-analyzers}\packs\Microsoft.NETCore.App.Ref\8\analyzers\** -``` - -If multiple SDKs are inserted into VS, -they should have different major versions, -but if there are two SDKs trying to copy the same pattern with the same major version, -an error will be reported (can be changed later to have only the more recent SDK win if needed). - -### Redirecting analyzer loads in Roslyn -[roslyn-redirecting]: #redirecting-analyzer-loads-in-roslyn - -The file is used to redirect DLL loads in Roslyn. -We do not rely on knowledge of `{dotnet-root}`, we simply try to match any path containing the pattern. -For example the following pattern - -``` -packs/Microsoft.NETCore.App.Ref/*/analyzers -``` - -matches - -``` -C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.7\analyzers\dotnet\cs\Microsoft.Interop.ComInterfaceGenerator.dll -``` - -and redirects load of that DLL into load of - -``` -{VS-analyzers}\packs\Microsoft.NETCore.App.Ref\8\analyzers\dotnet\cs\Microsoft.Interop.ComInterfaceGenerator.dll -``` +because +1. the suffix `Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll` matches, and +2. the version `9.0.100-preview.5.24307.3` has the same major component (`9`) as the version `9.0.100-dev`. Analyzers that cannot be matched will continue to be loaded from the SDK (and will fail to load if they reference Roslyn that is newer than the VS). -### Future extensibility - -If needed, the format can be extended/changed in the future together with the Roslyn redirecting implementation. -Since Roslyn and SDK (which contains the file) are inserted into VS approximately together, -there should be no problems with the file and the implementation that reads it being incompatible. -We could add a version into the file name (like `mapping.v2.txt`) so it is simply ignored -in the short transition period when a different SDK is inserted into VS than Roslyn -(relevant only to internal preview VS builds). - -## Alternatives - -- The file could live in the Roslyn repo, deployed together with Roslyn into VS. - That would make updating the format and the implementation easier if needed. - The SDK would have to extract it from a Roslyn transport package to use it for inserting the analyzer DLLs. - [torn-sdk]: https://github.com/dotnet/sdk/issues/42087 [dual-insert]: https://github.com/dotnet/sdk/blob/8a2a7d01c3d3f060d5812424a9de8a00d70b3061/documentation/general/torn-sdk.md#net-sdk-in-box-analyzers-dual-insert -[analyzer-assembly-resolver]: https://github.com/dotnet/roslyn/blob/dabd07189684b5cda34b3072326a12b18301a012/src/Compilers/Core/Portable/DiagnosticAnalyzer/IAnalyzerAssemblyResolver.cs#L12 From 13535d99abe90b65c44916db41e4ff549c28c360 Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 30 Aug 2024 11:13:08 +0200 Subject: [PATCH 6/9] Match minor version as well --- documentation/general/analyzer-redirecting.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 426761cbdd22..5c75eadc2bdd 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -1,7 +1,7 @@ # Redirecting analyzers in SDK to VS We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue at design time. -Only major versions will be redirected because different major versions of the same analyzer cannot be assumed to be compatible. +Only matching major+minor versions will be redirected because different versions of the same analyzer cannot be assumed to be compatible. So this applies to a situation like: - Having an analyzer in SDK 9.0.1 referencing Roslyn 4.12. That gets deployed to VS 17.12. - Having an analyzer in SDK 9.0.7 referencing Roslyn 4.13. @@ -9,7 +9,7 @@ So this applies to a situation like: Previously the analyzers would fail to load as they reference newer Roslyn version (4.13) than what is part of VS (4.12). Now we will redirect the analyzers to those from SDK 9.0.1 that are deployed as part of VS and reference the matching Roslyn (4.12). -Loading analyzers with older major version should not be a problem because they must reference an older version of Roslyn. +Loading older analyzer versions should not be a problem because they must reference an older version of Roslyn. Targeting an SDK (and hence also loading analyzers) with newer major version in an old VS already results in an error like: @@ -41,7 +41,7 @@ WebSDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.As Given an analyzer assembly load going through our `IAnalyzerAssemblyResolver`, we will redirect it if the original path of the assembly being loaded matches the path of a VSIX-deployed analyzer - only segments of these paths starting after the version segment are compared, -plus the major component of the versions must match. +plus the major and minor component of the versions must match. For example, analyzer @@ -57,10 +57,9 @@ will be redirected to because 1. the suffix `Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll` matches, and -2. the version `9.0.100-preview.5.24307.3` has the same major component (`9`) as the version `9.0.100-dev`. +2. the version `9.0.100-preview.5.24307.3` has the same major and minor component (`9.0`) as the version `9.0.100-dev`. Analyzers that cannot be matched will continue to be loaded from the SDK (and will fail to load if they reference Roslyn that is newer than the VS). [torn-sdk]: https://github.com/dotnet/sdk/issues/42087 -[dual-insert]: https://github.com/dotnet/sdk/blob/8a2a7d01c3d3f060d5812424a9de8a00d70b3061/documentation/general/torn-sdk.md#net-sdk-in-box-analyzers-dual-insert From ccdc04109dadf8838397f211dc3d96d03eed227a Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Fri, 30 Aug 2024 11:16:52 +0200 Subject: [PATCH 7/9] Update roslyn API --- documentation/general/analyzer-redirecting.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 5c75eadc2bdd..3a276587f14b 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -19,13 +19,15 @@ Targeting an SDK (and hence also loading analyzers) with newer major version in ## Overview -- The SDK will contain a VSIX with the analyzer DLLs and an MEF-exported implementation of `IAnalyzerAssemblyResolver`. - Implementations of this interface are imported by Roslyn and can intercept analyzer DLL loading. +- The SDK will contain a VSIX with the analyzer DLLs and an MEF-exported implementation of `IAnalyzerAssemblyRedirector`. + Implementations of this interface are imported by Roslyn and can redirect analyzer DLL loading. -- Our `IAnalyzerAssemblyResolver` will redirect any analyzer DLL matching some pattern - to the corresponding DLL installed from the VSIX. +- The SDK's implementation of `IAnalyzerAssemblyRedirector` will redirect any analyzer DLL matching some pattern + to the corresponding DLL deployed via the VSIX. Details of this process are described below. +- Note that when `IAnalyzerAssemblyRedirector` is involved, Roslyn is free to not use shadow copy loading and instead load the DLLs directly. + ## Details The VSIX contains some analyzers, for example: @@ -38,9 +40,9 @@ SDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis WebSDKAnalyzers\9.0.100-dev\Sdks\Microsoft.NET.Sdk.Web\analyzers\cs\Microsoft.AspNetCore.Analyzers.dll ``` -Given an analyzer assembly load going through our `IAnalyzerAssemblyResolver`, -we will redirect it if the original path of the assembly being loaded -matches the path of a VSIX-deployed analyzer - only segments of these paths starting after the version segment are compared, +Given an analyzer assembly load going through our `IAnalyzerAssemblyRedirector`, +we will redirect it if the original path of the assembly being loaded matches the path of a VSIX-deployed analyzer - +only segments of these paths starting after the version segment are compared, plus the major and minor component of the versions must match. For example, analyzer From ec748bb20539b3203cc41ba3c71290d5dfec91bf Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 13 Jan 2025 11:19:43 +0100 Subject: [PATCH 8/9] Improve wording Co-authored-by: Fred Silberberg --- documentation/general/analyzer-redirecting.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 3a276587f14b..5db6bc6722b6 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -1,12 +1,12 @@ # Redirecting analyzers in SDK to VS -We will redirect analyzers from the SDK to ones deployed in the VS to avoid the [torn SDK][torn-sdk] issue at design time. +We will redirect analyzers from the SDK to ones deployed in VS to avoid the [torn SDK][torn-sdk] issue at design time. Only matching major+minor versions will be redirected because different versions of the same analyzer cannot be assumed to be compatible. So this applies to a situation like: - Having an analyzer in SDK 9.0.1 referencing Roslyn 4.12. That gets deployed to VS 17.12. - Having an analyzer in SDK 9.0.7 referencing Roslyn 4.13. - User loads project with SDK 9.0.7 in VS 17.12. - Previously the analyzers would fail to load as they reference newer Roslyn version (4.13) than what is part of VS (4.12). + Previously the analyzers would fail to load as they reference a newer Roslyn version (4.13) than what is part of VS (4.12). Now we will redirect the analyzers to those from SDK 9.0.1 that are deployed as part of VS and reference the matching Roslyn (4.12). Loading older analyzer versions should not be a problem because they must reference an older version of Roslyn. @@ -45,7 +45,7 @@ we will redirect it if the original path of the assembly being loaded matches th only segments of these paths starting after the version segment are compared, plus the major and minor component of the versions must match. -For example, analyzer +For example, the analyzer ``` C:\Program Files\dotnet\sdk\9.0.100-preview.5.24307.3\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll @@ -62,6 +62,6 @@ because 2. the version `9.0.100-preview.5.24307.3` has the same major and minor component (`9.0`) as the version `9.0.100-dev`. Analyzers that cannot be matched will continue to be loaded from the SDK -(and will fail to load if they reference Roslyn that is newer than the VS). +(and will fail to load if they reference Roslyn that is newer than is in VS). [torn-sdk]: https://github.com/dotnet/sdk/issues/42087 From 684582f3a10f0d5889bb7f1dcd77a5193a6dff7c Mon Sep 17 00:00:00 2001 From: Jan Jones Date: Mon, 13 Jan 2025 11:25:13 +0100 Subject: [PATCH 9/9] Clarify that versions come from the paths --- documentation/general/analyzer-redirecting.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/documentation/general/analyzer-redirecting.md b/documentation/general/analyzer-redirecting.md index 5db6bc6722b6..208c28734787 100644 --- a/documentation/general/analyzer-redirecting.md +++ b/documentation/general/analyzer-redirecting.md @@ -59,7 +59,8 @@ will be redirected to because 1. the suffix `Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll` matches, and -2. the version `9.0.100-preview.5.24307.3` has the same major and minor component (`9.0`) as the version `9.0.100-dev`. +2. the version `9.0.100-preview.5.24307.3` has the same major and minor component (`9.0`) as the version `9.0.100-dev` + (both versions are read from the paths, not DLL metadata). Analyzers that cannot be matched will continue to be loaded from the SDK (and will fail to load if they reference Roslyn that is newer than is in VS).