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

[Bug]: can't find project file in root directory #10540

Open hickford opened 1 month ago

hickford commented 1 month ago

Issue Description

When run in root directory such as C:\, MSBuild can't find project file

Steps to Reproduce

  1. Create project file c:\hello.proj
  2. Change directory to c:\
  3. Run msbuild

Expected Behavior

MSBuild runs default target in project c:\hello.proj

Actual Behavior

MSBuild shows error:

MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

Versions & Configurations

MSBuild version 17.11.2+c078802d4 for .NET Framework 17.11.2.32701

baronfel commented 1 month ago

@rainersigwald we don't do globbing/discovery from a drive root by design, right? Concerns with enumeration performance/user foot-guns?

rainersigwald commented 1 month ago

No, we're not doing this on purpose. It works on .NET 9:

❯ ls *proj

    Directory: S:\

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---           8/20/2024 11:08 AM              0 build.proj

❯ msbuild
MSBuild version 17.12.0-preview-24412-02+0716e1c2a for .NET Framework
MSBUILD : error MSB1003: Specify a project or solution file. The current working directory does not contain a project or solution file.

❯ dotnet msbuild -tl:off
MSBuild version 17.12.0-preview-24374-02+48e81c6f1 for .NET
S:\build.proj : error MSB4025: The project file could not be loaded. Root element is missing.

This looks like a bug in .NET Framework's System.IO.Directory.EnumerateFiles(); check out the behavior of:

System.IO.Directory.SetCurrentDirectory(@"\");

var x = System.IO.Directory.GetFiles(".", "*.*proj");

System.Console.WriteLine(x.Length);
❯ .\play\io\bin\Debug\net472\io.exe
0

❯ .\play\io\bin\Debug\net6.0\io.exe
1