VS 2017(甚至更早版本),当您导航到Debug -> <ProjectName> Properties -> Debug tab
时,您可以添加您的程序可以通过Environment.GetEnvironmentVariable("var_name")
使用的环境变量。
当为变量使用单行值时,这非常有用,但具有字符限制。
我有一些程序依赖于在部署应用程序时在其运行的系统上定义的多行变量,例如:
string rsaPrivateKey = Environment.GetEnvironmentVariable("PRIVATE_KEY");
但是,这是一个RSA私钥,那些是多线的。我希望能够在我的工作站上调试应用程序,并在我的VS 2017中声明这些环境变量,而不是硬编码,以便使用这些变量的逻辑实际上可以成功。
有没有人碰到这个,你能提供一个替代方案来声明多行环境变量用于调试目的而不会提交给源代码吗?
使用:
string rsaPrivateKey;
string rsaPrivateKeyPath = Environment.GetEnvironmentVariable("PRIVATE_KEY_Path");
using (StreamReader sr = File.OpenText(rsaPrivateKeyPath ))
{
rsaPrivateKey = sr.ReadToEnd();
}