MSBuild error: MSB4014 "Illegal characters in path"
See original GitHub issueSteps 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
-
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
toC:\Program Files\dotnet
get around it. https://github.com/dotnet/cli/blob/aacd49f514fecca254f631d4add049c4f8fa0861/src/Microsoft.DotNet.MSBuildSdkResolver/MSBuildSdkResolver.cs#L170 -
It presumes the
PATH
has an invalid character, but the following is the exactPATH
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:
- Created 6 years ago
- Comments:8 (3 by maintainers)
Top GitHub Comments
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.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.