Reputation: 6845
There are Web.config
and Web.debug.config
and Web.release.config
files in my visual studio solution window.
I want to set different email configurations for release and debug.
So I set Web.debug.config file
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<network host="localhost" port="587" defaultCredentials="true"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\Temp\Mail\Debug"/>
</smtp>
</mailSettings>
</system.net>
And I set my 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>
When I run the applciaitons, my settings does not load to SmtpClient
object.
Why does not take settings from Web.debug.config
Upvotes: 3
Views: 1393
Reputation: 1566
https://devblogs.microsoft.com/aspnet/asp-net-web-projects-web-debug-config-web-release-config/
Debug is for development environment
Release for production environment
Web.config is for local machine
Upvotes: 1
Reputation: 1140
As mentioned before it is not a webconfig rather than transformations. And a transformation is tranformed into the web.config when building/publishing in for example release mode.
You must set some meta information in the web.release.config how the tranformation should be treated, for example:
<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>
This will instruct the transformation to replace the specifiedPickupDirectory tag in the web.config with the one in web.release.config.
If you want to make tranformations on build and not only when you publish, you have to add a TransformXml to a BeforeBuild section in your csproj.
Upvotes: 3
Reputation: 413
Like Merryweather said, this is a transform to apply on top of the base config. SlowCheetah offers extensions that let you right click to preview the config transform. You can access those through the visual studio gallery:
https://visualstudiogallery.msdn.microsoft.com/05bb50e3-c971-4613-9379-acae2cfe6f9e
Upvotes: 1
Reputation: 4624
This only works for when you publish a project, not in the IDE. Read more here:
https://msdn.microsoft.com/en-us/library/dd465318(v=vs.100).aspx
Upvotes: 4