简体   繁体   中英

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,

在此处输入图片说明

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?

在此处输入图片说明

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

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM