3

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

enter image description here

3
  • before you run it switch in solution configuration from debug to release Commented Apr 4, 2016 at 12:09
  • why does not work Web.debug.config ? Commented Apr 4, 2016 at 12:16
  • Your web.debug.config doesn't contain any transformations. You could convert it into a transformation by adding xdt:Transform="Replace" xdt:Locator="Match(name)" to the smtp element Commented Apr 4, 2016 at 12:34

4 Answers 4

4

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

Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

1

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

2 Comments

Isn't SlowCheetah deprecated since it is not actively maintained anymore, och does not work for example in Visual Studio 2015? sedodream.com/CategoryView,category,SlowCheetah.aspx
That post was from 2014 but the gallery entry was from 2015 so something must have changed his mind between the two...
1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.