Why I hate Roslyn even more


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">
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.


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.

Post a Comment