嘗試將您的項目首先上傳到blob存儲是一個不錯的主意,但不幸的是,這是Visual Studio在幕後爲您做的。正如其他地方已經指出的那樣,大多數部署時間不是上傳本身,而是停止和啓動所有更新域。
如果你只是在一個開發環境中運行這個網站,那麼我知道加快它的唯一方法就是隻運行一個實例。如果這是現場環境,那麼......對不起,我認爲你運氣不好。
爲了不必部署到雲端來測試微小的更改,我發現的工作相當好,就是設計站點,以便在本地IIS中運行,就像任何其他MVC站點一樣。
這項工作的最大障礙是您在雲配置中的設置。我們解決這個問題的方法是複製您的雲配置中的所有設置,並將它們放入appSettings中的web.config中。然後,而不是使用RoleEnvironment.GetConfigurationSettingValue()
創建您調用的包裝類。這個包裝類檢查RoleEnvironment.IsAvailable
以查看它是否在Azure結構中運行,如果是,則調用上述通常的配置功能,如果不是,則調用WebConfigurationManager.AppSettings[]
。
有,你要做到讓周圍其中希望你可以從下面的代碼找出配置設置更改事件一些其他的東西:
減少需要
public class SmartConfigurationManager
{
private static bool _addConfigChangeEvents;
private static string _configName;
private static Func<string, bool> _configSetter;
public static bool AddConfigChangeEvents
{
get { return _addConfigChangeEvents; }
set
{
_addConfigChangeEvents = value;
if (value)
{
RoleEnvironment.Changing += RoleEnvironmentChanging;
}
else
{
RoleEnvironment.Changing -= RoleEnvironmentChanging;
}
}
}
public static string Setting(string configName)
{
if (RoleEnvironment.IsAvailable)
{
return RoleEnvironment.GetConfigurationSettingValue(configName);
}
return WebConfigurationManager.AppSettings[configName];
}
public static Action<string, Func<string, bool>> GetConfigurationSettingPublisher()
{
if (RoleEnvironment.IsAvailable)
{
return AzureSettingsGet;
}
return WebAppSettingsGet;
}
public static void WebAppSettingsGet(string configName, Func<string, bool> configSetter)
{
configSetter(WebConfigurationManager.AppSettings[configName]);
}
public static void AzureSettingsGet(string configName, Func<string, bool> configSetter)
{
// We have to store these to be used in the RoleEnvironment Changed handler
_configName = configName;
_configSetter = configSetter;
// Provide the configSetter with the initial value
configSetter(RoleEnvironment.GetConfigurationSettingValue(configName));
if (AddConfigChangeEvents)
{
RoleEnvironment.Changed += RoleEnvironmentChanged;
}
}
private static void RoleEnvironmentChanged(object anotherSender, RoleEnvironmentChangedEventArgs arg)
{
if ((arg.Changes.OfType<RoleEnvironmentConfigurationSettingChange>().Any(change => change.ConfigurationSettingName == _configName)))
{
if ((_configSetter(RoleEnvironment.GetConfigurationSettingValue(_configName))))
{
RoleEnvironment.RequestRecycle();
}
}
}
private static void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
// If a configuration setting is changing
if ((e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)))
{
// Set e.Cancel to true to restart this role instance
e.Cancel = true;
}
}
}
我開始越來越喜歡你的方法。但有一個問題:你是否將所有的js文件,圖像等與de項目分開(在VS中),或者只是將它們配置爲不是發佈的包的一部分? – 2010-12-21 22:30:39
我已決定採用這個答案,因爲它似乎是最實際的,當最終接受完全部署將是一個緩慢的過程,無論如何。 – 2010-12-31 10:38:40
http://blogs.msdn.com/b/jnak/archive/2010/10/29/rapid-developer-deploy-to-azure.aspx – 2011-02-04 22:11:14