18

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 ?

fahadash
  • 3,133
  • 1
  • 30
  • 59

2 Answers2

19

You need to install the BuildTools for Visual Studio 2015.

Jason Malinowski
  • 18,148
  • 1
  • 38
  • 55
  • 1
    Where can I get full CTP ? – fahadash Aug 27 '14 at 01:51
  • 3
    If you download the iso file, you can actually find the build tools inside under packages\BuildTools_MsBuild_x86 – xinqiu Aug 28 '14 at 21:07
  • 7
    The build tools is now available as a separate download: http://go.microsoft.com/?linkid=9863815 – Kirk Woll Dec 02 '14 at 15:22
  • The Build Tools "14" are now called "Microsoft Build Tools 2015", current link is here: http://www.microsoft.com/en-us/download/details.aspx?id=48159 – Dr Rob Lang Aug 20 '15 at 10:37
  • Have similar issue when running the same code in VS2015 and error regarding Microsoft.Build 15.1 version. Is there something like BuildTools for Visual Studio 2017? Haven't found anything... – Michal Hosala Apr 13 '17 at 12:31
  • 1
    Seems like installing [Microsoft.Build](https://www.nuget.org/packages/Microsoft.Build/) nuget resolved my problem, but I am wondering why it isnt listed among dependencies of roslyn nuget packages that I built and used locally. – Michal Hosala Apr 13 '17 at 14:09
  • ... or not entirely, I am able to load console VB.NET apps correctly, but if I try to load web app then it shows zero documents for that particular project, am I still missing some package? Ideas? – Michal Hosala Apr 18 '17 at 09:43
  • @MichalHosala: probably best to start a new question for this, at least for your web app question. "web app" can mean lots of project types, and your environment matters too. – Jason Malinowski Apr 20 '17 at 04:24
3

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.

Zarat
  • 2,584
  • 22
  • 40