Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
267 views
in Technique[技术] by (71.8m points)

c# - How to Edit and Continue in ASP.Net MVC 6

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...