dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

dotnet build cannot support path with folder name has '%20' #2178

Open rainersigwald opened 7 years ago

rainersigwald commented 7 years ago

From @micli on June 5, 2017 6:24

Steps to reproduce

Recently I am trying to write a book to introduce .NET Core Debugging skill to audience. I created a project on Visual Studio Online with name "Dotnet core Debugging Book". It git clone to local, folder is "Dotnet%20core%20Debugging%20Book". In this folder, if I create a simple console .Net Core 2.0 app with below command, it will not build correctly. dotnet new console -o DumpMe dotnet restore dotnet build

I got below error message when did dotnet build action: `/usr/local/share/dotnet/sdk/2.0.0-preview1-005977/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(155,5): error : Assets file '/Users/micl/Documents/DotnetDebugging/Dotnet core Debugging Book/code/Chapter04/DumpMe/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(7,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(8,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(9,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(6,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(7,61): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(8,59): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(9,59): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(10,68): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(11,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(12,53): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(13,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(4,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] /usr/local/share/dotnet/sdk/2.0.0-preview1-005977/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(94,5): error : Assets file '/Users/micl/Documents/DotnetDebugging/Dotnet core Debugging Book/code/Chapter04/DumpMe/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj]

Build FAILED.

/usr/local/share/dotnet/sdk/2.0.0-preview1-005977/Sdks/Microsoft.NET.Sdk/build/Microsoft.PackageDependencyResolution.targets(155,5): error : Assets file '/Users/micl/Documents/DotnetDebugging/Dotnet core Debugging Book/code/Chapter04/DumpMe/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(6,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(7,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(8,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(9,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(6,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(7,61): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(8,59): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(9,59): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(10,68): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(11,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(12,53): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(13,55): error CS0518: Predefined type 'System.String' is not defined or imported [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(3,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] obj/Debug/netcoreapp2.0/DumpMe.AssemblyInfo.cs(4,7): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] /usr/local/share/dotnet/sdk/2.0.0-preview1-005977/Sdks/Microsoft.NET.Sdk/build/Microsoft.NET.Sdk.targets(94,5): error : Assets file '/Users/micl/Documents/DotnetDebugging/Dotnet core Debugging Book/code/Chapter04/DumpMe/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/micl/Documents/DotnetDebugging/Dotnet%20core%20Debugging%20Book/code/Chapter04/DumpMe/DumpMe.csproj] 0 Warning(s) 20 Error(s) ` But if I do above under a folder without '%20', It actions as usual.

Expected behavior

To confirm the folder name with '%20' supports or not. It seems that general actions like copy, paste doing well under the folder which name has '%20'.

Actual behavior

Environment data

dotnet --info output: .NET Command Line Tools (2.0.0-preview1-005977)

Product Information: Version: 2.0.0-preview1-005977 Commit SHA-1 hash: 414cab8a0b

Runtime Environment: OS Name: Mac OS X OS Version: 10.12 OS Platform: Darwin RID: osx.10.12-x64 Base Path: /usr/local/share/dotnet/sdk/2.0.0-preview1-005977/

Microsoft .NET Core Shared Framework Host

Version : 2.0.0-preview1-002111-00 Build : 1ff021936263d492539399688f46fd3827169983

Copied from original issue: dotnet/cli#6761

rainersigwald commented 7 years ago

From @livarcocc on June 5, 2017 19:27

I could not repro this.

I wonder if this is something depending on which shell you are using. I tried with zsh.

The folder I ended up with was /git/temp/Dotnet core Debugging Book/DumpMe.

I tried the following steps:

  1. mkdir "Dotnet core Debugging book"
  2. cd Dotnet\ core\ Debugging\ Book/
  3. dotnet new console -o DumpMe
  4. cd DumpMe
  5. dotnet restore
  6. dotnet build

All commands succeeded.

rainersigwald commented 7 years ago

From @dasMulli on June 5, 2017 22:19

I have seen similar issues when passing "URL-like" paths to msbuild arguments..

@livarcocc this reproduces with %20 in the path:

  1. mkdir evil%20directory
  2. cd evil%20directory
  3. dotnet new console (includes a restore)
  4. dotnet build

(OS X, 2.0.0-preview2-006098)

rainersigwald commented 7 years ago

From @micli on June 6, 2017 0:2

@livarcocc Indeed, it works when you use real blank character as “Dotnet core Debugging book”. But MS Build doesn't work under "URL-like" path as "Dotnet%20core%20Debugging%20Book" as @dasMulli said before. I think the root casue is MS Build cannot compatible "%20".

rainersigwald commented 7 years ago

From @livarcocc on June 6, 2017 1:8

@rainersigwald have you seen this before?

rainersigwald commented 7 years ago

This is similar to https://github.com/Microsoft/msbuild/issues/985, but that is fixed now. Based on the errors, it looks like a NuGet problem.

The critical error is

                   "S:\work\escaped%20space\escaped%20space.csproj" (Build target) (1) ->
                   (RunResolvePackageDependencies target) -> 
                     C:\Program Files\dotnet\sdk\2.0.0-preview1-005977\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(155,5): error : Assets file 'S:\work\escaped space\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [S:\work\escaped%20space\escaped%20space.csproj]

Note that it unescaped the space there.

That target is defined as

    <ResolvePackageDependencies
      ProjectPath="$(MSBuildProjectFullPath)"
      ProjectAssetsFile="$(ProjectAssetsFile)"
      ProjectLanguage="$(Language)"
      ContinueOnError="ErrorAndContinue">

So this looks like the problem is that $(MSBuildProjectFullPath) needs to be treated as escaped.

BasieP commented 5 years ago

still open.... Is there a fix here?

nlowe commented 5 years ago

We're running into this too for some of our jenkins builds for branches that contain a / in the name. Depending on the branch length, Jenkins makes the working directory as foo%2Fbar, but dotnet build / restore tries to work with foo/bar\My.Project.sln instead of foo%2Fbar\My.Project.sln

mitchdowd commented 5 years ago

This is still an issue. Just like above, this affects us with Jenkins when we have feature branches with a forward slash in the branch name. Jenkins swaps it for a %2F in the directory name, but dotnet build seems to do a decode of that directory name so looks for non-existent subdirectory.

knom commented 5 years ago

+1 Just hit this in a project - and took us hours to find it.. It doesn't seem to be resolved in .NET Core 3..

niko-la-petrovic commented 3 years ago

Same issue when doing dotnet build on a Visual Studio extension project template. By default, the analyzer project has the following lines in it's main property group:

<!-- Avoid ID conflicts with the package project. -->
    <PackageId>*$(MSBuildProjectFullPath)*</PackageId>

since the NuGet package is typically called the same way as the analyzer project. When doing dotnet build , this causes

usr/share/dotnet/sdk/5.0.301/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(241,5): error NETSDK1060: Error reading assets file: Error loading lock file '/home/usr/Test/Test/obj/project.assets.json' : 'home/usr/Test/RefLib/RefLib.csproj*/1.0.0' is not a valid version string. (Parameter 'value') [/home/usr/Test/Test/Test.csproj]

Any workaround to make dotnet build work without supplying the project name itself (while also keeping MSBuild working using MSBuildProjectFullPath, preferrably)?

Logerfo commented 1 year ago

This is still happening even with the current preview.

roborchiston commented 5 months ago

Still happening in Microsoft Visual Studio Professional 2022 (64-bit) - Current Version 17.7.3 Brand new build env, pulled in from Azure DevOps source control. Space added in the Path due to project name. Project References were not loaded until I took the %20 out of the path name which were added automatically when pulling the project down.