10/04/2017

Why I hate Roslyn even more

Home



In my previous post I wrote about my problem with "empty" projects and Roslyn. The symptom was that in some cases according to Roslyn my C# projects didn't contain any files. For quite a long time, I haven't been able to find a solution. Especially because I couldn't reproduce problem on my local machine. Fortunately, today I noticed exactly the same problem on another computer.

Knowing that Roslyn likes to fail silently I started investigation my telling Visual Studio to break when any exception is thrown. Then I run my program and I stared analyzing strange exceptions like COMException, DllNotFoundException or InvalidProjectFileException. Especially, the last one was interesting. It was thrown in Microsoft.Build.dll and the included message was:

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

Following my intuition, I opened the csproj file for my project. It looked in this way:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
</Project>
So my project was created with tools in the version 12.0. Well, it was neither equal to 15.0 nor on the list of available versions but I decided to try my luck. I updated ToolsVersion="12.0" to ToolsVersion="14.0" and run my program one more time.

And you know what? It worked this time! Gosh, I hate fighting with such silly problems. Again, it confirms that Roslyn fails in slowly, silently and not in the clear way! Do not do that to your clients.

I suspect that the problem might be somehow related to the version of MSBuild that is installed on the machine but for now I'm not sure. Do you know something?

*The picture at the beginning of the post comes from own resources and shows Tatry Mountains.

6 comments:

Helton Moraes said...

Very useful post. I found it a good idea to just "turn on ALL exceptions" to deal with silent-failing libraries in general. I solved my problem by changing the toolset in every ".csproj" file to "4.0".

e1v said...

Thank you, your solution worked after I got the "tools version "15.0" is unrecognized" after the latest visual studio update (15.3) (but I do not understand why :)

Unknown said...
This comment has been removed by the author.
Anonymous said...

I have exactly the same problem after upgrading to 15.3 of Visual Studio 2017.

Dima Sorkin said...

If anyone interested in this yet, the problem is that in VSv15+ MsBuild isn't so tightly connected with the IDE, and the correct tool set is discovered by hints around your PC. This includes environment variables. So you may open project with Roslyn that is being developed in VSv15, as long as you have VSv14 installed. And you will need to provide the additional information for the workspace if you don't:
https://github.com/dotnet/roslyn/issues/21644

Rennie Petersen said...

Following the link in the previous comment, the information here https://gist.github.com/DustinCampbell/32cd69d04ea1c08a16ae5c4cd21dd3a3 reveals that there is now an MSBuildWorkspace.Diagnostics collection that can be queried, and which hopefully avoids (or at least reduces) the problem of MSBuild failing silently. There is also a new Microsoft.Build.Locator NuGet package simplifies things for machines with Visual Studio installed.

Post a Comment