简体   繁体   English

如何在 IIS 上托管我的 ASP.NET 核心站点(在开发环境中,无需部署/发布)

[英]How to host my ASP.NET core site on IIS (in development environment, without deploy / publish)

I used to host my ASP.NET sites (not core) on IIS locally, in my development environment.在我的开发环境中,我曾经在 IIS 上本地托管我的 ASP.NET 站点(非核心)。
Doing it helped me avoiding from using IIS Express (It's very uncomfortable to start & stop IIS express every time).这样做帮助我避免使用 IIS Express(每次启动和停止 IIS Express 都非常不舒服)。
In this way all I had to do is to rebuild and refresh the site.这样,我所要做的就是重建和刷新站点。
My goal is to work with ASP.NET core in the same way.我的目标是以同样的方式使用 ASP.NET 内核。
I read this: https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x and it didn't go well.我读到这个: https://docs.microsoft.com/en-us/aspnet/core/publishing/iis?tabs=aspnetcore2x ,它没有 go 很好。
What I'm looking for is to do it without deploy / publish after every C# code change (that requires building).我正在寻找的是在每次 C# 代码更改(需要构建)后无需部署/发布即可。
I use ASP.NET core 2 & IIS 10我使用 ASP.NET 核心 2 & IIS 10

If you need to debug an application, you can configure the ASP.NET Core application as the default IIS startup. 如果需要调试应用程序,可以将ASP.NET Core应用程序配置为默认的IIS启动。

reference: https://docs.microsoft.com/aspnet/core/host-and-deploy/iis/development-time-iis-support#configure-the-project 参考: https//docs.microsoft.com/aspnet/core/host-and-deploy/iis/development-time-iis-support#configure-the-project

Create a new launch profile to add development-time IIS support. 创建新的启动配置文件以添加开发时IIS支持。 In Visual Studio's Solution Explorer , right-click the project and select Properties . 在Visual Studio的解决方案资源管理器中 ,右键单击该项目,然后选择“ 属性” Select the Debug tab. 选择“ 调试”选项卡。 Select IIS from the Launch dropdown. 从“ 启动”下拉列表中选择“ IIS ”。 Confirm that the Launch browser feature is enabled with the correct URL. 确认使用正确的URL启用了启动浏览器功能。

Or 要么

Alternatively, manually add a launch profile to the launchSettings.json file in the app: 或者,手动将启动配置文件添加到应用程序中的launchSettings.json文件:

{
"iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iis": {
        "applicationUrl": "http://localhost/WebApplication2",
        "sslPort": 0
    }
},
"profiles": {
    "IIS": {
        "commandName": "IIS",
        "launchBrowser": "true",
        "launchUrl": "http://localhost/WebApplication2",
        "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
        }
    }
}

You can take advantage of the app_offline.htm feature of the ASPNETCore module and incorporate this into your build process. 您可以利用ASPNETCore模块的app_offline.htm功能,并将其合并到您的构建过程中。

But you need to publish your site and run IIS site/virtual app from that folder, not the project folder. 但您需要发布您的站点并从该文件夹而不是项目文件夹运行IIS站点/虚拟应用程序。

In the example below, we're publishing the site to a folder "published-site", relative to the sln location, but only for a Debug build. 在下面的示例中,我们将站点发布到相对于sln位置的文件夹“published-site”,但仅用于Debug构建。

I'm also assuming that the build process takes longer than it takes to spin down the process. 我还假设构建过程花费的时间比关闭过程所花费的时间要长。

  1. Create a PreBuild target that creates the app_offline.htm file in the publish folder. 创建PreBuild目标,在publish文件夹中创建app_offline.htm文件。

     <Target Name="PreBuild" BeforeTargets="PreBuildEvent" Condition="'$(Configuration)'=='Debug'"> <Exec Command="IF EXIST &quot;$(SolutionDir)published-site&quot; (&#xD;&#xA; echo. 2&gt;&quot;$(SolutionDir)published-site\\app_offline.htm&quot;&#xD;&#xA;)" /> </Target> 
  2. Create a PostBuild target that deletes the app_offline.htm file and then calls dotnet publish. 创建一个PostBuild目标,删除app_offline.htm文件,然后调用dotnet publish。

     <Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="'$(Configuration)'=='Debug'"> <Exec Command="IF EXIST &quot;$(SolutionDir)published-site\\app_offline.htm&quot; (&#xD;&#xA; del &quot;$(SolutionDir)published-site\\app_offline.htm&quot;&#xD;&#xA;)&#xD;&#xA;&#xD;&#xA;dotnet publish --no-build --no-restore &quot;$(ProjectPath)&quot; -c $(ConfigurationName) -o &quot;$(SolutionDir)published-site&quot;" /> </Target> 

Without deploy/publish it is not possible. 没有部署/发布,就不可能。 But you could consider using auto deployment as a workaround. 但您可以考虑使用自动部署作为解决方法。 For instance you could use some extensions like Auto Deploy , or by extending the MSBuild process . 例如,您可以使用Auto Deploy等扩展,或者扩展MSBuild进程

you need Install the ASP.NET Core Module/Hosting Bundle,and Confirm the process model identity has the proper permissions,more info https://docs.microsoft.com/en-us/aspnet/core/tutorials/publish-to-iis?view=aspnetcore-6.0&tabs=visual-studio您需要安装 ASP.NET 核心模块/托管捆绑包,并确认进程 model 身份具有适当的权限,更多信息Z5E056C500A1C4B6A7110B50D807BADEus5Z://docs/tutorials.com/en-lishus5Z/docs/tutorials.com/en-lishus5Z视图=aspnetcore-6.0&tabs=visual-studio

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

相关问题 在非IIS环境中部署/发布ASP.NET Web服务 - Deploy/Publish ASP.NET webservice in non IIS environment 无法在 Asp.NET CORE 中将我的环境变量设置为开发 - Cannot set my Environment Variable to Development in Asp.NET CORE ASP.NET Core 2.1 App在本地构建和运行成功,但无法通过Web Deploy发布到IIS - ASP.NET Core 2.1 App succeeds in Building and Running Locally but fails to Publish to IIS via Web Deploy IIS 发布 ASP.NET 核心应用程序而不关闭 IIS 网站 - IIS Publish ASP.NET Core App Without Bringing Down IIS Website 如何在IIS中部署我的asp.net项目? - How to deploy my asp.net project in IIS? ASP.NET 核心 api 项目 3.1 发布在 IIS - ASP.NET Core api project 3.1 publish on IIS 如何将网站从IIS托管站点更改为ASP.Net Development Server托管站点? - How do I change a web site from an IIS hosted site to an ASP.Net Development Server hosted site? 如何使用.net Framework应用程序将Asp.Net Core部署到IIS - How to deploy Asp.Net Core using .net Framework application to IIS 如何附加针对以net47为目标的IIS中运行的ASP.NET Core网站的调试器? - How to attach debugger for ASP.NET Core web site running in IIS targeting net47? 如何在IIS 5.1上发布ASP.NET 3.5? - How to publish ASP.NET 3.5 on IIS 5.1?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM