c# - 为什么在通过 dotnet CLI 运行 ASP.NET Core 应用程序时看到项目目录名称而不是 dotnet(进程外)?

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

我创建了一个名为 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 运行应用程序时,它会显示

EmployeeManagement

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

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

iisexpress

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

最佳答案

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

如果您直接使用 dotnet bin\netcoreapp3.1\EmployeeManagement.dll 或在 csproj 中设置以下内容,您应该会看到不同之处:

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

关于c# - 为什么在通过 dotnet CLI 运行 ASP.NET Core 应用程序时看到项目目录名称而不是 dotnet(进程外)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62276413/

相关文章:

c# - 等同于 .NET Core 的 App.config 转换?

C# 屏幕流程序

c# - 如何按位操作十六进制值?

c# - 通过反射获取组件

http - 为什么我看不到 HttpUtility.ParseQueryString 方法?

c# - 在 Redis 中存储和使用配置文件的最佳方式?

c# - 在c#中使用smtp在同一线程中为gmail发送电子邮件

c# - 在 ASP.NET Core 中访问当前的 HttpContext

asp.net-core - ASP.NET 5 和 DocumentDb

authentication - .NET Core WebAPI 永久 token 认证