当我调试 React .NET 项目时,会打开两个终端。一种用于 React,一种用于 .NET 后端。 现在,当我将应用程序发布到文件夹时,我会得到一个 wwwroot 和运行时文件夹、一大堆 dll 和一个 exe 文件。
所以我知道一个终端不再出现,因为 React 应用程序现在只是一个像普通 html 网站一样的文件夹。
当我调试网站时,我得到:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://localhost:7291
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5026
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\Users\renek\source\ReactNet\ReactNet
info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
No SPA development server running at https://localhost:44411 found.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware[0]
SPA proxy is not ready. Returning temporary landing page.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyMiddleware[0]
SPA proxy is ready. Redirecting to https://localhost:44411.
info: Microsoft.AspNetCore.SpaProxy.SpaProxyLaunchManager[0]
SPA development server running at 'https://localhost:44411'
现在,当我将项目发布到我的 VPS 并运行 exe 时:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5000
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\inetpub
有人可以解释一下我如何才能获得相同的设置吗?
到目前为止我尝试过的:
{
"profiles": {
"ReactNet": {
"commandName": "Project",
"launchBrowser": false, // True originally
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production", // Development originally
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
},
"applicationUrl": "https://localhost:7291;http://localhost:5026"
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": false, // True originally
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production", // Development originally
"ASPNETCORE_HOSTINGSTARTUPASSEMBLIES": "Microsoft.AspNetCore.SpaProxy"
}
}
},
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:32385",
"sslPort": 44344
}
}
}
是的,我知道编辑 launchSettings 仅用于开发。这是我实际上要发布的第一个项目,所以不要责怪我不知道具体如何做。
如果您想在运行.exe文件时保留端口,您可以尝试:
var builder = WebApplication.CreateBuilder(args);
builder.WebHost.UseUrls("http://localhost:5026;https://localhost:7291");
这是文档相关
结果: