Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web server for ASP.NET 5 that works without debugging active

sorry if this is a stupid question but I don't get it. So I've created an ASP.NET 5 page using Visual Studio 2015 and DNX.

Out of the box I have these two dependencies in my project.json:

"Microsoft.AspNet.Server.IIS": "1.0.0-beta4",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta4"

Under "commands" in project.json I have the following:

"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000"

In the project properties I can change profiles between "IIS Express" and "web" as deployment options. Both are working fine, when I start debug it starts the web server (either IIS Express or the WebListener) and the site is working. If I stop debugging the server stops. The WebListener opens a "dnx.exe" in a command prompt.

This pluggable server layer is really nice, I get the point. But how do I, as a developer setup an easy server where I can make a change to my site and quickly see the changes? I can of course install IIS and create a site that is pointing to my wwwroot but is that my only option in the ASP.NET world? Can I have the WebListener "started in the background" (without showing me a command prompt with dnx.exe)? I can also start a node server but yet again - it's great that i can but why do I have to when I have the full ASP.NET toolbelt?

ASP.NET 5 has dynamic compilation but I'm not sure how to even test it since my web server is only started when I'm in debug mode.

I know that this is a pre-release but any help would be greatly appreciated.

like image 243
mikeesouth Avatar asked Jun 15 '15 21:06

mikeesouth


1 Answers

But how do I, as a developer setup an easy server where I can make a change to my site and quickly see the changes.

Regardless of the server used, you can use dynamic compilation by Starting the project without debugging (Shift + F5).

Due to architectural reasons, dynamic compilation does not work when starting with debugging (F5) in Visual Studio. This is due the fact that the difference between Shift + F5 and F5 is that in the latter, VS attaches the debugger to the process.

Will this every be supported in the future? That is unclear but right now because VS isn't "smart" enough to handle detaching from process, waiting for dnx to dynamically recompile, and then reattaching to the process. However until now it never had a reason to support such a scenario, so it is unclear if it is just a "it doesn't know how to do it yet" or a "it is impossible to do."

I can of course install IIS and create a site that is pointing to my wwwroot but is that my only option in the ASP.NET world?

No. You can use any webserver which supports Microsoft.AspNet.Hosting. Today your choices are limited to IIS, IIS Express, and the two experimental servers you linked to but the goal is to enable third parties to develop alternatives by providing an interface that can be programmed against (Microsoft.AspNet.Hosting).

ASP.NET 5 has dynamic compilation but I'm not sure how to even test it since my web server is only started when I'm in debug mode.

If the web application is running then the server is started. No webserver = no ASP.NET application. I assume by "debug mode" you mean "Start with Debug (F5)". If so then "Start without Debug (Shift + F5)" to fix the problem you're experiencing.

Here is an excercise:

  1. Close Visual Studio (not a requirement but useful to show none of this is VS specific).
  2. Start the web server. The easiest way would be dnx . web run from command line in the project root folder. You could however start IIS Express (should already be configured) or even configure the IIS and start it.
  3. Verify the web server and web application is running by opening it in a browser.
  4. Using notepad or some other text editor, edit a file in the project that would have a visible change or just force an error "throw new NullReferenceException()".
  5. Save the file.
  6. Refresh the browser.

The web application will reflect the change. You may notice a slight delay if you refresh quickly. That is the dynamic compilation to memory occurring.

like image 97
Gerald Davis Avatar answered Nov 15 '22 06:11

Gerald Davis