【问题标题】:How do I setup VS 2017 with AspNetCoreModuleV2?如何使用 AspNetCoreModuleV2 设置 VS 2017?
【发布时间】:2019-10-26 21:28:30
【问题描述】:

我正在尝试将现有应用从 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>

我的 AppPool 和应用程序在使用 AspNetCoreModule 之前已经设置好了。应用程序的物理路径指向 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 中打开 stdout 日志记录时,我得到的唯一结果是:

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 包所在的目录

【问题讨论】:

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


    【解决方案1】:

    看来这可能是因为应用程序池正在使用 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 之类的东西,或具有必要权限的用户。这对我来说更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-25
      • 1970-01-01
      • 2017-08-28
      • 1970-01-01
      • 1970-01-01
      • 2019-06-02
      • 1970-01-01
      相关资源
      最近更新 更多