Asp.net
如何將配置轉換應用於外部配置文件
我在網上找不到我的問題的例子,想知道是否有人知道解決方案。基本上,如果在我們的 web.config 中,我們指向另一個文件,如下所示:
<configuration> <configSections /> <appSettings file="AppSettings.config"> </configuration>那麼我們如何將轉換應用於該外部文件?
基本上,我想創建一個 AppSettings.config、AppSettings.Debug.config、AppSettings.Release.config 並對其進行轉換……這甚至可能嗎?
提前致謝,
塞爾吉奧
有幾個解決方法:
解決方法 1
- 寫入
AppSettings.Debug.config,AppSettings.Release.config具有完整值(不具有轉換屬性)- 在您的
web.config中,使用轉換,替換為適當的文件:
web.debug.config<appSettings file="AppSettings.debug.config" xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>
web.release.config<appSettings file="AppSettings.release.config" xdt:Transform="SetAttributes" xdt:Locator="Match(file)"/>它不太理想,有點違背了轉換的目的,但根據個人情況可能比使用 SlowCheetah 之類的東西更合適。
解決方法 2