我們曾嘗試沃爾瑪的做法幾乎解決了這個問題,但我們遇到了與點擊一次部署,請參閱我的沃爾瑪的答覆意見的問題。
我們目前正在使用的解決方案是在此張貼提示條件編譯:
http://www.codeproject.com/Articles/451734/Visual-Studio-Use-Conditional-Compilation-to-Contr
的優點是,除了有一次點擊,完美的工作,就是你不必調整VS項目文件或使用任何第三方組件。缺點是如果您想添加/更改端點,則需要更新源代碼。
我們所做的是將新的.setttings文件添加到項目中。這並不是強制性的,但我們認爲將終端配置保存在單獨的設置文件中是個好主意,因爲這個文件必須稍微調整。它的調整,以使用條件編譯基於對編譯啓用配置,使正確的端點:
public ServiceSettings() {
// // To add event handlers for saving and changing settings, uncomment the lines below:
//
// this.SettingChanging += this.SettingChangingEventHandler;
//
// this.SettingsSaving += this.SettingsSavingEventHandler;
//
// Each method corrsponds to a build version. We call all four methods, because
// the conditional compilation will only compile the one indicated:
this.SetLocalApplicationSettings();
this.SetAS12ApplicationSettings();
}
[Conditional("LOCAL")]
private void SetLocalApplicationSettings()
{
this["LoginAddress"] = "https://localhost/services/loginservice";
this["SettingsAddress"] = "https://localhost/services/settingsservice";
}
[Conditional("EXAMPLE")]
private void SetAS12ApplicationSettings()
{
this["LoginAddress"] = "https://example.com/services/loginservice";
this["SettingsAddress"] = "https://example.com/services/settingsservice";
}
在VS,我們創建一個配置每個端點和定義生成選項卡上的適當條件編譯符號,即本地或例。
我們還更新使用VS生成的使用在設置中定義的端點的WS客戶端類的代碼文件:
var client = new SettingsServiceClient("SettingsServiceImplPort",
ServiceSettings.Default.SettingsAddress);
在App.config我們只是保留了默認配置(本地主機)和綁定配置保持VS幸福:
<system.serviceModel>
<bindings>
<customBinding>
<binding name="SettingsServiceImplServiceSoapBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
<binding name="LoginServiceImplServiceSoapBinding">
<textMessageEncoding messageVersion="Soap12" />
<httpsTransport />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="https://localhost/services/settingsservice"
binding="customBinding" bindingConfiguration="SettingsServiceImplServiceSoapBinding"
contract="SettingsServiceReference.SettingsService" name="SettingsServiceImplPort" />
<endpoint address="https://localhost/services/loginservice"
binding="customBinding" bindingConfiguration="LoginServiceImplServiceSoapBinding"
contract="LoginServiceReference.LoginService" name="LoginServiceImplPort" />
</client>
</system.serviceModel>
<applicationSettings>
<ConfigurationTest.ServiceSettings>
<setting name="SettingsAddress" serializeAs="String">
<value>https://localhost/services/settingsservice</value>
</setting>
<setting name="LoginAddress" serializeAs="String">
<value>https://localhost/services/loginservice</value>
</setting>
</ConfigurationTest.ServiceSettings>
</applicationSettings>
沒有爲「有條件的ClickOnce部署爲構建配置」,可能會感興趣的MSDN開發中心的相關討論。 http://social.msdn.microsoft.com/Forums/en/winformssetup/thread/71933eaf-4a21-4923-bccd-19dd851dc7c3 –