23

Back in the days using older versions of Visual Studio and ASP.NET was possible to edit the code while you were debugging it (even with some limitations).

How can I enable edit and continue using ASP.Net/VNext (MVC 6) with VS 2015 RC. This feature is available? The message that I receive is:

Error "Changes are not allowed if the project wasn't built when debugging started".

How can I build the project when the debug mode is starting?

J. Lennon
  • 3,311
  • 4
  • 33
  • 64

4 Answers4

10

I got Edit and Continue to work in VS 2015 on my ASP.Net MVC 4 project. David R posted a link in his answer (here again for completeness)

http://blogs.msdn.com/b/visualstudioalm/archive/2015/04/29/net-enc-support-for-lambdas-and-other-improvements-in-visual-studio-2015.aspx

The page says that VS2015 supports Edit Continue on Attach To Process if an environment variable is set during load of the runtime. The way I understand it is that this variable cues in the CLR to allocate a little bit of extra memory which is needed for Edit and Continue to work.

Now the trick is to get the w3wp.exe process running your application pool to load with this variable. On any other process I would just open a command line and do

set COMPLUS_FORCEENC=1
ExeToDebug.exe

But I couldn't find a way to directly run my app pool with an environment variable. I posted a workaround (as CSUdev) on this page, that is a little hack which sets a machine level environment variable, resets iis, calls a url which starts the app pool, then clears the machine level environment variable. http://forums.iis.net/p/1195182/2115550.aspx?p=True&t=635895941266217500

The OP in that thread said he used to have this working in prior versions of IIS by setting Environment variables for the user profile that the Application Pool would then load when its user profile loaded, although he wasn't able to get the working in IIS8 (might be related to WS2012/Win8 security settings in the OS).

tldr; here's how I got it working

Wrote bat script...

#set Edit n Continue variable (global... :/ )
setx /m COMPLUS_FORCEENC 1

#kill/restart existing app pools
iisreset

#force app pool to start up (and use the Edit & Continue var)
#you can download wget or curl (instead of start) 
#if you don't want this to open up your default browser every time
start "http://localhost/urlForAspNetApp" 

#clear Edit n Continue var
setx /m COMPLUS_FORCEENC ""

Then VS2015 attach to process w3wp.exe. Bam. Edit and Continue. Thanks MS & VS2015 folks!

C. Tewalt
  • 2,271
  • 2
  • 30
  • 49
  • rats... and you can guess from my answer, this was using .Net 4.5... not sure how this will work on .Net Core, and asp.net core, etc... but hopefully this is still helpful to someone. – C. Tewalt Jan 28 '16 at 22:12
  • 1
    Despite trying everything here http://stackoverflow.com/questions/1010213/edit-and-continue-changes-are-not-allowed-when-the-debugger-has-been-attached , the Edit and Continue did not work for me. However your script made it working :) The only extra thing I had to do was to ensure under Tools > Options > Debugging > General > "Require source files to exactly match the original version" is unchecked. – Abhishek Shrivastava Mar 30 '16 at 17:08
  • Sadly, it did not work for me. I verified the env variable got set, I have unchecked "Require source files to exactly match the original version" and I have switched the project type to x86. Still, no success. I could only ever make it work with IIS Express. – DenNukem May 18 '16 at 17:57
  • 1
    Personally, I just set `COMPLUS_FORCEENC=1` via Environment Varables -> system variables – Brian Sep 13 '17 at 20:19
5

Edit and Continue does not work for ASP.NET 5 applications at this point in Visual Studio 2015, but it is planned to support it in the final 2015 release.

For more information about VS2015 ENC changes, have a look at this blog entry: http://blogs.msdn.com/b/visualstudioalm/archive/2015/04/29/net-enc-support-for-lambdas-and-other-improvements-in-visual-studio-2015.aspx

David Roth
  • 677
  • 4
  • 14
  • 1
    David, any update on when Edit and Continue will present itself? I've tried dnx-watch and it doesn't work. What does work is nodemon, but restarting the dnx web call is abysmally slow. This may not be the best place to ask this, but its worth a shot. – Stuart Allen Dec 13 '15 at 02:21
  • @StuartAllen Any luck or new information? Google doesn't give much help. – Josh Mouch Jan 10 '16 at 16:51
  • @StuartAllen I guess ENC will be available in the RTM version of ASP.NET 5 or maybe in one of the next RC versions. In RC1 it is still not working. Although this is speculative, I haven't found any official announcement either. – David Roth Jan 11 '16 at 08:40
  • 1
    Still not working for me either, I had to go back to the older pattern for the time being, not having ENC is a nightmare for my flow. Having to restart dnx everytime I edit frontend code is way too slow. – Stuart Allen Jan 11 '16 at 11:07
1

This seems to be fixed for VS 2015 Update 1 for MVC 6 projects after this servicing update is installed https://www.microsoft.com/en-us/download/details.aspx?id=50723

Matt Kocaj
  • 11,278
  • 6
  • 51
  • 79
1

I have ASP.NET MVC5 and realized that if you use IIS Express "Edit and Continue" works pretty much out of the box.

With "Local IIS" it does not work, did not try the "COMPLUS_FORCEENC" setting from matrixugly's post though.

Ended up switching to IIS Express for debugging because of this.

Florin D
  • 1,610
  • 18
  • 17