dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

`dotnet publish --tl on` fails with `MSBUILD : error MSB1009: Project file does not exist.` #36921

Open JeroenOortwijn opened 11 months ago

JeroenOortwijn commented 11 months ago

Description

According to https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build, dotnet publish --tl on should build a .Net 8 project with terminal logging enabled.

Reproduction Steps

  1. Create a new .Net 8 project with dotnet new console.
  2. Publish it with dotnet publish --tl.
  3. Publish it with dotnet publish --tl on.

Expected behavior

Every step succeeds.

Actual behavior

dotnet publish --tl on fails with MSBUILD : error MSB1009: Project file does not exist.:

C:\Users\Jeroen\Downloads\Test>dotnet new console
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring C:\Users\Jeroen\Downloads\Test\Test.csproj:
  Determining projects to restore...
  Restored C:\Users\Jeroen\Downloads\Test\Test.csproj (in 216 ms).
Restore succeeded.

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,4s) → bin\Release\net8.0\publish\

Build succeeded in 1,1s

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl on
MSBuild version 17.8.3+195e7f5a3 for .NET
MSBUILD : error MSB1009: Project file does not exist.
Switch: on

Regression?

No response

Known Workarounds

No response

Configuration

C:\Users\Jeroen\Downloads\Test>dotnet --info
.NET SDK:
 Version:           8.0.100
 Commit:            57efcf1350
 Workload version:  8.0.100-manifests.8d38d0cc

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100\

.NET workloads installed:
 Workload version: 8.0.100-manifests.8d38d0cc
There are no installed workloads to display.

Host:
  Version:      8.0.0
  Architecture: x64
  Commit:       5535e31a71

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]
  6.0.417 [C:\Program Files\dotnet\sdk]
  8.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.15 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.25 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

Other information

No response

dotnet-issue-labeler[bot] commented 11 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

vitek-karas commented 11 months ago

The same problem exists with dotnet build --tl on which fails the same way.

Also the docs only describe this option for dotnet build, but it seems to work for dotnet publish as well, so might be worth updating.

baronfel commented 11 months ago

Short-term workaround: use the --tl=<on|off|auto> format - replacing the space between the option and the arg with an equals sign. That should always work. We'll look into what's happening in the CLI and see if docs updates need to happen.

baronfel commented 11 months ago

re: @vitek-karas - it's available for any command that delegates to MSBuild under the covers, so we probably need to do more thorough documentation:

definitely support it, but there may be one or two more I'm forgetting.

baronfel commented 11 months ago

This is 'just' a doc bug. What we're doing here is just letting the dotnet CLI pass through to MSBuild, so you have to use the MSBuild syntax. I'll send a PR to the docs for now. For 8.0.200 we should make a proper .NET CLI option so that usres have the nicer syntax.

baronfel commented 11 months ago

Logged https://github.com/dotnet/docs/issues/38259 to track the docs updates.

adegeo commented 11 months ago

I filed a request back before the repos split with runtime/sdk (I think, if my memory is correct) requesting that the CLI build in a way to export every command and description to a json output. The Azure CLI did this and it was extremely easy to use that JSON to automate docs, do diffs to find differences, etc.

Should I file another request?

baronfel commented 11 months ago

Yes please - that's directly aligned with something that I was discussing with @MiYanni yesterday.

JeroenOortwijn commented 11 months ago

Short-term workaround: use the --tl=<on|off|auto> format - replacing the space between the option and the arg with an equals sign. That should always work. We'll look into what's happening in the CLI and see if docs updates need to happen.

Unfortunately that doesn't work either:

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl=on
MSBuild version 17.8.3+195e7f5a3 for .NET
MSBUILD : error MSB1001: Unknown switch.
    Full command line: 'C:\Program Files\dotnet\sdk\8.0.100\MSBuild.dll -maxcpucount -verbosity:m -restore -target:Publish --property:_IsPublishing=true -property:Configuration=Release --tl=on -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\8.0.100\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\8.0.100\dotnet.dll'
  Switches appended by response files:
Switch: --tl=on

For switch syntax, type "MSBuild -help"
JeroenOortwijn commented 11 months ago

This is 'just' a doc bug. What we're doing here is just letting the dotnet CLI pass through to MSBuild, so you have to use the MSBuild syntax. I'll send a PR to the docs for now. For 8.0.200 we should make a proper .NET CLI option so that usres have the nicer syntax.

I don't think it's just a documentation bug, because the --configuration switch does work correctly:

C:\Users\Jeroen\Downloads\Test>dotnet publish --configuration Debug
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Debug\net8.0\Test.dll
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Debug\net8.0\publish\
JeroenOortwijn commented 11 months ago

Short-term workaround: use the --tl=<on|off|auto> format - replacing the space between the option and the arg with an equals sign. That should always work. We'll look into what's happening in the CLI and see if docs updates need to happen.

Unfortunately that doesn't work either:

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl=on
MSBuild version 17.8.3+195e7f5a3 for .NET
MSBUILD : error MSB1001: Unknown switch.
    Full command line: 'C:\Program Files\dotnet\sdk\8.0.100\MSBuild.dll -maxcpucount -verbosity:m -restore -target:Publish --property:_IsPublishing=true -property:Configuration=Release --tl=on -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\8.0.100\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\8.0.100\dotnet.dll'
  Switches appended by response files:
Switch: --tl=on

For switch syntax, type "MSBuild -help"

Looking through the code, I found a working solution:

C:\Users\Jeroen\Downloads\Test>dotnet publish -tlp:default=on
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,2s) → bin\Release\net8.0\publish\

Build succeeded in 0,8s

C:\Users\Jeroen\Downloads\Test>dotnet publish -tlp:default=off
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\Test.dll
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\publish\

C:\Users\Jeroen\Downloads\Test>dotnet publish -tlp:default=auto
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,2s) → bin\Release\net8.0\publish\

Build succeeded in 0,9s
JeroenOortwijn commented 11 months ago

Another working solution (from: https://github.com/dotnet/msbuild/issues/9150):

C:\Users\Jeroen\Downloads\Test>dotnet publish -tl:on
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,2s) → bin\Release\net8.0\publish\

Build succeeded in 0,9s

C:\Users\Jeroen\Downloads\Test>dotnet publish -tl:off
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\Test.dll
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\publish\

C:\Users\Jeroen\Downloads\Test>dotnet publish -tl:auto
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,3s) → bin\Release\net8.0\publish\

Build succeeded in 0,9s

And --tl then also works:

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl:on
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,2s) → bin\Release\net8.0\publish\

Build succeeded in 0,9s

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl:off
MSBuild version 17.8.3+195e7f5a3 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\Test.dll
  Test -> C:\Users\Jeroen\Downloads\Test\bin\Release\net8.0\publish\

C:\Users\Jeroen\Downloads\Test>dotnet publish --tl:auto
MSBuild version 17.8.3+195e7f5a3 for .NET
Restore complete (0,4s)
  Test succeeded (0,2s) → bin\Release\net8.0\publish\

Build succeeded in 0,9s