Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet-watch support for publish subprocess #38340

Open
superdarki opened this issue Nov 26, 2023 · 11 comments
Open

dotnet-watch support for publish subprocess #38340

superdarki opened this issue Nov 26, 2023 · 11 comments
Assignees
Labels
Area-CLI untriaged Request triage from a team member

Comments

@superdarki
Copy link

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 have :

Use :
  dotnet-watch [<forwardedArgs>...] [options]
Arguments :
  <forwardedArgs> Arguments to pass to the child dotnet process.
Options :
  ...

Is 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

  • ID: 16f49f1b-261c-8cd0-a024-32c2535d0a0f
  • Product: dotnet-fundamentals
@superdarki
Copy link
Author

superdarki commented Nov 26, 2023

Btw, I use the last 8.0 version downloadable on dotnet.microsoft.com and I tried with the latest 6.x version.

@tdykstra
Copy link
Contributor

What exactly is the command you're using that doesn't work?

@Gnitry
Copy link

Gnitry commented Jan 25, 2024

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]

@afmg-aherzog
Copy link

As I see, dotnet watch doesn't take into account command 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 execute dotnet 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.

@tdykstra tdykstra self-assigned this Jan 29, 2024
@tdykstra
Copy link
Contributor

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.

@tdykstra tdykstra transferred this issue from dotnet/docs Jan 29, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-CLI untriaged Request triage from a team member labels Jan 29, 2024
@tdykstra tdykstra removed their assignment Jan 29, 2024
@case303
Copy link

case303 commented Mar 12, 2024

There are a couple other issues about this: #36918 #34949
However, I'm not sure if publish was fixed in #37233
@baronfel @tmat

@baronfel
Copy link
Member

Looks like publish isn't one of the known/supported commands in the rewrite that was done:

var runCommand = new CliCommand("run") { Hidden = true };
var testCommand = new CliCommand("test") { Hidden = true };
var buildCommand = new CliCommand("build") { Hidden = true };

@case303 can you describe the use case for dotnet watch publish a bit more? I'm not very familiar with what that would be.

@afmg-aherzog
Copy link

@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.

@case303
Copy link

case303 commented Mar 12, 2024

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

command argument

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 run dotnet <command>, you can run dotnet watch <command>. If the child command isn't specified, the default is run for dotnet run.

Possible this could be plaguing other child commands?

@baronfel
Copy link
Member

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.

@brianmed
Copy link

brianmed commented Apr 6, 2024

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>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-CLI untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

8 participants