-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57500 from dotnet/merges/release/dev17.1-to-relea…
…se/dev17.1-vs-deps Merge release/dev17.1 to release/dev17.1-vs-deps
- Loading branch information
Showing
9 changed files
with
152 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/Workspaces/Remote/ServiceHub/Host/RemoteAnalyzerAssemblyLoader.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.Collections.Immutable; | ||
using System.IO; | ||
|
||
namespace Microsoft.CodeAnalysis.Remote.Diagnostics | ||
{ | ||
/// <summary> | ||
/// For analyzers shipped in Roslyn, different set of assemblies might be used when running | ||
/// in-proc and OOP e.g. in-proc (VS) running on desktop clr and OOP running on ServiceHub .Net6 | ||
/// host. We need to make sure to use the ones from the same location as the remote. | ||
/// </summary> | ||
internal sealed class RemoteAnalyzerAssemblyLoader : DefaultAnalyzerAssemblyLoader | ||
{ | ||
private readonly string _baseDirectory; | ||
|
||
public RemoteAnalyzerAssemblyLoader(string baseDirectory) | ||
{ | ||
_baseDirectory = baseDirectory; | ||
} | ||
|
||
protected override string GetPathToLoad(string fullPath) | ||
{ | ||
var fixedPath = Path.GetFullPath(Path.Combine(_baseDirectory, Path.GetFileName(fullPath))); | ||
return File.Exists(fixedPath) ? fixedPath : fullPath; | ||
} | ||
|
||
#if NETCOREAPP | ||
|
||
// The following are special assemblies since they contain IDE analyzers and/or their dependencies, | ||
// but in the meantime, they also contain the host of compiler in remote process. Therefore on coreclr, | ||
// we must ensure they are only loaded once and in the same ALC compiler asemblies are loaded into. | ||
// Otherwise these analyzers will fail to interoperate with the host due to mismatch in assembly identity. | ||
private static readonly ImmutableHashSet<string> s_ideAssemblySimpleNames = | ||
CompilerAssemblySimpleNames.Union(new[] | ||
{ | ||
"Microsoft.CodeAnalysis.Features", | ||
"Microsoft.CodeAnalysis.CSharp.Features", | ||
"Microsoft.CodeAnalysis.VisualBasic.Features", | ||
"Microsoft.CodeAnalysis.Workspaces", | ||
"Microsoft.CodeAnalysis.CSharp.Workspaces", | ||
"Microsoft.CodeAnalysis.VisualBasic.Workspaces", | ||
}); | ||
|
||
internal override ImmutableHashSet<string> AssemblySimpleNamesToBeLoadedInCompilerContext => s_ideAssemblySimpleNames; | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...orkspaces/Remote/ServiceHubTest/Microsoft.CodeAnalysis.Remote.ServiceHub.UnitTests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE file in the project root for more information. --> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Library</OutputType> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<RootNamespace>Microsoft.CodeAnalysis.UnitTests</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup Label="Project References"> | ||
<ProjectReference Include="..\ServiceHub\Microsoft.CodeAnalysis.Remote.ServiceHub.csproj" /> | ||
<ProjectReference Include="..\..\..\Compilers\Test\Core\Microsoft.CodeAnalysis.Test.Utilities.csproj" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> | ||
</ItemGroup> | ||
</Project> |
70 changes: 70 additions & 0 deletions
70
src/Workspaces/Remote/ServiceHubTest/RemoteAnalyzerAssemblyLoaderTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System.IO; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
using Microsoft.CodeAnalysis.Diagnostics; | ||
using Microsoft.CodeAnalysis.Remote.Diagnostics; | ||
using Xunit; | ||
|
||
namespace Microsoft.CodeAnalysis.Remote.UnitTests | ||
{ | ||
public class RemoteAnalyzerAssemblyLoaderTests | ||
{ | ||
[Fact] | ||
public void NonIdeAnalyzerAssemblyShouldBeLoadedInSeparateALC() | ||
{ | ||
var remoteAssemblyInCurrentAlc = typeof(RemoteAnalyzerAssemblyLoader).GetTypeInfo().Assembly; | ||
var remoteAssemblyLocation = remoteAssemblyInCurrentAlc.Location; | ||
|
||
var loader = new RemoteAnalyzerAssemblyLoader(Path.GetDirectoryName(remoteAssemblyLocation)!); | ||
|
||
// Try to load MS.CA.Remote.ServiceHub.dll as an analyzer assembly via RemoteAnalyzerAssemblyLoader | ||
// since it's not one of the special assemblies listed in RemoteAnalyzerAssemblyLoader, | ||
// RemoteAnalyzerAssemblyLoader should loaded in a spearate DirectoryLoadContext. | ||
loader.AddDependencyLocation(remoteAssemblyLocation); | ||
var remoteAssemblyLoadedViaRemoteLoader = loader.LoadFromPath(remoteAssemblyLocation); | ||
|
||
var alc1 = AssemblyLoadContext.GetLoadContext(remoteAssemblyInCurrentAlc); | ||
var alc2 = AssemblyLoadContext.GetLoadContext(remoteAssemblyLoadedViaRemoteLoader); | ||
Assert.NotEqual(alc1, alc2); | ||
} | ||
|
||
[Fact] | ||
public void IdeAnalyzerAssemblyShouldBeLoadedInLoaderALC() | ||
{ | ||
var featuresAssemblyInCurrentAlc = typeof(Microsoft.CodeAnalysis.Completion.CompletionProvider).GetTypeInfo().Assembly; | ||
var featuresAssemblyLocation = featuresAssemblyInCurrentAlc.Location; | ||
|
||
// Try to load MS.CA.Features.dll as an analyzer assembly via RemoteAnalyzerAssemblyLoader | ||
// since it's listed as one of the special assemblies in RemoteAnalyzerAssemblyLoader, | ||
// RemoteAnalyzerAssemblyLoader should loaded in its own ALC. | ||
var loader = new RemoteAnalyzerAssemblyLoader(Path.GetDirectoryName(featuresAssemblyLocation)!); | ||
loader.AddDependencyLocation(featuresAssemblyLocation); | ||
|
||
var featuresAssemblyLoadedViaRemoteLoader = loader.LoadFromPath(featuresAssemblyLocation); | ||
|
||
var alc1 = AssemblyLoadContext.GetLoadContext(featuresAssemblyInCurrentAlc); | ||
var alc2 = AssemblyLoadContext.GetLoadContext(featuresAssemblyLoadedViaRemoteLoader); | ||
Assert.Equal(alc1, alc2); | ||
} | ||
|
||
[Fact] | ||
public void CompilerAssemblyShouldBeLoadedInLoaderALC() | ||
{ | ||
var compilerAssemblyInCurrentAlc = typeof(SyntaxNode).GetTypeInfo().Assembly; | ||
var compilerAssemblyLocation = compilerAssemblyInCurrentAlc.Location; | ||
|
||
var loader = new RemoteAnalyzerAssemblyLoader(Path.GetDirectoryName(compilerAssemblyLocation)!); | ||
loader.AddDependencyLocation(compilerAssemblyLocation); | ||
|
||
var compilerAssemblyLoadedViaRemoteLoader = loader.LoadFromPath(compilerAssemblyLocation); | ||
|
||
var alc1 = AssemblyLoadContext.GetLoadContext(compilerAssemblyInCurrentAlc); | ||
var alc2 = AssemblyLoadContext.GetLoadContext(compilerAssemblyLoadedViaRemoteLoader); | ||
Assert.Equal(alc1, alc2); | ||
} | ||
} | ||
} |