Reputation: 303
There's a good feature in ASP.NET core apps using Visual Studio and IIS Express that you can change the C# code and just refresh the browser to apply the change, no rebuild required.
Is there anyway to do the same in VS Code, or Command Line?
With command line, you'll have to dotnet run
, change the code, Ctrl+C
to shutdown server, and again dotnet run
to apply the changes.
Am I missing something or is there another way to do it in Code or CommandLine what we do in Visual Studio?
Upvotes: 3
Views: 855
Reputation: 19598
You can do it VSCode as well as in commandline. If you want to use in commandline, you need to install a tool called dotnet watch. Once you install it, instead of using dotnet run
you should use dotnet watch run
. This will watch for changes in the file system and will compile based on the changes.
Add the following statement in project.json under tools section.
"Microsoft.DotNet.Watcher.Tools": "1.0.0-preview2-final"
Execute the dotnet restore
command, then you can run dotnet watch run
. You can find more details dotnet watch here
And if you want to use in VSCode, you need to create a command in tasks.json file and you need to execute the task to watch. Here is the tasks.json file.
{
"version": "0.1.0",
"command": "dotnet",
"isShellCommand": true,
"args": [],
"tasks": [
{
"taskName": "build",
"args": [
"${workspaceRoot}\\project.json"
],
"isBuildCommand": true,
"problemMatcher": "$msCompile"
},
{
"taskName": "watch",
"args": [
"run"
],
"isWatching": true
}
]
}
You can use "Terminate running tasks" option in VS Code to stop this watch.
Hope it helps
Upvotes: 2