Build a .NET core application while running Kestre

2019-05-26 18:04发布

问题:

In classic .NET applications, I'd set up my local IIS to run the specified application. I could build the application and hit the endpoint to see the change immediately. I did not need to launch the debugger every time. I want to achieve this with .NET core using Kestrel server.

I'm able to run my application by running dotnet run from the command line. However, when I try to build, the files are in use and the build fails. Are there any development configuration options that do not lock down the files and instead run them only as needed, allowing me to build and test changes immediately?

回答1:

Extending the dotnet-cli with the Watcher-tool is the way to go. In short - reference

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="1.0.0" />
</ItemGroup> 

in your .csproj file and then run dotnet watch run from the commandline. That'll allow you to make changes to the code which will automatically recompile.

dotnet-watch