【问题标题】:Why do I see project directory name instead of dotnet(out-of-process) while running ASP.NET Core app through dotnet CLI?为什么在通过 dotnet CLI 运行 ASP.NET Core 应用程序时看到项目目录名称而不是 dotnet(进程外)?
【发布时间】:2020-06-09 16:32:33
【问题描述】:

我创建了一个名为 EmployeeManagement 的示例 ASP.NET Core 应用程序。该应用已明确配置为进程外托管,如下所示,

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

此应用程序的主要目标是显示当前正在运行的进程名称。

public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
  ...

  app.UseEndpoints(endpoints =>
  {
   endpoints.MapGet("/", async context =>
   {
      await context.Response.WriteAsync(System.Diagnostics.Process.GetCurrentProcess().ProcessName);
   });
  });
}

当我使用 dotnet CLI 运行应用程序时,它会显示

员工管理

为什么它不显示 dotnet 作为进程名称?当我们使用 dotnet CLI 运行应用程序时,应用程序可能在 Kestrel 服务器中托管和运行。所以,我假设 dotnet.exe 应该是托管进程。

如果应用程序配置为 InProcess 托管模式。它显示

iisexpress

作为进程名称。目标框架为.NET Core 3.1版本。

【问题讨论】:

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


    【解决方案1】:

    从 ASP.NET Core 3.0 开始,会为您当前正在构建的平台自动生成一个主机 exe(“apphost”)(由于其签名/公证要求,macOS 除外),因此您的 EmployeeManagement.exe bin 文件夹将用于运行 .NET Core 运行时。

    如果你直接使用dotnet bin\netcoreapp3.1\EmployeeManagement.dll或者在csproj中设置如下应该会看到不同:

    <PropertyGroup>
      <UseAppHost>False</UseAppHost>
    </PropertyGroup>
    

    【讨论】:

      猜你喜欢
      • 2021-07-06
      • 1970-01-01
      • 1970-01-01
      • 2017-10-11
      • 2016-11-15
      • 2019-10-14
      • 2016-08-02
      • 2021-07-19
      • 1970-01-01
      相关资源
      最近更新 更多