Sdk: build.cmd fails on windows when space is in directory path

Created on 10 Jul 2019  路  3Comments  路  Source: dotnet/sdk

Steps to reproduce

clone the cli repo
run build.cmd from commandline

Expected behavior

build starts

Actual behavior

build fails with error:

The term C:\Users\<FirstPartofUserName> is not recognized as the name of a cmdlet, 
function...
verify that the path is correct and try again.

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
Version: 3.0.100-preview6-011681
Commit: 2f5626d019

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100-preview6-011681\

Host (useful for support):
Version: 3.0.0-preview6-27629-07
Commit: a3967b6096

.NET Core SDKs installed:
2.1.602 [C:\Program Files\dotnet\sdk]
2.1.700 [C:\Program Files\dotnet\sdk]
2.2.202 [C:\Program Files\dotnet\sdk]
2.2.203 [C:\Program Files\dotnet\sdk]
2.2.300 [C:\Program Files\dotnet\sdk]
3.0.100-preview6-011681 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.9 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.11 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.3 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.4 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.5 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.9 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.11 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.3 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.4 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0-preview6-19230-05 [C:\Program Files\dotnetshared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.9 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.11 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.3 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.4 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0-preview6-27629-07 [C:\Program Files\dotnetshared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0-preview6-27629-07 [C:\Program Files\dotnetshared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

Investigation

$RepoRoot = "$PSScriptRoot"
Invoke-Expression "$RepoRoot\eng\common\build.ps1 -restore -build $ConfigurationParam 
$ArchitectureParam $ExtraParameters"

Above line uses $RepoRoot which is set from $PSScriptRoot containing space from username

good first issue help wanted

All 3 comments

@peterhuene this seems like it would be a good first issue. Mainly figuring out proper quotation in the run-build.ps1 script.

What do you think?

Hi, I'd like to take a stab at this! Currently working on something, should have a PR up by the end of the day. 馃槃

So, the issue has become more complicated than I thought. I was able to have the build command work in run-build.ps1 like so:

Invoke-Expression "& ""$RepoRoot\eng\common\build.ps1"" -restore -build $ConfigurationParam $ArchitectureParam $ExtraParameters"

Where the file path is wrapped in quotes and the leading ampersand instructs Invoke-Expression to treat the string as a command.

But somewhere along the build process the spaces in the file path must be an issue elsewhere. My log after cloning a new repo, editing the run-build file, and running build.cmd:

Build succeeded.

D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\build\MSBuildExtensions.targets(53,5): error MSB3030: Could not copy the file "D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\.nuget\packages\microsoft.net.build.extensions\3.0.100-preview8.19360.3\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\tools\net472\zh-Hans\Microsoft.NET.Build.Extensions.Tasks.resources.dll" because it was not found. [D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\src\redist\redist.csproj]
D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\build\MSBuildExtensions.targets(53,5): error MSB3030: Could not copy the file "D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\.nuget\packages\microsoft.net.build.extensions\3.0.100-preview8.19360.3\msbuildExtensions\Microsoft\Microsoft.NET.Build.Extensions\tools\net472\zh-Hans\Microsoft.NET.Build.Extensions.Tasks.resources.dll" because it was not found. [D:\Users\corey\Documents\OpenSource\Folder With Spaces\cli\src\redist\redist.csproj]
    0 Warning(s)
    2 Error(s)

Time Elapsed 00:01:52.10

I did confirm that Microsoft.NET.Build.Extensions.Tasks.resources.dll existed in my file system. I checked the file the error message pointed to, cli\src\redist\redist.csproj and this line seemed to be relevant:
C# <Import Project="$(RepoRoot)/build/MSBuildExtensions.targets" />
I don't have a lot of knowledge on editing .csproj files nor this repo, so I'd appreciate some additional thoughts on what the issue may be.

Was this page helpful?
0 / 5 - 0 ratings