question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

MSBuild error: MSB4014 "Illegal characters in path"

See original GitHub issue

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\

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
livarcocccommented, Nov 15, 2017

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.

2reactions
milleniumbugcommented, Nov 15, 2017

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

MSBuild error: MSB4014 "Illegal characters in path" #8875
I had the error "Microsoft.DotNet.MSBuildSdkResolver failed to run. Illegal characters in path" when I tried to create a new .Net Core project ...
Read more >
Visual Studio build error "Illegal characters in path"
Go to Tools->Options->Project and Solutions and then change the MSBuild Verbosit to detailed. After that you should see a lot more info in...
Read more >
Illegal Characters In Path Error : r/VisualStudio
Everytime i try and create the project i get an error saying "Illegal Characters in path". Restarted, updated and tried again to no...
Read more >
Illegal characters in path. - Microsoft Q&A
I am trying to create a new project through following procedure but visual studio is throwing exception.
Read more >
#22043 Illegal characters in path when I try to compile
Hi,. A colleague of mine has recently added Postsharp to our solution. We all installed it from http://www.postsharp.net/download and we're using v3.1.48.9.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found