0

I'm coming from a PHP background, working with WAMP server. I'm now trying to learn ASP.NET MVC using Visual Studio Community 2015 as IDE. When working with WAMP, you can make changes to your server or client code and simply refresh the page to see them. In Visual Studio on the other hand, I have to hit the debug button each time to compile and get IIS running. The problem is Visual Studio won't let me edit the server code when in debug mode, it won't let me edit some of the client code (cshtml files) and it limits the actions I can do on files in my project in general. So I find myself constantly having to click debug and stop debugging, which is a real nuisance compared to the smooth workflow in PHP. I understand that things are different due to C# having to be compiled, but isn't there a way to have the server constantly running in the background, so that I just have to build the project when I make changes to the server code and refresh the page in the browser? (and for client code I should just be able to refresh the browser to see changes...)

Royar
  • 611
  • 6
  • 21
  • If you click the pause button, you can edit most files. – Alexander Derck Jun 17 '16 at 09:40
  • Normally, you should be able to edit `.cshtml` files, hit refresh and then see the changed pages without having to restart debugging. The same applies to client side scripts. Also, the debugger has a feature called _edit and continue_ but to be honest I'm not sure you can get it to work with ASP.NET projects. – Martin Liversage Jun 17 '16 at 09:41
  • You should be able to edit .cshtml files since they are only compiled at runtime, so your changes will be picked up by refreshing the page in your browser. The only exception might be if you have specified that the views must be compiled. – user1666620 Jun 17 '16 at 09:44
  • _"I find myself constantly having to click debug and stop debugging, which is a real nuisance compared to the smooth workflow in PHP"_ - well pardon my French, but that workflow isn't really programming, it's hacking. Yes, you can enable it through various mechanisms, but the real problem is that you should think first, then code, then test and finally run. So if you introduce proper abstractions and unit tests, you'll find the need to edit code while running it diminish very fast. – CodeCaster Jun 17 '16 at 09:45
  • You should be able (not sure if in Express you can) to check a flag to allow edit during debug. You should also be able to host your Server in Local IIS(that runs even if Debug isn't started) instead of the VS one – Matteo Umili Jun 17 '16 at 09:48
  • See also [How to Edit and Continue in ASP.Net MVC 6](http://stackoverflow.com/questions/30632427/how-to-edit-and-continue-in-asp-net-mvc-6). – CodeCaster Jun 17 '16 at 09:50
  • @CodeCaster as far as i understand "edit and continue" allow you to keep IIS Express running and make change in file and refresh browser. but this question is quite different, he also asked about dynamic compilation things. request you not to mark this as duplicate. – Abhimanyu Jun 17 '16 at 09:53
  • @Abhimanyu no, they didn't. The problem statement is _"Visual Studio won't let me edit the server code when in debug mode"_. – CodeCaster Jun 17 '16 at 09:56
  • @CodeCaster cool, if you think "Visual Studio won't let me edit the server code when in debug mode" has some relation with duplicated reference link. sadly agreed :( – Abhimanyu Jun 17 '16 at 09:59
  • Thanks for the answers. I have no experience in unit testing @CodeCaster, have any recommendation for a good source to learn how to do c# unit tests? Would you also recommend using a DI framework (I heard it helps make code more testable)? I currently program as a hobby and I started working on a board game in ASP.NET MVC+CreateJS in the client. – Royar Jun 17 '16 at 11:03
  • @Royar no, sorry, I don't have one good source for unit testing. There are a couple of books (of which none I can recommend) and a lot of blogs, but over all most of it takes practice. – CodeCaster Jun 17 '16 at 11:30

2 Answers2

2

Yes this was real frustration before Roslyn comes in picture. Roslyn can enable you to do everything you mentioned.

Roslyn uses dynamic compilation, so we can just make the changes in the code and need to just refresh the browser to reflect our changes. In the previous versions of ASP.NET we have to make code changes then re-build the solution and then refresh the browser for our changes to take effect.

In case of .cshtml page, this never required compilation so you can still make changes and refresh browser to see changes, just make sure IIS Express keeps running...that's it.

To get started with C# dynamic compilation with Roslyn, suggest you to read this post http://www.codeproject.com/Articles/835251/Overview-of-ASP-NET-vNext#rosy

Abhimanyu
  • 2,173
  • 2
  • 28
  • 44
1

Use detatch process. Using this way you cannot debug(can't use breakpoints), but your IIS will be running.

Once you detatch your application then you can edit your code. After editing need to build your project, then if you refresh your browser you can see the changes. Please refer here .

Community
  • 1
  • 1
NnN
  • 463
  • 2
  • 11
  • Detaching the debugger and having to attach it again after editing is a real cumbersome workflow, especially if multiple web servers are running (which process to attach to?) and having the web server frequently crash upon detaching. – CodeCaster Jun 17 '16 at 09:49
  • Then we have to publish our application to IIS(local machine should configured with IIS). Once we publish our applications, we can run them from IIS, but need to refresh the application in IIS after making changes in code level. – NnN Jun 17 '16 at 10:08
  • That's a totally outdated and unproductive workflow, and you can still have multiple IIS worker processes to attach to. – CodeCaster Jun 17 '16 at 10:08