MSB4011

Issue with MSB4011 warnings

If MSB4011 warnings appears on every project you have, and you get “tons” of them, then you have this issue. In order to get rid of these annoying warnings you must fix up your installation as described below..

How the error appears

First of all, you see warnings like shown below in the Output window for build:

2>C:\Program Files (x86)\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Microsoft.NuGet.ImportAfter.targets(16,3): warning MSB4011: "D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.targets" cannot be imported again. It was already imported at "D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\Microsoft.NuGet.ImportAfter.targets (16,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\Users\Terje\Source\Repos\ABC\Engine.csproj]
2>C:\Program Files (x86)\MSBuild\15.0\Imports\Microsoft.Common.props\ImportBefore\Microsoft.NuGet.ImportBefore.props(16,3): warning MSB4011: "D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\NuGet\15.0\Microsoft.NuGet.props" cannot be imported again. It was already imported at "D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Imports\Microsoft.Common.props\ImportBefore\Microsoft.NuGet.ImportBefore.props (16,3)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\Users\Terje\Source\Repos\ABC\Tool.csproj]

Further, you see multiple of the same warnings in the Visual Studio Error window:

VisualStudioWarnings

The reason for the warnings

Installations of Visual  Studio and MSBuild have added extra nuget target files in locations where they should not be. Due to these extra files, these warnings appears.

The two location to check are:

(Note that my install locations are given, so change them with respect to your installation,  with respect to drive and VS  SKU (Enterprise/Professional/Community) )

For Visual Studio:

For MSBuild:

At some time you installed some pre-release version of Visual Studio. This version created these folders with their content.  Subsequent releases did not clean them out as they should have.  So now you need to do this manually, which fortunately is very easy.

Solution

Keep the ones under Visual Studio, hence delete the ones under MSBuild.  You can also see the ones under MSBuild have an earlier date, so they come from some pre-release version installed earlier

Consequently the important ones to disable are the two folders marked (1). You can  either delete or just rename them, if you’re the cautious type. The bin folder marked (2) also contains older stuff, so you can delete that one too.