Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Abolute path in dotnet watch run command doesn't work

Tags:

To run dotnet core application with specified absolute path we need to run following command:

dotnet run -p C:\foo\bar\Project\Project.csproj 

But it seems it doesn't work the same with dotnet watch run:

watch : Could not find a MSBuild project file in 'C:\directory\where\we\execute\command'. Specify which project to use with the --project option. 

Running the same command with -project instead of -p doesn't help however...

Dotnet watch help specifies -p or -project parameter anyway:

Microsoft DotNet File Watcher 2.1.1-rtm-30846

Usage: dotnet watch [options] [[--] ...]

Options: -?|-h|--help Show help information
-p|--project The project to watch -q|--quiet Suppresses all output except warnings and errors -v|--verbose
Show verbose output --list Lists all discovered files without starting the watcher --version Show version information

Environment variables:

DOTNET_USE_POLLING_FILE_WATCHER When set to '1' or 'true', dotnet-watch will poll the file system for changes. This is required for some file systems, such as network shares, Docker mounted volumes, and other virtual file systems.

DOTNET_WATCH dotnet-watch sets this variable to '1' on all child processes launched.

Remarks: The special option '--' is used to delimit the end of the options and the beginning of arguments that will be passed to the child dotnet process. Its use is optional. When the special option '--' is not used, dotnet-watch will use the first unrecognized argument as the beginning of all arguments passed into the child dotnet process.

For example: dotnet watch -- --verbose run

Even though '--verbose' is an option dotnet-watch supports, the use of '--' indicates that '--verbose' should be treated instead as an argument for dotnet-run.

Examples: dotnet watch run dotnet watch test

What's wrong then? Why absolute path to project doesn't work with dotnet watch run while works with dotnet run?

like image 440
Arkadiusz Kałkus Avatar asked Jan 18 '19 13:01

Arkadiusz Kałkus


People also ask

What is dotnet watch run?

dotnet watch is a tool that runs a . NET Core CLI command when source files change. For example, a file change can trigger compilation, test execution, or deployment. This tutorial uses an existing web API with two endpoints: one that returns a sum and one that returns a product.

What is dotnet Run command?

Description. The dotnet run command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code.


2 Answers

You can resolve this by specifying the -p (or the longer --project) option on the watch command rather than on the run command. In your case, that would be:

dotnet watch -p C:\foo\bar\Project\Project.csproj run 

There's a note in the docs that covers this:

You can use dotnet watch --project <PROJECT> to specify a project to watch. For example, running dotnet watch --project WebApp run from the root of the sample app will also run and watch the WebApp project.

like image 135
Kirk Larkin Avatar answered Sep 21 '22 13:09

Kirk Larkin


I'm not 100% sure, but dotnet watch is looking for file changes in the current directory. So if you use absolute path it must know where should it looks for changes. Of course, such implementation is possible but I just think that nobody thinked about it when implementing watch command

like image 26
Piotr Stapp Avatar answered Sep 20 '22 13:09

Piotr Stapp