[英]Get ASPNETCORE_ENVIRONMENT in T4 Template?
Within a T4 Template, I'm having trouble getting the value for ASPNETCORE_ENVIRONMENT in my project, currently set to "Development". 在T4模板中,我很难在我的项目(目前设置为“开发”)中获取ASPNETCORE_ENVIRONMENT的值。
string env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
This appears to run fine, but pulls back null. 这似乎运行良好,但返回空值。
In my understanding, T4 is always Design Time -> Developement Environment. 以我的理解,T4始终是“设计时->开发环境”。 Therefore I am not sure, what exactly you are trying to do.
因此,我不确定您到底想做什么。
The environment variable is set in Properties/launchSettings.json and will be loaded if you start your project via Visual Studio: 环境变量在Properties / launchSettings.json中设置,如果通过Visual Studio启动项目,则将加载该环境变量:
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Of course, T4 doesn't load the Variables configured in launchSettings.json , since it is not the application itself. 当然,T4不会加载在launchSettings.json中配置的变量,因为它不是应用程序本身。 You could parse the file manualy, or set the environment variable yourself in Windows or probably in MSBuild .
您可以手动解析文件,也可以在Windows或MSBuild中自行设置环境变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.