2012-05-16 30 views

回答

1

我假設你有一個團隊,並且你的一些團隊成員無意中檢查了這些配置,將該值更改爲localhost。

如果是這種情況,爲什麼不爲每個環境提供轉換文件,其中調試配置可以將密鑰設置爲localhost,並且您的production/test/stage/qa/whatever配置可以將其設置爲example.com或別的東西。

你可能不知道msbuild可以轉換你的配置文件。本質上你有你的主要配置文件,然後爲每個環境配置一個包含更改內容的配置文件。在進行構建時,msbuild將修改主構件,其中包含其他「變形」文件中的更改。

App.Config Transformation for projects which are not Web Projects in Visual Studio 2010?

你轉換文件看起來像:

<?xml version="1.0"?> 

<!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 --> 

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">  
    <appSettings> 
    <add key="url" value="http://www.example.com/" xdt:Locator="Match(key)" xdt:Transform="SetAttributes"/> 
    </appSettings> 
</configuration> 

微軟環節是http://msdn.microsoft.com/en-us/library/dd465326(VS.100).aspx

他們可以很容易地在web.configs,以及app.configs使用,稍微調整一下你的項目文件。

0

另一種解決方案是將單元測試作爲構建的一部分進行集成,並讓測試驗證web.config中的關鍵。

轉到你的構建:

enter image description here

右鍵單擊您的構建和點擊編輯構建定義:

enter image description here

選擇過程:

enter image description here

現在,我們可以設置失敗的構建在這裏:因爲它的意思來分析C#源代碼

enter image description here