【发布时间】:2020-02-26 12:22:50
【问题描述】:
当我使用dotnet WebApplicationLaunchProfile.dll 运行 ASP.Net Core 应用程序时,请帮我指定配置文件名称
我使用这个简短的表格只是为了有可能在 VS 之外运行项目并检查它是如何工作的。
我知道我可以使用dotnet run --launch-profile testProfileName,但是它需要.csproj 和.cs 源文件可用。我想避免复制源代码文件并使用已编译的程序集。我的流程是:
- 使用
dotnet build构建 - 将构建结果(
bin\Debug文件夹内容)复制到单独的文件夹中 - 使用
dotnet WebApplicationLaunchProfile.dll表单启动 dll 以使用正确的配置文件名称
但问题是
当应用程序通过 dotnet run 启动时,使用第一个带有 "commandName": "Project" 的配置文件
如果项目使用dotnet dll 命令执行,则规则from the documentation is not applied。显然不应该应用它,因为我没有使用dotnet run 命令。
但是我想以某种方式指定个人资料名称。
我已经从 VS 模板创建了新的 ASP.Net Core 项目并更新了 launchSettings.json 文件如下:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
...
"profiles": {
...
"WebApplicationLaunchProfile": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:4430;http://localhost:8080",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
我已经调整了profiles:WebApplicationLaunchProfile:applicationUrl 值并替换了 5000 和 5001 端口,如您所见。
项目已上传至https://github.com/oleksabor/curly-broccoli,仅供快速参考。
但是除了launchSettings.json之外没有任何修改。
我可以使用VS或dotnet run命令启动应用程序没有任何问题
但是,当使用dotnet dll 命令执行应用程序时出现错误,如下所示:
C:\projects\WebApplicationLaunchProfile\bin\Debug\netcoreapp3.1>dotnet WebApplicationLaunchProfile.dll
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address http://127.0.0.1:5000: address already in use.
我占用了 5000 端口,想使用 4430 代替。
dotnet WebApplicationLaunchProfile.dll --launch-profile WebApplicationLaunchProfile不起作用(错误相同)
是否可以使用dotnet dll 设置配置文件名称?
【问题讨论】:
标签: c# asp.net-core