Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuildWorkspace.Create() throws exception

Tags:

roslyn

I have Visual Studio 2013. I also have installed MSBuild Tools 2013. The following code gives me exception

var workspace=MSBuildWorkspace.Create();

Here is the exception

Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

What am I doing wrong ?

like image 488
fahadash Avatar asked Aug 26 '14 11:08

fahadash


2 Answers

You need to install the BuildTools for Visual Studio 2015.

like image 96
Jason Malinowski Avatar answered Sep 27 '22 19:09

Jason Malinowski


You could compile Roslyn against an older version of MSBuild to avoid this problem. I've done this with VS 2012:

Src/Workspaces/Core/Workspaces.csproj
-    <Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+    <Reference Include="Microsoft.Build" />
+    <Reference Include="Microsoft.Build.Framework" />

Src/Workspaces/CSharp/CSharpWorkspace.csproj
-    <Reference Include="Microsoft.Build, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <Reference Include="Microsoft.Build.Framework, Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
-    <Reference Include="Microsoft.Build.Tasks.$(MSBuildAssemblyNameFragment), Version=$(VisualStudioReferenceAssemblyVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
+    <Reference Include="Microsoft.Build" />
+    <Reference Include="Microsoft.Build.Framework" />
+    <Reference Include="Microsoft.Build.Tasks.v4.0" />

Basically I strip the strong name (note that the name of the Tasks assembly is different though) so it picks up the MSBuild from the GAC which comes with the .NET Framework, which for me is the version VS 2012 used.

like image 26
Zarat Avatar answered Sep 27 '22 19:09

Zarat