Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions documentation/general/analyzer-redirecting.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ 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 `IAnalyzerAssemblyRedirector`.
- The SDK will deploy analyzer DLLs and Roslyn will deploy an implementation of `IAnalyzerAssemblyRedirector`
(could be deployed by SDK but we are saving on analyzer loads and Roslyn already has a VSIX with a DLL).
Implementations of this interface are imported by Roslyn and can redirect analyzer DLL loading.

- The SDK's implementation of `IAnalyzerAssemblyRedirector` will redirect any analyzer DLL matching some pattern
to the corresponding DLL deployed via the VSIX.
- That implementation of `IAnalyzerAssemblyRedirector` will redirect any analyzer DLL matching some pattern
to the corresponding DLL deployed with VS.
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.
Expand All @@ -33,7 +34,7 @@ Targeting an SDK (and hence also loading analyzers) with newer major version in

## Details

The VSIX contains some analyzers, for example:
The VS deployment contains some analyzers, for example:

```
AspNetCoreAnalyzers\analyzers\dotnet\cs\Microsoft.AspNetCore.App.Analyzers.dll
Expand Down Expand Up @@ -69,7 +70,7 @@ C:\Program Files\dotnet\sdk\9.0.100-preview.5.24307.3\Sdks\Microsoft.NET.Sdk\ana
will be redirected to

```
{VSIX}\SDKAnalyzers\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll
{InstallDir}\SDKAnalyzers\Sdks\Microsoft.NET.Sdk\analyzers\Microsoft.CodeAnalysis.NetAnalyzers.dll
```

where `metadata.json` has `"SDKAnalyzers": "9.0.100-dev"`, because
Expand All @@ -83,6 +84,5 @@ Analyzers that cannot be matched will continue to be loaded from the SDK
### Implementation

Analyzer DLLs are contained in transport package `VS.Redist.Common.Net.Core.SDK.RuntimeAnalyzers`.
The redirecting logic lives in "system" VS extension `Microsoft.Net.Sdk.AnalyzerRedirecting`.

[torn-sdk]: https://github.com/dotnet/sdk/issues/42087
2 changes: 0 additions & 2 deletions sdk.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
</Folder>
<Folder Name="/src/">
<Project Path="src/Microsoft.DotNet.TemplateLocator/Microsoft.DotNet.TemplateLocator.csproj" />
<Project Path="src/Microsoft.Net.Sdk.AnalyzerRedirecting/Microsoft.Net.Sdk.AnalyzerRedirecting.csproj" />
<Project Path="src/Microsoft.Net.Sdk.Compilers.Toolset/Microsoft.Net.Sdk.Compilers.Toolset.csproj" />
<Project Path="src/Microsoft.Win32.Msi/Microsoft.Win32.Msi.csproj" />
<Project Path="src/System.CommandLine.StaticCompletions/System.CommandLine.StaticCompletions.csproj" />
Expand Down Expand Up @@ -337,7 +336,6 @@
<Project Path="test/Microsoft.NET.Publish.Tests/Microsoft.NET.Publish.Tests.csproj" />
<Project Path="test/Microsoft.NET.Rebuild.Tests/Microsoft.NET.Rebuild.Tests.csproj" />
<Project Path="test/Microsoft.NET.Restore.Tests/Microsoft.NET.Restore.Tests.csproj" />
<Project Path="test/Microsoft.Net.Sdk.AnalyzerRedirecting.Tests/Microsoft.Net.Sdk.AnalyzerRedirecting.Tests.csproj" />
<Project Path="test/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.AoT.Tests.csproj" />
<Project Path="test/Microsoft.NET.Sdk.BlazorWebAssembly.Tests/Microsoft.NET.Sdk.BlazorWebAssembly.Tests.csproj" />
<Project Path="test/Microsoft.NET.Sdk.Publish.Tasks.Tests/Microsoft.NET.Sdk.Publish.Tasks.Tests.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\Microsoft.Net.Sdk.AnalyzerRedirecting\Microsoft.Net.Sdk.AnalyzerRedirecting.csproj" />
<ProjectReference Include="..\redist\redist.csproj" />
</ItemGroup>

Expand All @@ -30,49 +29,29 @@
<RedistRuntimeAnalyzersContent Include="$(RedistInstallerLayoutPath)packs\Microsoft.AspNetCore.App.Ref\*\analyzers\**\*.*" DeploymentSubpath="AspNetCoreAnalyzers" />
<RedistRuntimeAnalyzersContent Include="$(RedistInstallerLayoutPath)sdk\*\Sdks\Microsoft.NET.Sdk\analyzers\**\*.*" DeploymentSubpath="SDKAnalyzers" />
<RedistRuntimeAnalyzersContent Include="$(RedistInstallerLayoutPath)sdk\*\Sdks\Microsoft.NET.Sdk.Web\analyzers\**\*.*" DeploymentSubpath="WebSDKAnalyzers" />
<RedirectingRuntimeAnalyzersContent Include="$(ArtifactsBinDir)Microsoft.Net.Sdk.AnalyzerRedirecting\$(Configuration)\net472\**\*.*" DeploymentSubpath="AnalyzerRedirecting" />
</ItemGroup>

<Error Condition="'@(RedistRuntimeAnalyzersContent)' == ''" Text="The 'RedistRuntimeAnalyzersContent' items are empty. This shouldn't happen!" />
<Error Condition="'@(RedirectingRuntimeAnalyzersContent)' == ''" Text="The 'RedirectingRuntimeAnalyzersContent' items are empty. This shouldn't happen!" />

<!-- The custom task cannot access %(RecursiveDir) without this. -->
<ItemGroup>
<RedistRuntimeAnalyzersContent Update="@(RedistRuntimeAnalyzersContent)">
<CustomRecursiveDir>%(RecursiveDir)</CustomRecursiveDir>
</RedistRuntimeAnalyzersContent>
<RedirectingRuntimeAnalyzersContent Update="@(RedirectingRuntimeAnalyzersContent)">
<CustomRecursiveDir>%(RecursiveDir)</CustomRecursiveDir>
</RedirectingRuntimeAnalyzersContent>
</ItemGroup>

<ProcessRuntimeAnalyzerVersions Inputs="@(RedistRuntimeAnalyzersContent)" MetadataFilePath="$(SdkRuntimeAnalyzersMetadataFile)">
<Output TaskParameter="Outputs" ItemName="ProcessedRedistRuntimeAnalyzersContent" />
</ProcessRuntimeAnalyzerVersions>

<ItemGroup>
<RuntimeAnalyzersContent Include="@(ProcessedRedistRuntimeAnalyzersContent);@(RedirectingRuntimeAnalyzersContent)" />
<RuntimeAnalyzersContent Include="@(ProcessedRedistRuntimeAnalyzersContent)" />
</ItemGroup>

<Copy SourceFiles="@(RuntimeAnalyzersContent)"
DestinationFiles="@(RuntimeAnalyzersContent->'$(OutputPath)\%(DeploymentSubpath)\%(CustomRecursiveDir)%(Filename)%(Extension)')"
UseHardlinksIfPossible="true" />

<!-- Replace Experimental=true with SystemComponent=true in the VS extension manifest. -->
<PropertyGroup>
<_VsixNamespace>
<Namespace Prefix="pm" Uri="http://schemas.microsoft.com/developer/vsx-schema/2011" />
</_VsixNamespace>
</PropertyGroup>
<XmlPoke XmlInputPath="$(OutputPath)\AnalyzerRedirecting\extension.vsixmanifest"
Namespaces="$(_VsixNamespace)"
Query="/pm:PackageManifest/pm:Installation/@Experimental"
Value="false" />
<XmlPoke XmlInputPath="$(OutputPath)\AnalyzerRedirecting\extension.vsixmanifest"
Namespaces="$(_VsixNamespace)"
Query="/pm:PackageManifest/pm:Installation/@SystemComponent"
Value="true" />

<GenerateRuntimeAnalyzersSWR RuntimeAnalyzersLayoutDirectory="$(OutputPath)"
OutputFile="$(SdkRuntimeAnalyzersSwrFile)" />

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/Tasks/sdk-tasks/GenerateRuntimeAnalyzersSWR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@ public override bool Execute()
"metadata.json",
]);

AddFolder(sb,
"AnalyzerRedirecting",
@$"{installDir}\AnalyzerRedirecting",
filesToInclude:
[
"Microsoft.Net.Sdk.AnalyzerRedirecting.dll",
"Microsoft.Net.Sdk.AnalyzerRedirecting.pkgdef",
"extension.vsixmanifest",
]);

AddFolder(sb,
"AspNetCoreAnalyzers",
@$"{installDir}\AspNetCoreAnalyzers");
Expand Down
Loading
Loading