我在 ASP.NET 核心项目中有 React 应用程序 运行ning 并且想同时 运行

I have React application running in ASP.NET Core project and want to run both at the same time

我在 Visual Studio 中创建了一个默认的 React/.NET Core 项目,我的 launchSettings.json 看起来像这样:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:28087",
      "sslPort": 44341
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "TTMApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "applicationUrl": "https://localhost:5001;http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

如何在 port 44341 同时 运行 port 5001 api 服务器和 React 服务器?如果我键入 dotnet-run 它 运行 是 5001 应用程序,但是如果我在 Visual Studio 中单击“开始”或“IIS Express”,它 运行 是 44341 React app.有没有办法同时 运行 以便我可以测试对位于 5001 端口的 API 的 React 查询?

我已经 运行 使用 Node React,你可以同时使用 运行 两者,我只是不确定如何在 .Net Core 中实现这一点而不创建单独的React 和 API 的项目。我只有来自 Visual Studio 的 OOB React 项目,看起来它在一个项目中创建了所有内容,尽管 React 代码在一个端口而 API 在另一个端口。

打开Startup.cs看看configure方法代码

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";

    if (env.IsDevelopment())
    {
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
});

你有这个配置吗? 这样,dotnet run命令在后台运行react开发