簡體   English   中英

<appSettings />是否可以包含設置並引用另一個文件中的另一個<appSettings />部分?

[英]Is it possible for <appSettings /> to contain settings AND refer to another <appSettings /> section in a different file?

我可以在app.config中有一個<appSettings />部分,其中包含許多設置,但也引用了另一個文件中的<appSettings />部分嗎?

這將允許我保留只有開發人員應該感興趣的配置選項,例如在主窗口上顯示調試輸出的選項(非常混亂但對我有用)或將某些文件保存到特定位置。

具體來說,這就是我想要實現的目標:

<!-- this is the appSettings section of the normal app.config file,
     which also contains everything else that app.config would -->
<appSettings configSource="AppSettings.config"> <!-- references another file -->
  <add key="deployment_config_option1" value="1"/>
  <add key="deployment_config_option2" value="2"/>
</appSettings>

<!-- this a new appSettings section of another file called DevSettings.Config
     which only contains settings us developers are interested in
     by keeping these settings in a different file, 
     I can ensure it's never deployed -->
<appSettings> <!-- references another file -->
  <add key="show_debug_on_screen" value="true"/>
  <add key="save_copy_to_desktop" value="false"/>
</appSettings>

是。 考慮到可能的場景數量, 文檔有點薄,但根據下面的引用說,僅在appSettings標記的情況下有合並。

由於對Web.config文件的任何更改都會導致應用程序重新啟動,因此使用單獨的文件允許用戶修改appSettings部分中的值,而不會導致應用程序重新啟動。 單獨文件的內容與Web.config文件中的appSettings部分合並 此功能僅限於appSettings屬性。

在ASP.NET的情況下對此(下面)的測試顯示它使用<add>標記。 雖然我沒有測試邊緣情況,但是在下級文件中使用像<clear>標簽這樣的更高級的東西顯然會出現問題。 不能說ASP以外的部署技術; Machine.Config也未經過測試。

在web.config文件中:

    <appSettings file="_config\AppSettings.Config">
            <add key="testing-1" value="Web.Config" />
    </appSettings>

在“_config \\ AppSettings.config”文件中:

    <appSettings>
            <add key="testing-2" value="_config/AppSettings.config" />
    </appSettings>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM