将 .Net Core 作为 DLL 部署到 IIS - 无法使用命令行“"dotnet" site.dll”启动进程

Deploy .Net Core as DLL to IIS - Failed to start process with commandline '"dotnet" site.dll'

我有一个针对 net461 框架的 .Net Core Web 应用程序。它最初生成一个 .EXE 并且在部署到 IIS 时工作正常。我想改成便携app,所以我在ProjectJson中改了"buildOptions"如下:

"buildOptions": {
  "emitEntryPoint": false,
  "preserveCompilationContext": true,
  "debugType": "portable" 
},

现在,当我编译时,我得到了一个 DLL,它 运行 在 IIS Express 中很好,但是当我发布到 IIS 并将 web.config aspnetcore 元素更改为:

  <aspNetCore processPath="dotnet" arguments=".\myWebApp.dll" 
            stdoutLogEnabled="false" 
            stdoutLogFile=".\logs\stdout" 
            forwardWindowsAuthToken="false" />

项目无法 运行,我在应用程序事件日志中看到 "Failed to start process with commandline '"dotnet" MyWebApp.dll', ErrorCode = '0x80004005'"。

尝试从命令行使用 "dotnet mywebapp.dll" 运行 结果:

A fatal error was encountered. The library 'hostpolicy.dll' required to   
execute the application was not found in 'C:\inetpub\wwwroot\ETimeCore2'.

所以我找到并复制了hostpolicy.dll到目录下,现在得到:

Could not resolve CoreCLR path. For more details, enable tracing by setting 
CORE HOST_TRACE environment variable to 1

我确实将 CORE HOST_TRACE 设置为 1,并得到了所有正在加载的 dll 的详细响应,最后只有一个错误(上图),因此它没有增加任何价值。

知道我做错了什么吗??我更喜欢 DLL 而不是 EXE,因为要在 .EXE 时发布更改,您必须先回收应用程序池,这真的很痛苦。

如果禁用 "emitEntryPoint",则无法使用 dotnet mywebapp.dll

emitEntryPoint 表示该项目是控制台应用程序还是库。来自 sources

if (framework.IsDesktop() && compilerOptions.EmitEntryPoint.GetValueOrDefault())
{
   OutputExtension = FileNameSuffixes.DotNet.Exe;
}

在您的情况下,framework.IsDesktop() 是正确的,因为您的目标框架是 net461,即 .NET Framework,而不是 .NET Core。如果启用 emitEntryPoint.

,这就是您获得 .exe 作为输出的方式

实际上错误 "The library 'hostpolicy.dll' required to execute the application was not found in " 现在意味着以下内容(参见 http://github.com/dotnet/cli/issues/2859 问题):

dotnet.exe cannot find the entry point in mywebapp.dll