Skip to content

Commit e65d2e4

Browse files
Merge pull request KirillOsenkov#92 from DustinCampbell/update-msbuildworkspace
Update MSBuildWorkspace to enable multi-targeted projects
2 parents a675330 + c4dc78f commit e65d2e4

File tree

6 files changed

+20
-32
lines changed

6 files changed

+20
-32
lines changed

NuGet.config

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
<add key="automatic" value="True" />
1212
</packageRestore>
1313
<packageSources>
14+
<!-- This package feed is temporary until Microsoft.CodeAnalysis.Workspaces.MSBuild is released on https://nuget.org. -->
15+
<add key="roslyn" value="https://dotnet.myget.org/F/roslyn/api/v3/index.json" />
1416
<add key="nuget.org" value="https://www.nuget.org/api/v2/" />
1517
</packageSources>
1618
</configuration>

src/HtmlGenerator/HtmlGenerator.csproj

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,17 @@
3333
<PackageReference Include="Microsoft.Build.Locator" Version="1.0.7-preview-ge60d679b53" />
3434
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.6.82" ExcludeAssets="runtime" />
3535
<PackageReference Include="Microsoft.Build.Utilities.Core" Version="15.6.82" ExcludeAssets="runtime" />
36-
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.6.1" />
36+
<!-- Temporarily use latest beta Roslyn packages until 2.9.0 is released on https://nuget.org. -->
37+
<PackageReference Include="Microsoft.CodeAnalysis" Version="2.9.0-beta4-62819-06" />
3738
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="2.6.0" />
38-
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="2.6.1" />
39-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.6.1" />
40-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="2.6.1" />
41-
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.6.1" />
42-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.6.1" />
43-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="2.6.1" />
44-
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="2.6.1" />
39+
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="2.9.0-beta4-62819-06" />
40+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.9.0-beta4-62819-06" />
41+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Features" Version="2.9.0-beta4-62819-06" />
42+
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.9.0-beta4-62819-06" />
43+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.9.0-beta4-62819-06" />
44+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="2.9.0-beta4-62819-06" />
45+
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="2.9.0-beta4-62819-06" />
46+
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="2.9.0-beta4-62819-06" />
4547
<PackageReference Include="Microsoft.Language.Xml" Version="1.1.20" />
4648
<PackageReference Include="Microsoft.VisualStudio.Language.Intellisense" Version="15.6.27413" />
4749
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />

src/HtmlGenerator/Pass1-Generation/MetadataAsSource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using Microsoft.CodeAnalysis;
9+
using Microsoft.CodeAnalysis.Host.Mef;
910
using Microsoft.CodeAnalysis.Text;
1011
using Microsoft.SourceBrowser.Common;
1112

@@ -41,7 +42,7 @@ public static Solution LoadMetadataAsSourceSolution(string assemblyFilePath)
4142
{
4243
var assemblyName = Path.GetFileNameWithoutExtension(assemblyFilePath);
4344

44-
var solution = new AdhocWorkspace(WorkspaceHacks.Pack).CurrentSolution;
45+
var solution = new AdhocWorkspace(MefHostServices.DefaultHost).CurrentSolution;
4546
var workspace = solution.Workspace;
4647
var project = solution.AddProject(assemblyName, assemblyName, LanguageNames.CSharp);
4748
var metadataReference = CreateReferenceFromFilePath(assemblyFilePath);

src/HtmlGenerator/Pass1-Generation/SolutionGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private static MSBuildWorkspace CreateWorkspace(ImmutableDictionary<string, stri
128128
propertiesOpt = propertiesOpt.Add("VisualStudioVersion", "15.0");
129129
propertiesOpt = propertiesOpt.Add("AlwaysCompileMarkupFilesInSeparateDomain", "false");
130130

131-
var w = MSBuildWorkspace.Create(properties: propertiesOpt, hostServices: WorkspaceHacks.Pack);
131+
var w = MSBuildWorkspace.Create(properties: propertiesOpt);
132132
w.LoadMetadataForReferencedProjects = true;
133133
return w;
134134
}

src/HtmlGenerator/Utilities/FirstChanceExceptionHandler.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@ public static void HandleFirstChanceException(object sender, FirstChanceExceptio
9191
return;
9292
}
9393

94+
if (ex is FileLoadException && ex.Message.Contains("The assembly '' has already loaded from a different location"))
95+
{
96+
return;
97+
}
98+
9499
if (ex is FileNotFoundException)
95100
{
96101
return;

src/HtmlGenerator/Utilities/WorkspaceHacks.cs

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
11
using System;
2-
using System.ComponentModel.Composition.Hosting;
3-
using System.Linq;
42
using System.Reflection;
53
using Microsoft.CodeAnalysis;
64
using Microsoft.CodeAnalysis.Host;
7-
using Microsoft.CodeAnalysis.Host.Mef;
85

96
namespace Microsoft.SourceBrowser.HtmlGenerator
107
{
118
public static class WorkspaceHacks
129
{
13-
public static HostServices Pack { get; set; }
14-
15-
static WorkspaceHacks()
16-
{
17-
var assemblyNames = new[]
18-
{
19-
"Microsoft.CodeAnalysis.Workspaces",
20-
"Microsoft.CodeAnalysis.Workspaces.Desktop",
21-
"Microsoft.CodeAnalysis.CSharp.Workspaces",
22-
"Microsoft.CodeAnalysis.VisualBasic.Workspaces",
23-
"Microsoft.CodeAnalysis.Features",
24-
"Microsoft.CodeAnalysis.CSharp.Features",
25-
"Microsoft.CodeAnalysis.VisualBasic.Features"
26-
};
27-
var assemblies = assemblyNames
28-
.Select(n => Assembly.Load(n));
29-
Pack = MefHostServices.Create(assemblies);
30-
}
31-
3210
public static dynamic GetSemanticFactsService(Document document)
3311
{
3412
return GetService(document, "Microsoft.CodeAnalysis.LanguageServices.ISemanticFactsService", "Microsoft.CodeAnalysis.Workspaces");

0 commit comments

Comments
 (0)