编辑并继续在 VS 2010 / ASP.Net MVC 2 中不起作用

发布于 2024-09-03 10:48:00 字数 347 浏览 6 评论 0原文

尽管在我的 ASP.Net MVC 2 项目的 Web 选项卡上选中了“启用编辑并继续”,但实际上我无法在运行时更改源代码。例如,如果我尝试在调试器暂停时编辑控制器,则无法更改该文件(就像只读一样)。

我找到了相关帖子在 ASP.NET Web 项目中编辑并继续,但是

  • 答案似乎表明我应该至少能够编辑代码,然后重新加载页面以查看结果。
  • 我不知道 Web 应用程序和网站项目之间有什么区别

Although Enable Edit and Continue is checked on the Web tab of my ASP.Net MVC 2 project, I cannot in fact change the source code while running. For example, if I try to edit a controller while paused in the debugger, I cannot change the file (acts as if read only).

I found a related post Edit and continue in ASP.NET web projects, however

  • The answers seem to suggest I should be able to at least edit the code, then reload the page to see the result.
  • I don't know what the distinction is between a Web Application and Web Site projects

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

迷迭香的记忆 2024-09-10 10:48:00

区别在于 Web 应用程序需要编译,而网站则在执行时动态编译(甚至是隐藏的代码)。

由于 ASP.NET MVC 使用 Web 应用程序,因此每次进行更改时都需要重新编译它,并且重新编译需要离开调试模式。事实上,您可以修改视图和部分而无需重新编译,但对于控制器逻辑,您始终需要重新编译。

为了加快速度,我建议您执行以下操作:

  1. 在使用视图和部分(即进行一些设计工作)时,使用 Ctrl+F5 而不是 F5 运行应用程序,这将只需在正常模式下启动应用程序,当您刷新浏览器时,您的更改就会自动生效
  2. 。使用代码隐藏时,您应该有一个相应的单元测试,可以让您快速检查行为。在这种情况下,在调试模式下运行可能更有用,因为您可能需要检查值。

The distinction is that a Web Application needs to be compiled while a Web Site is compiled dynamically when executed (even the code behind).

As ASP.NET MVC uses a web application every time you make a change you need to recompile it and recompiling requires leaving the Debug mode. Indeed you could modify views and partials without the need of recompiling but for controller logic you always need to recompile.

To speed things up I would recommend you the following:

  1. When working with views and partials (i.e. doing some design stuff) run the application with Ctrl+F5 instead of F5 which will simply start the application in normal mode and your changes will be automatically picked up when you refresh the browser
  2. When working with code behind you should have a corresponding unit test that will allow you to quickly check the behavior. In this case running in Debug mode might be more useful as you might require checking values.
靖瑶 2024-09-10 10:48:00

使用 Mvc,您无法编辑并继续。
但是,如果您通过 IISExpress 运行项目,那么无需在调试模式下运行项目,您就可以编辑代码隐藏,重建项目。然后刷新浏览器中的页面就可以了。

With Mvc you can't edit and continue.
But if you run the project by IISExpress, then without running the project in debug mode you can edit the codebehind, rebuild the project. And then refreshing the pages in browser would work.

独守阴晴ぅ圆缺 2024-09-10 10:48:00

除了@Darin 的回答之外,我不得不说我不喜欢在运行时更改代码的想法。

我认为我们应该有足够的纪律来编写反映预期结果的测试,编写代码然后进行实时测试。

尽管如此,我解决这个问题的方法是在浏览器中启动应用程序而不运行,进行更改,编译,然后刷新浏览器。

当然,这样我就没有逐步执行代码的好处,但我可以在需要时随时附加到工作进程。

Further to @Darin's answer I'd have to say I don't like the idea of being able to change code whilst running.

I think we should be disciplined enough to write a test that reflects the expected outcome, write the code and then test live.

Having said that though, the way I get around that is to start the application in a browser w/out running, making my changes, compiling and then refreshing the browser.

Of course then I don't have the benefit of stepping through code but I can attach to the worker process at any time I need to.

铃予 2024-09-10 10:48:00

升级到VS2012。这确实支持 ASP.Net 项目的“编辑并继续”(从项目属性窗口中的“Web”选项卡)。尽管默认情况下它似乎并未启用!

Upgrade to VS2012. This does support Edit and Continue for ASP.Net projects (from the Web tab in the project properties window). Although it doesn't appear to be enabled by default!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文