Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

View code changes without restarting the server

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.

like image 743
Shaun Luttin Avatar asked May 17 '15 16:05

Shaun Luttin


2 Answers

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.

like image 158
Victor Hurdugaci Avatar answered Sep 19 '22 17:09

Victor Hurdugaci


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.

like image 44
tugberk Avatar answered Sep 19 '22 17:09

tugberk