Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying different appSettings with Web Deploy in VS 2012

I have recently started using Web Deploy with IIS 7 on the server and Visual Studio 2012. My project in question is an ASP.Net MVC 3 web application.

I have set it all up correctly and the publishing is working and I get the desired connection string transformation so the target server can access the correct database.

However, there are a couple of appSettings that need to be different on the server than the values used for development on local machine.

Lets say for this example I have a development web.config with the following:

<appSettings>
    <add key="CommonName" value="AlwaysTheSame" />
    <add key="VariableName" value="LocalValue" />
<appSettings>

and when it gets published I want it to be as follows on the server:

<appSettings>
    <add key="CommonName" value="AlwaysTheSame" />
    <add key="VariableName" value="ServerValue" />
<appSettings>

I am thinking I need to change something in the .pubxml file which is found in the Properties > PublishProfiles folder as this seems to be how the connection string is changed. However, I am not finding any useful information about how to modify this file to suit my needs. What changes do I need to make?

like image 434
musefan Avatar asked Nov 07 '12 09:11

musefan


2 Answers

You could use config transforms, which allow you to have mulitple versions of a config file for different environments:

enter image description here

Then when publishing, you select your environment, and this will override the web.config with the environment-specific config.

In terms of keeping one value consistent across the different deployment types, you could just store that in the main web.config, and store the others in web.live.config etc.

For more information of config transforms, read this great blog post by Vishal R. Joshi:

http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx

like image 184
Curtis Avatar answered Dec 19 '22 19:12

Curtis


If you know the values to use on the server in advance, then you can use Web.config transformations.
However, if you require these values to be entered as parameters during the deployment process on the server then you can use Web Deploy parameters as described in this MSDN article.

like image 40
Eran Stiller Avatar answered Dec 19 '22 17:12

Eran Stiller