Aug 18, 2012
3 mins read
使用過內建的web.config transform功能,對於佈署不同環境時更新設定檔內容很有幫助 但app.config並沒有這樣的功能,之前搜尋了一些解法,大部份是自行修改專案檔,並利用MSBuild來轉換XML檔案 那一次研究到頭暈眼花還搞不定,就暫時放下,改天境界有所提升再來研究 最近又想到這個問題,趁著失眠的時後再來摸一下,應該可以很快就睡著XD 結果找到了這個套件,用滑鼠點一點就搞定了,使用上方便多了
](http://3.bp.blogspot.com/-eD-oI9lRbjQ/UC9h51R2VZI/AAAAAAAAAAo/RL1zOHSjxrU/s1600/02.AddTransform.png)
](http://3.bp.blogspot.com/-hZFwvWz7Jn4/UC9h6tFmWtI/AAAAAAAAAAs/ZmaHtC_mDzo/s1600/03.Alert.png)
](http://3.bp.blogspot.com/-dyVGcKN93PQ/UC9lbptDKlI/AAAAAAAAABc/heOoWKUG5Cs/s1600/035+Result.png)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ServerIP" value="127.0.0.1" />
</appSettings>
<connectionStrings>
<add name="MyDB" providerName="System.Data.SqlClient"
connectionString="Data Source=(local);Initial Catalog=DemoDB;Integrated Security=True"/>
</connectionStrings>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<!– For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134\. –>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="ServerIP" value="192.168.100.11"
xdt:Transform="SetAttribute" xdt:Locator="Match(key)" />
</appSettings>
<connectionStrings>
<add name="MyDB" connectionString="Data Source=192.168.100.11;Initial Catalog=DemoDB;uid=ooo;pwd=xxx;"
xdt:Transform="SetAttribute" xdt:Locator="Match(key)" />
</connectionStrings>
</configuration>
<?xml version="1.0" encoding="utf-8" ?>
<!– For more information on using transformations
see the web.config examples at http://go.microsoft.com/fwlink/?LinkId=214134\. –>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<appSettings>
<add key="ServerIP" value="10.8.200.11"
xdt:Transform="SetAttribute" xdt:Locator="Match(key)" />
</appSettings>
<connectionStrings>
<add name="MyDB" connectionString="Data Source=10.8.200.11;Initial Catalog=DemoDB;uid=###;pwd=***;"
xdt:Transform="SetAttribute" xdt:Locator="Match(key)" />
</connectionStrings>
</configuration>
App.Config Transformation for projects which are not Web Projects in Visual Studio 2010? SlowCheetah - XML Transforms 使用 Visual Studio 之 Web 應用程式專案部署的 Web.config 轉換語法
Sharing is caring!