Specifying different appSettings with Web Deploy in VS 2012
Asked Answered
H

2

5

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?

Hydrosphere answered 7/11, 2012 at 9:33 Comment(0)
L
7

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

Lastex answered 7/11, 2012 at 12:10 Comment(1)
Hmmm... this does look promising. I will have a play and see how it goesHydrosphere
M
2

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.

Motile answered 13/1, 2015 at 8:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.