c# - 在 Visual Studio 中管理本地与云开发配置设置的选项

标签 c# .net azure configuration

我们将来将使用 Windows Azure 网站来满足我们的基本托管需求。由于云与本地有非常具体的配置设置,您如何管理这些设置?以下面为例:

本地开发服务器:

string path = AppSettings["StoragePath"];

<add key="StoragePath" value="c:\temp" />

Windows Azure:

string path = AppSettings["StoragePath"];

<add key="StoragePath" value="xyz" />

您是否在每次发布之前手动更改配置文件中的 StoragePath 或者代码中是否有可以执行的操作,例如:

<add key="LocalStoragePath" value="c:\temp" />
<add key="BlobStoragePath" value="xyz" />    

string path;
if (Azure)
{
   path = AppSettings["BlobStoragePath"];
}
else
{
   path = AppSettings["LocalStoragePath"];
}

如果后者可以,我如何确定环境是否是Windows Azure?

最佳答案

我通常会创建一个新的构建配置(称为 Azure)。

然后在 web.config 中创建您的 key ..

<add key="LocalStoragePath" value="c:\blah" />
<add key="AzureStoragePath" value="xyz" />

在你的代码中写入:

#if CONFIG == "Azure"
  public const String storageKey = "AzureStoragePath";
#endif CONFIG == "Debug"
  public const String storageKey = "LocalStoragePath";
#endif

并使用它:

String path = AppSettings[storageKey];

关于c# - 在 Visual Studio 中管理本地与云开发配置设置的选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14555243/

相关文章:

c# - 如何在 protected 中实现接口(interface)成员?

asp.net-mvc-4 - MVC Azure AD 授权角色

C# 根据日期(月)和组拆分查询结果

c# - 如何计算上传大文件的最佳 block 大小

c# - 单击相同选择时通过鼠标单击切换 CheckedListBox 项目检查状态时的奇怪行为

.net - Visual Studio 2010 Professional 和 Team Foundation Server 2012 Express

Azure 媒体服务或用于 STA 视频存储的简单存储帐户

azure - 在azure中使用terraform创建资源组: Cannot find resource group directly after creating it

c# - 使用 foreach 遍历 IEnumerable 会跳过一些元素

c# - 将面板添加到用户控件时出错 : Object reference not set to an instance of an object