简体   繁体   English

如何在不调试或发布的情况下启动 ASP.NET MVC Core 以加快开发过程?

[英]How to launch ASP.NET MVC Core for faster development process without debugging or publishing?

Usually, when developing ASP.NET, I host the root of the project in IIS.通常,在开发ASP.NET时,我将项目的根目录托管在IIS中。 This helps me to just build and directly access the web application in the browser without launch it in visual studio debug mode.这有助于我在浏览器中构建并直接访问 web 应用程序,而无需在 Visual Studio 调试模式下启动它。

Here is how I set up IIS in ASP.NET MVC:这是我在 ASP.NET MVC 中设置 IIS 的方法:

I can open the site in browser simply just typing localhost/site-name with the above setting.我可以在浏览器中打开站点,只需使用上述设置输入 localhost/site-name。 But this method seems doesn't work in ASP.NET Core MVC.但是这种方法似乎在 ASP.NET Core MVC 中不起作用。

I have set the application pool to no managed code as it is required for .net core.我已将应用程序池设置为无托管代码,因为它是 .net 核心所必需的。

But the browser just display the directory但是浏览器只显示目录

So far, i have to do either below process in order to view the site in browser properly:到目前为止,我必须执行以下任一过程才能在浏览器中正确查看网站:

  • Launch it in Visual Studio debugging mode (url: localhost:[port]), or在 Visual Studio 调试模式下启动它(url: localhost:[port]),或者
  • Publish it using visual studio publisher (Go to menu Build > Publish), and host it an IIS Application with above setting.使用 Visual Studio 发布者发布它(转到菜单 Build > Publish),并将其托管在具有上述设置的 IIS 应用程序中。 (url: localhost/site-name) (网址:本地主机/站点名称)

But it kindly slows down the development process in my opinion.但在我看来,它会减缓开发过程。

Missing module缺少模块

Checkout the docs for hosting ASP.NET Core in IIS查看在 IIS 中托管 ASP.NET 内核的文档

There is a reference to the ASP.NET Core Module for IIS which is described as: IIS 的ASP.NET 核心模块参考如下:

The ASP.NET Core Module is a native IIS module that plugs into the IIS pipeline to either: ASP.NET 核心模块是一个原生 IIS 模块,可插入 IIS 流水线,用于:

  • Host an ASP.NET Core app inside of the IIS worker process (w3wp.exe), called the in-process hosting model.在 IIS 工作进程 (w3wp.exe) 内托管 ASP.NET 核心应用程序,称为进程内托管 model。
  • Forward web requests to a backend ASP.NET Core app running the Kestrel server, called the out-of-process hosting model.将 web 请求转发到运行 Kestrel 服务器的后端 ASP.NET 核心应用程序,称为进程外托管 model。

So you will need to have this module installed in IIS for your setup to work correctly.因此,您需要在 IIS 中安装此模块,以便您的设置正常工作。

A better alternative更好的选择

That said, there is an easy way to run ASP.NET (Full Framework or Core) applications in Visual Studio without having to debug to run the app.也就是说,有一种简单的方法可以在 Visual Studio 中运行 ASP.NET(完整框架或核心)应用程序,而无需调试运行应用程序。

Instead of clicking the green "Play" button every time you want to run the site, go to the "Debug" menu at the top of the window and select "Start Without Debugging" .而不是每次要运行站点时都单击绿色的“播放”按钮,go 到 window 和 select 顶部的“调试”菜单“开始”

The application will start and launch.应用程序将启动并启动。 Then when you make changes you only have to rebuild the project.然后,当您进行更改时,您只需重建项目。 The next time you make a request to the application in the browser the app will serve results using the latest changes.下次您在浏览器中向应用程序发出请求时,应用程序将使用最新更改提供结果。

You don't need to re-run the application every time you make changes - it's always running!您无需在每次进行更改时都重新运行应用程序 - 它始终在运行!

If you want to Debug after having started the application using "Start Without Debugging", you can "Attach" to the IIS Express process and start debugging.如果您想在使用“Start without Debugging”启动应用程序后进行调试,您可以“附加”到 IIS Express 进程并开始调试。

Open the "Debug" menu, select "Attach to Process", filter the list for "iisexpress", and select that process.打开“调试”菜单,select“附加到进程”,筛选“iisexpress”列表,然后 select 那个进程。

Visual Studio will load debug symbols and allow you to hit breakpoints. Visual Studio 将加载调试符号并允许您点击断点。

Then when you want to stop debugging, hit the red "Stop" button.然后当你想停止调试时,点击红色的“停止”按钮。 You will detach from the process, but the application will continue to run.您将与进程分离,但应用程序将继续运行。

You can attach and detach as many times as you want.您可以根据需要多次连接和分离。 Just make sure that after you make changes to your code you re-build the project before attaching to make sure the correct debug symbols are loaded.只需确保在更改代码后重新构建项目,然后再附加以确保加载了正确的调试符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM