Arkadiusz Kałkus
Arkadiusz Kałkus

Reputation: 18353

Absolute path in dotnet watch run command doesn't work

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?

Upvotes: 27

Views: 21839

Answers (4)

DOUMBIA Mamadou
DOUMBIA Mamadou

Reputation: 390

In my case, I run in Terminal:

- cd MyProject

then

dotnet watch

Upvotes: 0

Kirk Larkin
Kirk Larkin

Reputation: 93003

You need to specify the --project option on the watch command rather than on the run command:

dotnet watch --project 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.

Upvotes: 41

Ahsan Anwar
Ahsan Anwar

Reputation: 1

In my case, its just a minor error, you have to enter in the project directory before executing dotnet command, like:

cd yourAppName dotnet watch run It'll run

Upvotes: 0

Piotr Stapp
Piotr Stapp

Reputation: 19830

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

Upvotes: 3

Related Questions