简体   繁体   English

我可以在.settings文件中使用环境变量吗?

[英]Can I use environment variables in a .settings file?

.NET allows me to create and access values that are persistent between sessions. .NET允许我创建和访问在会话之间保持不变的值。
Is it possible to use environment variables such as %WINDIR% , %APPDATA% and others? 是否可以使用%WINDIR%%APPDATA%等环境变量?
If so, how would I go about doing this? 如果是这样,我将如何去做?

If you have this in the config: 如果您在配置中有这个:

 <appSettings>
   <add key="SomePath" value="%TEMP%"/>
 </appSettings>

Then from code you'd do something like: 然后,从代码中您将执行以下操作:

string path = ConfigurationManager.AppSettings["SomePath"];
string fullPath = System.Environment.ExpandEnvironmentVariables(path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用 json 应用程序设置而不是系统环境变量 - Use json app settings instead of system environment variables 无法使用环境变量覆盖 appsettings.json 设置 - can't override appsettings.json settings with environment variables 如何在应用中心的 Xamarin.Forms 中使用设置环境变量 - How can I use set Environment Variables in Xamarin.Forms from App Center 我可以在 Visual Studio 命令行参数中使用用户的环境变量吗? - Can I use user's environment variables in visual studio command line arguments? 应用程序设置文件中的环境变量 - Environment Variable in Application Settings File 我如何在设置中使用字符串文件路径,以便我可以在我的代码中使用该路径 - How do i use a string file path in settings so i can get that path useable in my code 我可以跟踪ConfigurationManager设置的使用 - Can I track the use of ConfigurationManager settings 将外部log4net配置文件与环境变量一起使用 - Use external log4net configuration file with environment variables 您可以使用 IConfiguration.GetSection() 读取环境变量吗? - Can you use IConfiguration.GetSection() to read environment variables? 如何使用config.json为Visual Studio 2015 / DNX项目设置特定于环境的变量? - How can I use config.json to set environment-specific variables for a Visual Studio 2015/DNX project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM