Sdk: MSBuild error: MSB4014 "Illegal characters in path"

Created on 14 Nov 2017  路  8Comments  路  Source: dotnet/sdk

Steps to reproduce

Unknown other than run MSBuild on any .NET Framework solution that includes a dotnet standard class library with dotnet 2.0 installed, perhaps.

Expected behavior

MSBuild succeeds

Actual behavior

MSBuild fails with error:

    error MSB4014: The build stopped unexpectedly because of an internal failure.\r
    error MSB4014: System.ArgumentException: Illegal characters in path.\r
    error MSB4014:    at System.IO.Path.CheckInvalidPathChars(String path, Boolean checkAdditional)\r
    error MSB4014:    at System.IO.Path.Combine(String path1, String path2)\r
    error MSB4014:    at Microsoft.DotNet.MSBuildSdkResolver.EnvironmentProvider.<>c__DisplayClass7_0.<GetCommandPath>b__0(String p)\r
    error MSB4014:    at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()\r
    error MSB4014:    at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)\r
    error MSB4014:    at Microsoft.DotNet.MSBuildSdkResolver.EnvironmentProvider.GetCommandPath(String commandName)\r
    error MSB4014:    at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.GetDotnetExeDirectory()\r
    error MSB4014:    at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.ResolveNetcoreSdkDirectory(SdkResolverContext context)\r
    error MSB4014:    at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)\r
    error MSB4014:    at Microsoft.Build.BackEnd.SdkResolution.GetSdkPath(SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath)

Environment data

dotnet --info output:

.NET Command Line Tools (2.0.2)

Product Information:
 Version:            2.0.2
 Commit SHA-1 hash:  a04b4bf512

Runtime Environment:
 OS Name:     Windows
 OS Version:  6.1.7601
 OS Platform: Windows
 RID:         win7-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.0.2\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

Additional Info

  1. I noticed that the error originates from this function in MSBuild that looks for the path to dotnet, so I set the DOTNET_MSBUILD_SDK_RESOLVER_CLI_DIR to C:\Program Files\dotnet get around it.
    https://github.com/dotnet/cli/blob/aacd49f514fecca254f631d4add049c4f8fa0861/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs#L170

  2. It presumes the PATH has an invalid character, but the following is the exact PATH environment variable with no invalid characters:
    C:\Program Files (x86)\EMC IRM\Common\;C:\ProgramData\Oracle\Java\javapath;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\DMIX;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files (x86)\Kaspersky Lab\Kaspersky Anti-Virus 6.0 for Windows Servers MP4\;C:\Program Files\Windows Imaging\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Dell\SysMgt\oma\bin;C:\Program Files (x86)\Dell\SysMgt\shared\bin;C:\Program Files (x86)\Dell\SysMgt\idrac;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.8\;C:\Users\tfsservice\AppData\Roaming\npm;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd ;C:\Program Files\nodejs\;%USERPROFILE%\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\dotnet\

Most helpful comment

Btw, I noticed a empty space at the end of one of your paths: C:\Program Files (x86)\Git\cmd ;. Not sure this is causing it, but maybe that's the culprit.

All 8 comments

Slightly related: I've spent 10h today debugging a similar issue, and it turned out there was a spurious carriage return character in %PATH% https://imgur.com/jDdyR6F.png I am not happy about it, so I really hope this comment will help here too.

I just commented on the other issue. Here it is again:

I am not sure what else we can do in this case. In the past, this has always been the case: some invisible character in the PATH or path causing issues. However, unfortunately the APIs available do not tell us what character is the culprit.

I would suggest taking a look in your path and maybe pasting that on a editor that would show these characters. Vim has worked for me in the past for this sort of thing.

Btw, I noticed a empty space at the end of one of your paths: C:\Program Files (x86)\Git\cmd ;. Not sure this is causing it, but maybe that's the culprit.

YOUR A GENIUS @livarcocc - thank you kindly!!

That was it, thank you @livarcocc !

Hi,

I had a similar error and found this searching for a solution. I had the error "Microsoft.DotNet.MSBuildSdkResolver failed to run. Illegal characters in path" when I tried to create a new .Net Core project in Visual Studio 2019 (new installation). It created the project, but didn't add it to the solution. When I tried adding it manually (add existing project) I got this error.

I had no illegal characters or trailing spaces in my path. But I had an old entry to a folder that no longer existed in it. After removing it everything was fine. So if someone comes here for such an error it may also be an entry pointing to a no longer existing directory, e.g. after uninstalling an application.

Was this page helpful?
0 / 5 - 0 ratings