- A+
开发过程中经常要发布一个版本到测试服上给测试人员测试,可能需要直接输出错误信息,需要设置环境变量为Development,如果是IIS可以通过设置IIS环境变量,见下面这篇文章
https://blog.csdn.net/lilinoscar/article/details/108362211
如果是linux系统就比较麻烦,可以设置临时环境变量,或者临时环境变量
https://www.cnblogs.com/lcxiao/p/11361052.html
但是改上述配置都比较麻烦,临时变量每次都得重新设置。
可以通过命令行直接传一个参数到系统入口,.Net3.1之前可以在 Main(string[] args)接受参数判断
.Net6可以直接这么写
WebApplicationBuilder builder;
if (args.Contains("Development"))
{
builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
Args = args,
EnvironmentName = Environments.Development
});
}
else
{
//默认
builder = WebApplication.CreateBuilder(args);
}
通过命令行启动:
dotnet aspnetcore.dll --urls http://localhost:7001 Development
配置supervisor:
command=dotnet aspnetcore.dll --urls http://localhost:7001 Development
docker 中:
ENTRYPOINT ["dotnet", "aspnetcore.dll", "--urls", "http://localhost:7001","Development"]