如何使用AspNetCoreModuleV2设置VS 2017?

时间:2019-10-26 21:28:30

标签: c# asp.net-core iis .net-core

我正在尝试将现有应用程序从2.1升级到2.2。与此同时,我正在尝试将IIS的AspNetCore托管模块升级到AspNetCoreModuleV2

这是我的web.config目前的样子:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <remove name="WebDAV" />
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\MyApp.dll"
                  stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout"
                  hostingModel="InProcess">
      </aspNetCore>
      <modules>
        <remove name="WebDAVModule" />
      </modules>
    </system.webServer>
  </location>
</configuration>

在使用AspNetCoreModule之前,已经设置了我的AppPool和应用程序。该应用程序的物理路径指向web.config所在项目的根目录:

C:\DEV\MyApp

现在,当我进行健康检查时出现以下错误:

HTTP Error 500.0 - ANCM In-Process Handler Load Failure 
Common causes of this issue: 
    The specified version of Microsoft.NetCore.App or Microsoft.AspNetCore.App was not found. 
    The in process request handler, Microsoft.AspNetCore.Server.IIS, was not referenced in the application. 
    ANCM could not find dotnet. 

Troubleshooting steps: 
    Check the system event log for error messages 
    Enable logging the application process' stdout messages 
    Attach a debugger to the application process and inspect 

当我在web.config中打开标准输出日志时,我唯一得到的是:

Failed to initialize CoreCLR, HRESULT: 0x80131022

我想知道它是否在应用程序指向的物理路径中寻找该dll,而不是bin\Debug\netcoreapp2.2\MyApp.dll

如果我更改arguments指向该完整路径,它仍然会失败,我认为是因为该目录中的所有内容都是我自己的DLL,并且没有web.config或系统依赖性。

如果我发布(即dotnet publish),它将在输出目录中创建一个publish目录,然后如果我将物理路径指向那个目录,则该页面有效,因为它具有所需的所有位。

我应该如何设置它,以便我可以简单地在VS中进行构建并进行更改更新,以及使用相同的web.config进行干净发布?

理想情况下,我可以重新构建,而无需发布。不知道我在做什么错。不同的帮助文章给出了不同的说明。

更多信息:

  • 使用VS 2017(15.9.17)
  • dotnet --list-sdks产生:
2.1.509 [C:\Program Files\dotnet\sdk]
2.2.107 [C:\Program Files\dotnet\sdk]
2.2.109 [C:\Program Files\dotnet\sdk]
2.2.402 [C:\Program Files\dotnet\sdk]
  • dotnet --list-runtimes产生:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

更新1 看起来VS 2017并未编译一些相关的.NET Standard / Core程序集并将其包括在输出中。我在ASNM日志中看到此错误:

Error:
  An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
    package: 'AWS.Logger.Core', version: '1.5.1'
    path: 'lib/netstandard2.0/AWS.Logger.Core.dll'

更新2 我能够打开更多日志记录。查看以下结果:

[aspnetcorev2.dll] Initializing logs for 'C:\Program Files\IIS\Asp.Net Core Module\V2\aspnetcorev2.dll'. Process Id: 17420.. File Version: 12.2.19225.7. Description: IIS ASP.NET Core Module V2. Commit: be0a4a7f4cf06cbd6ec714bd1d9afee6bdb040a8.
[aspnetcorev2.dll] Resolving hostfxr parameters for application: 'dotnet' arguments: 'exec .\MyApp.dll' path: 'C:\DEV\MyApp\'
[aspnetcorev2.dll] Known dotnet.exe location: ''
[aspnetcorev2.dll] Process path 'dotnet.exe' is dotnet, treating application as portable
[aspnetcorev2.dll] Resolving absolute path to dotnet.exe from 'dotnet.exe'
[aspnetcorev2.dll] Invoking where.exe to find dotnet.exe
[aspnetcorev2.dll] where.exe invocation returned: 'C:\Program Files (x86)\dotnet\dotnet.exe
C:\Program Files\dotnet\dotnet.exe
'
[aspnetcorev2.dll] Current process bitness type detected as isX64=1
[aspnetcorev2.dll] Processing entry 'C:\Program Files (x86)\dotnet\dotnet.exe'
[aspnetcorev2.dll] Binary type 0
[aspnetcorev2.dll] Processing entry 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Binary type 6
[aspnetcorev2.dll] Found dotnet.exe via where.exe invocation at 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Resolving absolute path to hostfxr.dll from 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] hostfxr.dll located at 'C:\Program Files\dotnet\host\fxr\2.2.7\hostfxr.dll'
[aspnetcorev2.dll] Converted argument '.\MyApp.dll' to 'C:\DEV\MyApp\MyApp.dll'
[aspnetcorev2.dll] Parsed hostfxr options: dotnet location: 'C:\Program Files\dotnet\dotnet.exe' hostfxr path: 'C:\Program Files\dotnet\host\fxr\2.2.7\hostfxr.dll' arguments:
[aspnetcorev2.dll] Argument[0] = 'C:\Program Files\dotnet\dotnet.exe'
[aspnetcorev2.dll] Argument[1] = 'exec'
[aspnetcorev2.dll] Argument[2] = 'C:\DEV\MyApp\MyApp.dll'
[aspnetcorev2.dll] Event Log: 'Invoking hostfxr to find the inprocess request handler failed without finding any native dependencies. This most likely means the app is misconfigured, please check the versions of Microsoft.NetCore.App and Microsoft.AspNetCore.App that are targeted by the application and are installed on the machine.' 
End Event Log Message.
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at d:\b\w\da744fbcc13abce\src\servers\iis\aspnetcoremodulev2\aspnetcore\handlerresolver.cpp:80 
[aspnetcorev2.dll] Event Log: 'Could not find inprocess request handler. Captured output from invoking hostfxr: Error:
  An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
    package: 'AWS.Logger.Core', version: '1.5.1'
    path: 'lib/netstandard2.0/AWS.Logger.Core.dll'
' 
End Event Log Message.
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at d:\b\w\da744fbcc13abce\src\servers\iis\aspnetcoremodulev2\aspnetcore\handlerresolver.cpp:153 
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at d:\b\w\da744fbcc13abce\src\servers\iis\aspnetcoremodulev2\aspnetcore\applicationinfo.cpp:136 
[aspnetcorev2.dll] Failed HRESULT returned: 0x8000ffff at d:\b\w\da744fbcc13abce\src\servers\iis\aspnetcoremodulev2\aspnetcore\applicationinfo.cpp:91 
[aspnetcorev2.dll] Event Log: 'Failed to start application '/LM/W3SVC/1/ROOT/myapp', ErrorCode '0x8000ffff'.' 
End Event Log Message.

更新3 如果删除以前手动创建的应用程序池和站点,然后在构建时让Visual Studio为我创建它,我似乎会更进一步。它必须设置一些额外的权限才能进入nuget包所在的目录

1 个答案:

答案 0 :(得分:0)

因此,这似乎是由于应用程序池正在使用ApplicationPoolIdentity而导致的,它无法访问所需的nuget软件包。

该用户(IIS AppPool\APP_POOL_NAME)必须被授予对以下目录的访问权限:

  • C:\Users\YOUR_USER\.nuget\packages(只读)
  • 您的应用/虚拟目录的物理路径
  • 就我而言,还需要访问C:\Windows\TEMP

一些记录在这里:

https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/iis/?view=aspnetcore-2.2#application-pool-identity

可能需要更多路径。我不确定VS在IIS中自动为您配置应用程序池时在做什么。如果我知道了,我会在这里发布。

或者,将应用程序池的标识更改为LocalSystem,或者将其更改为具有必要权限的用户。这对我来说是更简单的方法。