Open superdarki opened 11 months ago
Btw, I use the last 8.0 version downloadable on dotnet.microsoft.com and I tried with the latest 6.x version.
What exactly is the command you're using that doesn't work?
As I see, dotnet watch
doesn't take into account command
argument. It always run the application.
Steps to reproduce (I'm trying to let it publish the application on source change):
PS C:\1> dotnet new console
The template "Console App" was created successfully.
Processing post-creation actions...
Restoring C:\1\1.csproj:
Determining projects to restore...
Restored C:\1\1.csproj (in 102 ms).
Restore succeeded.
PS C:\1> dotnet watch publish
dotnet watch 🔥 Hot reload enabled. For a list of supported edits, see https://aka.ms/dotnet/hot-reload.
💡 Press "Ctrl + R" to restart.
dotnet watch 🔧 Building...
Determining projects to restore...
All projects are up-to-date for restore.
1 -> C:\1\bin\Debug\net8.0\1.dll
dotnet watch 🚀 Started
Hello, World!
dotnet watch ⌚ Exited
dotnet watch ⏳ Waiting for a file to change before restarting dotnet...
dotnet watch 🛑 Shutdown requested. Press Ctrl+C again to force exit.
As we see, it doesn't publish (dotnet publish
) the application, it runs the app (dotnet run
). The same occurs when I execute dotnet watch build
. If I'm not mistaken, it worked different before.
PS: installed SDKs:
PS C:\1> dotnet --list-sdks
5.0.405 [C:\Program Files\dotnet\sdk]
6.0.200 [C:\Program Files\dotnet\sdk]
6.0.418 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
7.0.405 [C:\Program Files\dotnet\sdk]
8.0.101 [C:\Program Files\dotnet\sdk]
As I see,
dotnet watch
doesn't take into accountcommand
argument. It always run the application....
As we see, it doesn't publish (
dotnet publish
) the application, it runs the app (dotnet run
). The same occurs when I executedotnet watch build
. If I'm not mistaken, it worked different before.
I could see the same behavior after upgrading from dotnet sdk 7.0.4XX to 8.0.101. This broke a whole workflow for our team, because building your own auto-publish on change is not trivial to get right.
This looks like a bug that was introduced in .NET 8.0 SDK. I get the expected behavior with dotnet watch publish
if global.json is set up for earlier SDK versions, while with .NET 8 SDK the same command runs dotnet run
and not dotnet publish
. Since this is a product bug rather than a documentation error I'm transferring this issue to the SDK repo.
There are a couple other issues about this: #36918 #34949
However, I'm not sure if publish
was fixed in #37233
@baronfel @tmat
Looks like publish
isn't one of the known/supported commands in the rewrite that was done: https://github.com/dotnet/sdk/blob/a0949af51e774067f50576877bce60ac491c475c/src/BuiltInTools/dotnet-watch/CommandLineOptions.cs#L150-L152
@case303 can you describe the use case for dotnet watch publish
a bit more? I'm not very familiar with what that would be.
@case303 can you describe the use case for
dotnet watch publish
a bit more? I'm not very familiar with what that would be.
We use it to auto update the input of a system test tool. We need dotnet publish
so we get all dependencies in the output dlls. So the use case is make change -> auto publish to specific location -> restart test in other tool
.
Thanks @baronfel, I'm working on an issue, running watch on a Class Library, not an executable.
Similar to what's described here and #36918, essentially dotnet watch publish
had worked in versions 5, 6, 7, but noticed the behavior's changed in 8 (after updating VS 2022 - 17.9.2).
dotnet watch --verbose --project Server/test_project_05.Server.csproj publish --configuration Release
dotnet watch 🚀 Started
Running dotnet with the following arguments: 'run publish --configuration Release'
Unable to run your project.
Ensure you have a runnable project type and ensure 'dotnet run' supports this project.
A runnable project should target a runnable TFM (for instance, net5.0) and have OutputType 'Exe'.
The current OutputType is 'Library'.
dotnet watch documentation states:
When it detects a change, it runs the dotnet run command or a specified dotnet command
dotnet watch can run any command that is dispatched via the
dotnet
executable, such as built-in CLI commands and global tools. If you can rundotnet <command>
, you can rundotnet watch <command>
. If the child command isn't specified, the default isrun
fordotnet run
.
Possible this could be plaguing other child commands?
Almost certainly yes - in .NET 8 the command was pretty drastically rewritten. I don't think the arbitrary command use case was taken into account. @tmat it's very reasonable that arbitrary commands should be used with watch
, IMO.
I would be grateful if the arbitrary command use case would be supported again.
I had a script called dotnet-copyPublish
and it would publish my wasm project and copy the resulting directory to my server project that has the wasm directory embedded.
Also, the wasm directory in my server project was added to Watch in the csproj. This way, my wasm project would cause the server project to auto build, after a wasm change.
Yes, I did have two terminals with dotnet watch
running.
Further, sometimes, I would have my server project rsync the published single file to a remote Linux box and then use ssh to run the app remotely.
Doing this made it possible to have a code --> compile --> publish --> deploy --> run loop that was automated and fast.
This worked really well.
dotnet-copyPublish snippet
dotnet publish --configuration Debug
if [ -d "../Linux/adminwasm" ]; then
mv -i ../Linux/adminwasm "$FORDELETE"/adminwasm
fi
cp -a -i bin/Debug/net8.0/publish/wwwroot ../Linux/adminwasm
csproj snippet
<ItemGroup>
<EmbeddedResource Include="adminwasm\**" />
<Watch Include="adminwasm\**" />
<Watch Include="adminwasm" />
</ItemGroup>
Type of issue
Other (describe below)
Description
Hello !
I have a particular use case where I need dotnet-watch to use the publish sub process but the CLI tool does not take the argument described in the docs.
This arg is also present in the readme of dotnet-watch in the sdk but when I run :
dotnet watch -?
I only haveIs this a planned change of the tool not even described in the sdk readme or an error ?
Thanks ! Lucas
Page URL
https://learn.microsoft.com/fr-fr/dotnet/core/tools/dotnet-watch
Content source URL
https://github.com/dotnet/docs/blob/main/docs/core/tools/dotnet-watch.md
Document Version Independent Id
218d2a4d-2ff3-8e4d-1f06-bbb3710878fe
Article author
tdykstra
Metadata