Jason Burton
Jason Burton

Reputation: 67

Easiest way to make web.config transforms for deployment?

Anyone have a preferred method for making web.config transforms? I am curious as to what others have done for this. I hate having to continuously update the web.config every time I update or republish.

Upvotes: 1

Views: 83

Answers (4)

Reikim
Reikim

Reputation: 186

A few years ago Scott Hanselman gave a solution using pre-build events and batch files:

http://www.hanselman.com/blog/ManagingMultipleConfigurationFileEnvironmentsWithPreBuildEvents.aspx

Basically you maintain a separate different configuration for each build and run the batch script pre-build to copy over the Web.Config. The obvious disadvantage is that if you have thirty different build configurations you need thirty different configs, but I find it's nice for projects where you only have two or three configs (like hobby projects, or tools you'll only ever be publishing to internal servers). Plus, it's nice knowing that if you want to you can take extra control of the build process if you want to.

Upvotes: 1

Ryan Mann
Ryan Mann

Reputation: 5357

  1. Create a build configuration for each server you want to deploy to

Example

-Dev Server "copy from debug"- -Prod Server Debug "copy from debug"- -Prod Server Release "copy from release"-

Then right click your web.config and select "add config transforms"

You will get new transforms for each configuration you added above.

Now configure your web config transforms for each environment.

Now when you publish you can just select the configuration "Dev, Prod Debug, or Prod Release" and out it goes, no need to update them after that.

Now, the base web.config should always be configured for your local environment, so if you set up in IIS locally it will use web.config without any transforms. Your transforms should transform your local settings in the base web.config to w/e they need to be.

Upvotes: 1

Stephen Brickner
Stephen Brickner

Reputation: 2602

Look into the nuget package for slow cheetah: https://www.nuget.org/packages/SlowCheetah/ This does what you are looking for quite nicely. Be aware that it is for publish transformations only, switching to a different config for local debugging will have no affect.

Upvotes: 1

g.pickardou
g.pickardou

Reputation: 35843

The easiest way to use VS built in support:

enter image description here

You have versions of web.config, for your build versions, (by default Debug and Release)

In the release version you can define transforms what are applied during build. The effective web.config will be the result.

Upvotes: 1

Related Questions