![](/img/trans.png)
[英]Understanding ASP.NET Web.config transformations - Web.Debug.config
[英]Asp.net mvc web.config and web.debug.config difference
我的 Visual Studio 解決方案窗口中有Web.config
和Web.debug.config
和Web.release.config
文件。
我想為發布和調試設置不同的電子郵件配置。
所以我設置了 Web.debug.config 文件
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" port="587" defaultCredentials="true"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Debug"/>
</smtp>
</mailSettings>
</system.net>
我設置了我的 Web.release.config
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" port="587" defaultCredentials="true"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Release"/>
</smtp>
</mailSettings>
</system.net>
當我運行應用程序時,我的設置不會加載到SmtpClient
對象。
為什么不從 Web.debug.config 中獲取設置
這僅適用於發布項目時,而不適用於 IDE。 在此處閱讀更多信息:
https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
如前所述,它不是 webconfig 而不是轉換。 在例如發布模式下構建/發布時,轉換會轉換為 web.config。
您必須在 web.release.config 中設置一些元信息應該如何處理轉換,例如:
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" port="587" defaultCredentials="true"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Release"/ xdt:Transform="Replace">
</smtp>
</mailSettings>
</system.net>
這將指示轉換將 web.config 中指定的PickupDirectory 標記替換為 web.release.config 中的標記。
如果您想在構建時進行轉換而不僅僅是在發布時進行轉換,您必須將 TransformXml 添加到您的 csproj 中的 BeforeBuild 部分。
就像 Merryweather 所說的,這是一個應用在基本配置之上的轉換。 SlowCheetah 提供了一些擴展,讓您可以右鍵單擊以預覽配置轉換。 您可以通過 Visual Studio 庫訪問這些:
https://visualstudiogallery.msdn.microsoft.com/05bb50e3-c971-4613-9379-acae2cfe6f9e
https://devblogs.microsoft.com/aspnet/asp-net-web-projects-web-debug-config-web-release-config/
Debug 是針對開發環境的
生產環境發布
Web.config 用於本地機器
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.