Skip to content

Commit 3e772db

Browse files
authored
Analyzer redirector (#11972)
* Bump roslyn version * Add razor redirector implementation * Add pinning test
1 parent 5d06658 commit 3e772db

File tree

5 files changed

+160
-65
lines changed

5 files changed

+160
-65
lines changed

eng/Version.Details.xml

Lines changed: 43 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,90 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<Dependencies>
33
<Source Uri="https://github.com/dotnet/dotnet" Mapping="razor" Sha="f5705c8f4c5079bba77bae8698ba1583bde0388c" BarId="269610" />
44
<ProductDependencies>
5-
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25316.1">
5+
<Dependency Name="Microsoft.Net.Compilers.Toolset" Version="5.0.0-1.25321.1">
66
<Uri>https://github.com/dotnet/roslyn</Uri>
7-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
7+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
88
</Dependency>
9-
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="5.0.0-1.25316.1">
9+
<Dependency Name="Microsoft.CommonLanguageServerProtocol.Framework" Version="5.0.0-1.25321.1">
1010
<Uri>https://github.com/dotnet/roslyn</Uri>
11-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
11+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
1212
</Dependency>
13-
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="5.0.0-1.25316.1">
13+
<Dependency Name="Microsoft.CodeAnalysis.Common" Version="5.0.0-1.25321.1">
1414
<Uri>https://github.com/dotnet/roslyn</Uri>
15-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
15+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
1616
</Dependency>
17-
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-1.25316.1">
17+
<Dependency Name="Microsoft.CodeAnalysis.CSharp" Version="5.0.0-1.25321.1">
1818
<Uri>https://github.com/dotnet/roslyn</Uri>
19-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
19+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
2020
</Dependency>
21-
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="5.0.0-1.25316.1">
21+
<Dependency Name="Microsoft.CodeAnalysis.CSharp.EditorFeatures" Version="5.0.0-1.25321.1">
2222
<Uri>https://github.com/dotnet/roslyn</Uri>
23-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
23+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
2424
</Dependency>
25-
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="5.0.0-1.25316.1">
25+
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Features" Version="5.0.0-1.25321.1">
2626
<Uri>https://github.com/dotnet/roslyn</Uri>
27-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
27+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
2828
</Dependency>
29-
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0-1.25316.1">
29+
<Dependency Name="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="5.0.0-1.25321.1">
3030
<Uri>https://github.com/dotnet/roslyn</Uri>
31-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
31+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
3232
</Dependency>
33-
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="5.0.0-1.25316.1">
33+
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures" Version="5.0.0-1.25321.1">
3434
<Uri>https://github.com/dotnet/roslyn</Uri>
35-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
35+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
3636
</Dependency>
37-
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="5.0.0-1.25316.1">
37+
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Common" Version="5.0.0-1.25321.1">
3838
<Uri>https://github.com/dotnet/roslyn</Uri>
39-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
39+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
4040
</Dependency>
41-
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="5.0.0-1.25316.1">
41+
<Dependency Name="Microsoft.CodeAnalysis.EditorFeatures.Text" Version="5.0.0-1.25321.1">
4242
<Uri>https://github.com/dotnet/roslyn</Uri>
43-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
43+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
4444
</Dependency>
45-
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="5.0.0-1.25316.1">
45+
<Dependency Name="Microsoft.CodeAnalysis.Remote.ServiceHub" Version="5.0.0-1.25321.1">
4646
<Uri>https://github.com/dotnet/roslyn</Uri>
47-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
47+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
4848
</Dependency>
49-
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="5.0.0-1.25316.1">
49+
<Dependency Name="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="5.0.0-1.25321.1">
5050
<Uri>https://github.com/dotnet/roslyn</Uri>
51-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
51+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
5252
</Dependency>
53-
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="5.0.0-1.25316.1">
53+
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.Common" Version="5.0.0-1.25321.1">
5454
<Uri>https://github.com/dotnet/roslyn</Uri>
55-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
55+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
5656
</Dependency>
57-
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.0.0-1.25316.1">
57+
<Dependency Name="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="5.0.0-1.25321.1">
5858
<Uri>https://github.com/dotnet/roslyn</Uri>
59-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
59+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
6060
</Dependency>
61-
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="5.0.0-1.25316.1">
61+
<Dependency Name="Microsoft.VisualStudio.LanguageServices" Version="5.0.0-1.25321.1">
6262
<Uri>https://github.com/dotnet/roslyn</Uri>
63-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
63+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
6464
</Dependency>
65-
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="5.0.0-1.25316.1">
65+
<Dependency Name="Microsoft.CodeAnalysis.Test.Utilities" Version="5.0.0-1.25321.1">
6666
<Uri>https://github.com/dotnet/roslyn</Uri>
67-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
67+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
6868
</Dependency>
69-
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor.Features" Version="5.0.0-1.25316.1">
69+
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor.Features" Version="5.0.0-1.25321.1">
7070
<Uri>https://github.com/dotnet/roslyn</Uri>
71-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
71+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
7272
</Dependency>
73-
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor.EditorFeatures" Version="5.0.0-1.25316.1">
73+
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.Razor.EditorFeatures" Version="5.0.0-1.25321.1">
7474
<Uri>https://github.com/dotnet/roslyn</Uri>
75-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
75+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
7676
</Dependency>
77-
<Dependency Name="Microsoft.CodeAnalysis.LanguageServer.Protocol" Version="5.0.0-1.25316.1">
77+
<Dependency Name="Microsoft.CodeAnalysis.LanguageServer.Protocol" Version="5.0.0-1.25321.1">
7878
<Uri>https://github.com/dotnet/roslyn</Uri>
79-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
79+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
8080
</Dependency>
81-
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="5.0.0-1.25316.1">
81+
<Dependency Name="Microsoft.CodeAnalysis.ExternalAccess.FSharp" Version="5.0.0-1.25321.1">
8282
<Uri>https://github.com/dotnet/roslyn</Uri>
83-
<Sha>e15bc0a7eb664d20e7237daef7ab6b76da6c16cb</Sha>
83+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
8484
</Dependency>
85-
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="3.12.0-beta1.25230.6">
85+
<Dependency Name="Microsoft.CodeAnalysis.Analyzers" Version="5.0.0-1.25321.1">
8686
<Uri>https://github.com/dotnet/roslyn</Uri>
87-
<Sha>ded867328249b5a9b9e6e29e3f07abc19111f5d1</Sha>
87+
<Sha>ad14335550de1134f0b5a59b6cd040001d0d8c8d</Sha>
8888
</Dependency>
8989
</ProductDependencies>
9090
<ToolsetDependencies>

eng/Versions.props

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<!-- Opt-in arcade features -->
33
<PropertyGroup>
44
<UsingToolVSSDK>true</UsingToolVSSDK>
@@ -47,27 +47,27 @@
4747
4848
-->
4949
<PropertyGroup Label="Automated">
50-
<MicrosoftCodeAnalysisAnalyzersPackageVersion>3.12.0-beta1.25230.6</MicrosoftCodeAnalysisAnalyzersPackageVersion>
51-
<MicrosoftNetCompilersToolsetPackageVersion>5.0.0-1.25316.1</MicrosoftNetCompilersToolsetPackageVersion>
52-
<MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>
53-
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>5.0.0-1.25316.1</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
54-
<MicrosoftCodeAnalysisExternalAccessRazorEditorFeaturesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisExternalAccessRazorEditorFeaturesPackageVersion>
55-
<MicrosoftCodeAnalysisExternalAccessRazorFeaturesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisExternalAccessRazorFeaturesPackageVersion>
56-
<MicrosoftCodeAnalysisCommonPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisCommonPackageVersion>
57-
<MicrosoftCodeAnalysisCSharpPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisCSharpPackageVersion>
58-
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
59-
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
60-
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
61-
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
62-
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
63-
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
64-
<MicrosoftCodeAnalysisLanguageServerProtocolPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisLanguageServerProtocolPackageVersion>
65-
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
66-
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
67-
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
68-
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
69-
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>5.0.0-1.25316.1</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
70-
<MicrosoftVisualStudioLanguageServicesPackageVersion>5.0.0-1.25316.1</MicrosoftVisualStudioLanguageServicesPackageVersion>
50+
<MicrosoftCodeAnalysisAnalyzersPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisAnalyzersPackageVersion>
51+
<MicrosoftNetCompilersToolsetPackageVersion>5.0.0-1.25321.1</MicrosoftNetCompilersToolsetPackageVersion>
52+
<MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisExternalAccessFSharpPackageVersion>
53+
<MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>5.0.0-1.25321.1</MicrosoftCommonLanguageServerProtocolFrameworkPackageVersion>
54+
<MicrosoftCodeAnalysisExternalAccessRazorEditorFeaturesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisExternalAccessRazorEditorFeaturesPackageVersion>
55+
<MicrosoftCodeAnalysisExternalAccessRazorFeaturesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisExternalAccessRazorFeaturesPackageVersion>
56+
<MicrosoftCodeAnalysisCommonPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisCommonPackageVersion>
57+
<MicrosoftCodeAnalysisCSharpPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisCSharpPackageVersion>
58+
<MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisCSharpEditorFeaturesPackageVersion>
59+
<MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisCSharpFeaturesPackageVersion>
60+
<MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisCSharpWorkspacesPackageVersion>
61+
<MicrosoftCodeAnalysisEditorFeaturesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisEditorFeaturesPackageVersion>
62+
<MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisEditorFeaturesCommonPackageVersion>
63+
<MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisEditorFeaturesTextPackageVersion>
64+
<MicrosoftCodeAnalysisLanguageServerProtocolPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisLanguageServerProtocolPackageVersion>
65+
<MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisRemoteServiceHubPackageVersion>
66+
<MicrosoftCodeAnalysisTestUtilitiesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisTestUtilitiesPackageVersion>
67+
<MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisVisualBasicWorkspacesPackageVersion>
68+
<MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisWorkspacesCommonPackageVersion>
69+
<MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>5.0.0-1.25321.1</MicrosoftCodeAnalysisWorkspacesMSBuildPackageVersion>
70+
<MicrosoftVisualStudioLanguageServicesPackageVersion>5.0.0-1.25321.1</MicrosoftVisualStudioLanguageServicesPackageVersion>
7171
<!--
7272
Exception - Microsoft.Extensions.ObjectPool and System.Collections.Immutable packages are not updated by automation,
7373
but are present in Version.Details.xml for source-build PVP flow. See the comment in Version.Details.xml for more information.

src/Razor/src/Microsoft.CodeAnalysis.Razor.CohostingShared/Microsoft.CodeAnalysis.Razor.CohostingShared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<Compile Include="$(MSBuildThisFileDirectory)Formatting\CohostRangeFormattingEndpoint.cs" />
3434
<Compile Include="$(MSBuildThisFileDirectory)OnAutoInsert\CohostOnAutoInsertEndpoint.cs" />
3535
<Compile Include="$(MSBuildThisFileDirectory)OnAutoInsert\CohostOnAutoInsertTriggerCharacterProviders.cs" />
36+
<Compile Include="$(MSBuildThisFileDirectory)RazorAnalyzerAssemblyRedirector.cs" />
3637
<Compile Include="$(MSBuildThisFileDirectory)Rename\CohostRenameEndpoint.cs" />
3738
<Compile Include="$(MSBuildThisFileDirectory)SignatureHelp\CohostSignatureHelpEndpoint.cs" />
3839
<Compile Include="$(MSBuildThisFileDirectory)FoldingRange\CohostFoldingRangeEndpoint.cs" />
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Collections.Frozen;
6+
using System.Collections.Immutable;
7+
using System.Composition;
8+
using System.IO;
9+
using System.Reflection;
10+
using IRazorAnalyzerAssemblyRedirector = Microsoft.CodeAnalysis.ExternalAccess.Razor.RazorAnalyzerAssemblyRedirector.IRazorAnalyzerAssemblyRedirector;
11+
12+
namespace Microsoft.VisualStudio.Razor;
13+
14+
#pragma warning disable RS0030 // Do not use banned APIs
15+
[Shared]
16+
[Export(typeof(IRazorAnalyzerAssemblyRedirector))]
17+
[method: ImportingConstructor]
18+
#pragma warning restore RS0030 // Do not use banned APIs
19+
internal sealed class RazorAnalyzerAssemblyRedirector() : IRazorAnalyzerAssemblyRedirector
20+
{
21+
private static readonly ImmutableArray<Type> s_compilerAssemblyTypes = [
22+
23+
typeof(CodeAnalysis.Razor.CompilerFeatures), // Microsoft.CodeAnalysis.Razor.Compiler.dll
24+
typeof(AspNetCore.Razor.ArgHelper), // Microsoft.AspNetCore.Razor.Utilities.Shared.dll
25+
26+
// The following dependencies will be provided by the Compiler ALC so its not strictly required to redirect them, but we do so for completeness.
27+
typeof(Microsoft.Extensions.ObjectPool.ObjectPool), // Microsoft.Extensions.ObjectPool.dll
28+
typeof(ImmutableArray) // System.Collections.Immutable.dll
29+
];
30+
31+
private static readonly FrozenDictionary<string, string> s_compilerAssemblyMap = s_compilerAssemblyTypes.ToFrozenDictionary(t => t.Assembly.GetName().Name!, t => GetAssemblyLocation(t.Assembly));
32+
33+
public string? RedirectPath(string fullPath)
34+
{
35+
var name = Path.GetFileNameWithoutExtension(fullPath);
36+
return s_compilerAssemblyMap.TryGetValue(name, out var path) ? path : null;
37+
}
38+
39+
private static string GetAssemblyLocation(Assembly assembly)
40+
{
41+
var location = assembly.Location;
42+
var name = Path.GetFileName(location);
43+
var directory = Path.GetDirectoryName(location) ?? "";
44+
45+
// In VS on windows, depending on who wins the race to load these assemblies, the base directory will either be the tooling root (if Roslyn wins)
46+
// or the ServiceHubCore subfolder (razor). In the root directory these are netstandard2.0 targeted, in ServiceHubCore they are .NET targeted.
47+
// We need to always pick the same set of assemblies regardless of who causes us to load. Because this code only runs in a .NET based host,
48+
// we want to prefer the .NET targeted ServiceHubCore versions if they exist.
49+
var serviceHubCoreVersion = Path.Combine(directory, "ServiceHubCore", name);
50+
if (File.Exists(serviceHubCoreVersion))
51+
{
52+
return serviceHubCoreVersion;
53+
}
54+
55+
return location;
56+
}
57+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using Microsoft.VisualStudio.Razor;
6+
using Xunit;
7+
8+
namespace Microsoft.VisualStudio.LanguageServices.Razor.Test;
9+
10+
public class AssemblyRedirectorTests
11+
{
12+
[Fact]
13+
public void AssemblyRedirector_RedirectedAssemblies()
14+
{
15+
// This test ensures that the expected set of razor assemblies are redirected in Roslyn.
16+
// This will fail if you change assembly names or move types around. You will need to
17+
// update this test to ensure that the new set of assemblies are redirected as needed.
18+
var expectedAssemblies = new[]
19+
{
20+
"Microsoft.CodeAnalysis.Razor.Compiler.dll",
21+
"Microsoft.AspNetCore.Razor.Utilities.Shared.dll",
22+
"Microsoft.Extensions.ObjectPool.dll",
23+
"System.Collections.Immutable.dll"
24+
};
25+
26+
var redirector = new RazorAnalyzerAssemblyRedirector();
27+
foreach (var assembly in expectedAssemblies)
28+
{
29+
var actualPath = redirector.RedirectPath(assembly);
30+
Assert.NotNull(actualPath);
31+
Assert.EndsWith(assembly, actualPath, StringComparison.OrdinalIgnoreCase);
32+
}
33+
34+
// Something not in the list doesn't get redirected
35+
Assert.Null(redirector.RedirectPath("goo.dll"));
36+
}
37+
}

0 commit comments

Comments
 (0)