Question

I'm having this weird issue I can't seem to figure out. I've developed this WPF application that has 2 configuration files setup one for Debug and another for Release. When I run the application in Debug mode it connects to the dev database as its supposed to and in Release it connects to the prod database and runs fine as its supposed to. However when I publish the application in Release mode and I go to launch the executable its running as if its in debug mode with the connection established to the dev database.

I placed this code in the post build event command line:

if "Debug"=="$(ConfigurationName)" goto :nocopy
del "$(TargetPath).config"
copy "$(ProjectDir)\Release.config" "$(TargetPath).config"

And copy pasted my debug.config file to my release.config and just changed my connection string in my release config to connect to my prod database.

How is this possible that it works fine when I'm debugging on both modes but when I publish in Release mode it uses the Debug config info? Any help would be greatly appreciated.

Update

When I publish what I do is right click on my project and select publish and walk through the wizard. I checked the publish tab under project properties and the configuration is grayed out and set to N/A. However, under the Debug tab configuration can be selected between debug and release.

No correct solution

OTHER TIPS

Check your publish settings and make sure configuration is set to Release and not Debug

One thing to verify is that you're selecting 'release' in the wizard, not just in visual studio. Pic below shows both.

enter image description here

Otherwise, there may be an error in your web.release.config transforms. Can you post the section from your web.release.config file? Looks like this (as usual, hide the data source, database name, user name and password):

<connectionStrings>
    <add name="fbConnection"
      connectionString="Data Source=mydatasource;Initial Catalog=myDataBaseName;User ID=MyUserName;Password=myPassword" providerName="System.Data.SqlClient"
      xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
  </connectionStrings>
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

the most likely error is that the name portion (add name="connectionName" ...) has a typo and isn't matching the name in your web.config file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top