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 informationEnvironment 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
?
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, runningdotnet watch --project WebApp run
from the root of the sample app will also run and watch the WebApp project.