2

I've been burning a few hours on this problem and have done a lot of searching to figure out what's going on.

I have an app which loads Project files from .csproj files, so it references Microsoft.Build dlls. On one of my computers everything works fine. On another, the app crashes when I try to load a .csproj file.

The exception I'm getting is of type Microsoft.Build.Exceptions.InvalidProjectFileException with the following message:

The tools version "15.0" is unrecognized. Available tools versions are "14.0", "2.0", "3.5", "4.0".

At first I wasn't sure what was causing the problem so I thought I'd include the .dlls as part of my project. That is, I copied the .dlls to a folder in my project, and referenced those .dlls. But when I run my project the GAC loading preference is biting me, as the output window shows me that a different .dll is being loaded:

Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\Microsoft.Build.Framework\v4.0_15.1.0.0__b03f5f7f11d50a3a\Microsoft.Build.Framework.dll'.

So I looked at the .dll being loaded on each machine by navigating to that location and viewing the properties on the .dll.

On the machine that does work the .dll has the version 15.1.1015. On the machine that does not work the .dll has the version 15.3.409

I haven't found people talking about this exact problem, but I have seen people talk about having issues after having upgraded to Visual Studio 15.3. Sure enough, the computer that does not work has Visual Studio 15.3.5, while the computer that does work has Visual Studio 15.2.

To try to address this, I removed 15.3 from the GAC using steps outlined here:

Could not load type 'Microsoft.Build.Framework.SdkReference' on project open in VS 2017 U1 (15.3)

Alas, even after this change, I am still encountering the same problem, so changing the GAC to point to an earlier Microsoft.Build.Framework.dll still didn't fix it (maybe because other files in the Microsoft.Build family are being GAC'ed in at 15.3?). I did verify that the version loaded by the GAC is now 15.1.

Is there another workaround or fix I could apply to solve this problem?

Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49
  • Did you try to build using the msbuild commandline. You should pass this step, otherwise the problem may be in msbuild. try `msbuild ` – M.Hassan Sep 23 '17 at 22:02
  • I don't know why msbuild .exe would be the problem because I'm not yet executing the build - just trying to load the .csproj. That said, the project does load in Visual Studio correctly and also builds fine in msbuild in the Developer Command Prompt for VS 2017 – Victor Chelaru Sep 24 '17 at 13:27

1 Answers1

1

I hope someone else can answer with something better than this, but I was able to work around the problem by forcing version 14.0 when loading the project. My project doesn't require Visual Studio 2017 (MSBuild 15.X). Since it can load in Visual Studio 2015 as well I simply specify the version number in the Project constructor:

coreVisualStudioProject = new Project(fileName, null, "14.0", new ProjectCollection());
Victor Chelaru
  • 4,491
  • 3
  • 35
  • 49
  • thanks for sharing your solution here, you could mark it as the answer, so it could help other community members who get the same issues. – Leo Liu Sep 27 '17 at 01:26