dotnet / dotnet/aspnetcore

"dotnet watch publish --no-build --no-restore" does not recover when started for a project that has not been built yet.

Open
#65,745 0 comments 0 reactions 0 assignees View on GitHub
area-commandlinetools
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I have a solution with properly functioning `dotnet publish --no-build --no-restore`, i.e. I can build the code without publishing it and publish it without building (i.e. it has already been built). And I also have `dotnet watch publish --no-build --no-restore` working great. Except when that command is started before the code is built for the first time. In that case the watch window shows this:
```
dotnet watch ❌ Error(s) finding watch items project file 'AspNetTest.csproj'.
dotnet watch 🔨 MSBuild output from target 'GenerateWatchList':
dotnet watch 🔨 MSBuild logs and debug information will be at "c:\temp\binlogs\watch\AspNetTest"
dotnet watch ❌ C:\dayforce\DevOps\Dayforce.Web\tests\apps\Microsoft.WebApplication.targets(136,5): error MSB3030: Could not copy the file "obj\Debug\AspNetTest.dll" because it was not found. [C:\dayforce\DevOps\Dayforce.Web\tests\apps\AspNetTest\AspNetTest.csproj]
dotnet watch ⌚ Fix the error to continue or press Ctrl+C to exit.
```
Which is expected, since the watch tries to publish what has not been built yet. What is unexpected is that after building the code, the watch does not recover despite the message implying to the contrary.
Either there is a bug to recover from failure or the phase **Fix the error to continue or** must be removed, because the only course of action at this point is to exit.

### Expected Behavior

Once the code is built, the watch is able to resume normal operation.

### Steps To Reproduce

1. `git clone https://markk-df@github.com/dayforce-hcm/SimpleAspNetApp`
2. `cd .\SimpleAspNetApp`
3. `git checkout 05_EnableDotnetWatch`
4. ` .\watch.ps1` # This is when the issue happens, the code has not been built yet
5. `dotnet build` # This is expected to fix the issue, but it does not.

The solution was created in order to demonstrate the different build aspects of a minimal **real world** example of a legacy Asp.Net Mvc application, which uses SDK style projects only.

```csharp
C:\work> git clone https://markk-df@github.com/dayforce-hcm/SimpleAspNetApp
Cloning into 'SimpleAspNetApp'...
remote: Enumerating objects: 74, done.
remote: Counting objects: 100% (74/74), done.
remote: Compressing objects: 100% (50/50), done.
remote: Total 74 (delta 20), reused 69 (delta 15), pack-reused 0 (from 0)
Receiving objects: 100% (74/74), 34.73 KiB | 4.96 MiB/s, done.
Resolving deltas: 100% (20/20), done.
C:\work> cd .\SimpleAspNetApp\
C:\work\SimpleAspNetApp [master ≡]> git co 05_EnableDotnetWatch
Note: switching to '05_EnableDotnetWatch'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

git switch -c

Or undo this operation with:

git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 91a1392 Allow dotnet watch publish to handle Lib content files
C:\work\SimpleAspNetApp [(05_EnableDotnetWatch)]> .\watch.ps1
C:\work\SimpleAspNetApp [(05_EnableDotnetWatch)]> dotnet build
Restore complete (1.1s)
Lib net472 succeeded (1.0s) → bin\Lib.dll
Main net472 succeeded (0.4s) → bin\_PublishedWebsites\Main\bin\Main.dll

Build succeeded in 2.6s
C:\work\SimpleAspNetApp [(05_EnableDotnetWatch)]>
```

### Exceptions (if any)

_No response_

### .NET Version

10.0.103

### Anything else?

.NET SDK:
Version: 10.0.103
Commit: c2435c3e0f
Workload version: 10.0.100-manifests.c992be6d
MSBuild version: 18.0.11+c2435c3e0

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

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
No workload sets are installed. Run "dotnet workload restore" to install a workload set.

Host:
Version: 10.0.3
Architecture: x64
Commit: c2435c3e0f

.NET SDKs installed:
9.0.308 [C:\Program Files\dotnet\sdk]
9.0.311 [C:\Program Files\dotnet\sdk]
10.0.103 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.36 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 8.0.22 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 8.0.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.