Expert wanna be
Expert wanna be

Reputation: 10624

Visual Studio 2010, asp.net mvc3 web.config for Debug and Release

I want to use Web.Debug.config and Web.Release.config each.

But it does not work in Visual Studio 2010 And it works on actual server after deployment.

Web.Release.config

<appSettings>
    <add key="GOOGLE_MERCHANT_ID" value="LIVE_GOOGLE_MERCHANT_ID" xdt:Transform="Insert" xdt:Locator="Match(key)" />
</appSettings>

Web.Debug.config

<appSettings>
    <add key="GOOGLE_MERCHANT_ID" value="DEBUG_GOOGLE_MERCHANT_ID" xdt:Transform="Insert" xdt:Locator="Match(key)" />
</appSettings>

I have like above config files and I try to echo on screen the config value.

string t = WebConfigurationManager.AppSettings["GOOGLE_MERCHANT_ID"]; Response.Write(t);

On Visual studio,

enter image description here

set as Release mode, and F5 (also I tried Build Solution(F6)) but it doesn't print anything.

So I try to Deployment package and install on server and run then it prints the right value.

How I do for that in Visual studio? I want to make sure everything OK before deploy package.

Please advise me~

Thank you!

[Edit]

Now I get it, thank you for everyone who gave me nice answer!

May I ask one more question please?

then what's this for?

enter image description here

If I change to Release or Debug then what effect to my project?

Upvotes: 1

Views: 1319

Answers (3)

NinjaNye
NinjaNye

Reputation: 7126

See this post https://stackoverflow.com/a/5734829/611288

As Jimmy says, the web.config transforms are only applied during the Web Publish Pipleline

Jimmy also supplies the following link for a hack: http://sedodream.com/2010/10/21/ASPNETWebProjectsWebdebugconfigWebreleaseconfig.aspx

Alternatively, create a test deploy that deploys locally and test the config settings there.

Upvotes: 1

Idrees Khan
Idrees Khan

Reputation: 7752

I think you can't do this is visual studio. If you want to test your project on server, then try to test it on local iis instead of the actual server.

Upvotes: 0

Dan Lister
Dan Lister

Reputation: 2583

As far as I'm aware, there isn't a way to build web.config when building your solution. You could get around this by executing an xml merge tool as a post-build event based on your selected build configuration. Something like XmlConfigMerge might help you.

Upvotes: 0

Related Questions