问题
We're using Visual Studio Code and DNX as follows.
Command Line to Start Web Server
dnx . web
project.json > commands
"web": "Microsoft.AspNet.Hosting
--server Microsoft.AspNet.Server.WebListener
--server.urls http://localhost:5001"
Note that we added carriage returns for readability.
When we change a *.cshtml
and refresh the browser, the changes show up in the browser. This is good.
When we change a *.cs
and refresh the browser, the changes do not show up in the browser. We expected that they would. To see the changes, we need to stop the web server (with Ctrl + C
in the command line) and then start it again with dnx . web
.
This isn't the end of the world; that said, I thought one of the features of ASP.NET 5 was the ability to refresh without recompiling etc.
How can we change *.cs
code and refresh the browser to see the changes without having to restart the DNX web server?
We have tried running dnx --watch . web
with the problem that, if we change a *.cs
file, then the web server stops and we must restart it anyway.
回答1:
This is the expected behavior. You can use something like gulp-aspnet-k to automate this process. More detailed info available here: Building and Running Your ASP.NET vNext Application with Gulp.
Note that this gulp integration unfortunately only works on Windows now but all it does is to watch the dnx process and restart it again.
回答2:
The change code on the fly feature works only when running without debugging. I assume you just press F5 (debug) from VS which actually attaches a debugger. Try without and it should work.
Long story short: in order to refresh the code behind, the server has to restart. When running from the command line, the server stops and never restarts - you have to handle that yourself, like @tugberk suggested - but when running from VS, tooling takes care of that for you.
回答3:
There is a command you can use for this, called dnx-watch. It didn't exist when the original question was asked, but was added in beta 8 in September 2015. You install it using
dnu commands install Microsoft.Dnx.Watcher You run it by simply passing to it the command you would have passed to dnx. So, replace
dnx web
with
dnx-watch web
You can learn more here: http://ardalis.com/get-started-with-dnx-watch
来源:https://stackoverflow.com/questions/30289023/view-code-changes-without-restarting-the-server