简体   繁体   English

在T4模板中获取ASPNETCORE_ENVIRONMENT?

[英]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.

相关问题 如何为控制台应用程序设置 ASPNETCORE_ENVIRONMENT? - How to set ASPNETCORE_ENVIRONMENT for console application? 创建新的ASPNETCORE_ENVIRONMENT进行开发 - Create new ASPNETCORE_ENVIRONMENT for Development 如何在运行时设置 ASPNETCORE_ENVIRONMENT 变量 - How to set ASPNETCORE_ENVIRONMENT variable at runtime 是否可以重命名 ASPNETCORE_ENVIRONMENT 变量? - Is it possible to rename ASPNETCORE_ENVIRONMENT variable? 在构建配置中设置aspnetcore_environment - Set aspnetcore_environment within build configuration ef core 在更新数据库期间不使用 AS.NETCORE_ENVIRONMENT - ef core doesn't use ASPNETCORE_ENVIRONMENT during update-database 如何在 AzureDevops 中为 Dockerfile 设置环境变量(ASPNETCORE_ENVIRONMENT)? - How to set environment variables (ASPNETCORE_ENVIRONMENT) in AzureDevops for Dockerfile? AZURE_FUNCTIONS_ENVIRONMENT 与 ASPNETCORE_ENVIRONMENT - AZURE_FUNCTIONS_ENVIRONMENT vs ASPNETCORE_ENVIRONMENT 使用 ASPNETCORE_ENVIRONMENT 覆盖 Azure 上的 appsettings.json - Override appsettings.json on Azure using ASPNETCORE_ENVIRONMENT 为什么 ChartJs.Blazor 有错误(更改 ASPNETCORE_ENVIRONMENT) - Why is there an error in ChartJs.Blazor (change in ASPNETCORE_ENVIRONMENT)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM