Skip to content

Commit

Permalink
Merge pull request #57500 from dotnet/merges/release/dev17.1-to-relea…
Browse files Browse the repository at this point in the history
…se/dev17.1-vs-deps

Merge release/dev17.1 to release/dev17.1-vs-deps
  • Loading branch information
dotnet-bot authored Nov 1, 2021
2 parents b82f234 + 282dec5 commit e4419d6
Show file tree
Hide file tree
Showing 9 changed files with 152 additions and 23 deletions.
10 changes: 9 additions & 1 deletion Roslyn.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31319.15
MinimumVisualStudioVersion = 10.0.40219.1
Expand Down Expand Up @@ -497,6 +498,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Remo
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests", "src\Compilers\CSharp\Test\Emit2\Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests.csproj", "{2B7DC612-1B37-41F7-BE31-4D600930EAC9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.CodeAnalysis.Remote.ServiceHub.UnitTests", "src\Workspaces\Remote\ServiceHubTest\Microsoft.CodeAnalysis.Remote.ServiceHub.UnitTests.csproj", "{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3}"
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Analyzers\VisualBasic\CodeFixes\VisualBasicCodeFixes.projitems*{0141285d-8f6c-42c7-baf3-3c0ccd61c716}*SharedItemsImports = 5
Expand Down Expand Up @@ -1296,6 +1299,10 @@ Global
{2B7DC612-1B37-41F7-BE31-4D600930EAC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2B7DC612-1B37-41F7-BE31-4D600930EAC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2B7DC612-1B37-41F7-BE31-4D600930EAC9}.Release|Any CPU.Build.0 = Release|Any CPU
{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -1523,6 +1530,7 @@ Global
{3829F774-33F2-41E9-B568-AE555004FC62} = {8977A560-45C2-4EC2-A849-97335B382C74}
{8FCD1B85-BE63-4A2F-8E19-37244F19BE0F} = {55A62CFA-1155-46F1-ADF3-BEEE51B58AB5}
{2B7DC612-1B37-41F7-BE31-4D600930EAC9} = {32A48625-F0AD-419D-828B-A50BDABA38EA}
{8D830CBB-CA6E-47D8-9FB8-9230AAD272F3} = {55A62CFA-1155-46F1-ADF3-BEEE51B58AB5}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {604E6B91-7BC0-4126-AE07-D4D2FEFC3D29}
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@
<MicrosoftNetSdkVersion>2.0.0-alpha-20170405-2</MicrosoftNetSdkVersion>
<MicrosoftNuGetBuildTasksVersion>0.1.0</MicrosoftNuGetBuildTasksVersion>
<MicrosoftPortableTargetsVersion>0.1.2-dev</MicrosoftPortableTargetsVersion>
<MicrosoftServiceHubClientVersion>3.0.2065</MicrosoftServiceHubClientVersion>
<MicrosoftServiceHubFrameworkVersion>3.0.2065</MicrosoftServiceHubFrameworkVersion>
<MicrosoftServiceHubClientVersion>3.1.4</MicrosoftServiceHubClientVersion>
<MicrosoftServiceHubFrameworkVersion>3.1.4</MicrosoftServiceHubFrameworkVersion>
<MicrosoftVisualBasicVersion>10.1.0</MicrosoftVisualBasicVersion>
<MicrosoftVisualStudioCacheVersion>17.0.13-alpha</MicrosoftVisualStudioCacheVersion>
<MicrosoftVisualStudioCallHierarchyPackageDefinitionsVersion>15.8.27812-alpha</MicrosoftVisualStudioCallHierarchyPackageDefinitionsVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ internal class DefaultAnalyzerAssemblyLoader : AnalyzerAssemblyLoader
"System.Xml.XDocument",
"System.Xml.XPath.XDocument");

internal virtual ImmutableHashSet<string> AssemblySimpleNamesToBeLoadedInCompilerContext => CompilerAssemblySimpleNames;

// This is the context where compiler (and some of its dependencies) are being loaded into, which might be different from AssemblyLoadContext.Default.
private static readonly AssemblyLoadContext s_compilerLoadContext = AssemblyLoadContext.GetLoadContext(typeof(DefaultAnalyzerAssemblyLoader).GetTypeInfo().Assembly)!;

Expand Down Expand Up @@ -119,7 +121,7 @@ public DirectoryLoadContext(string directory, DefaultAnalyzerAssemblyLoader load
protected override Assembly? Load(AssemblyName assemblyName)
{
var simpleName = assemblyName.Name!;
if (CompilerAssemblySimpleNames.Contains(simpleName))
if (_loader.AssemblySimpleNamesToBeLoadedInCompilerContext.Contains(simpleName))
{
// Delegate to the compiler's load context to load the compiler or anything
// referenced by the compiler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Razor.RemoteClient" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.VisualBasic" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.LanguageServices.Xaml" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Remote.ServiceHub.UnitTests" />
<InternalsVisibleTo Include="Roslyn.Hosting.Diagnostics" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.Setup" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.DiagnosticsWindow" />
Expand Down
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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,5 @@ public RemoteAnalyzerAssemblyLoaderService()

public IAnalyzerAssemblyLoader GetLoader(in AnalyzerAssemblyLoaderOptions options)
=> options.ShadowCopy ? _shadowCopyLoader : _loader;

// 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.
private 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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities2" />
<InternalsVisibleTo Include="Roslyn.VisualStudio.Next.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.EditorFeatures.UnitTests" />
<InternalsVisibleTo Include="Microsoft.CodeAnalysis.Remote.ServiceHub.UnitTests" />
<InternalsVisibleTo Include="Microsoft.VisualStudio.Completion.Tests" Key="$(IntelliCodeCSharpKey)" WorkItem="https://github.com/dotnet/roslyn/issues/35081" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.IntelliCode.CSharp" Partner="Pythia" Key="$(IntelliCodeCSharpKey)" />
<RestrictedInternalsVisibleTo Include="Microsoft.VisualStudio.IntelliCode.CSharp.Extraction" Partner="Pythia" Key="$(IntelliCodeCSharpKey)" />
Expand Down
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>
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);
}
}
}

0 comments on commit e4419d6

Please sign in to comment.