Transforming web.config before publishing to server with WebDeploy (TransformXml)

I have a WebAPI / EntityFramework project that I am working on and I publish updates to the server quite often (using WebDeploy).

My setup uses custom defaultConnectionFactory in order to create connection string based on certain criteria.

Every time I push an update to sever, an new connection string is added to my web.config file:
name: MyProject.Lib.Data.DataContext
value: MyProject.Lib.Data.DataContext_ConnectionString

I found a solution (http://stackoverflow.com/a/3622821/573208) that looks like exactly what I am looking for but I could not make it work.

I added this line at the end of my project file
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.Tasks.dll" />

Open in new window

right before </Project> closing tag. But could not go any more further.

The article states that I need to
place <TransformXml Source="web.config" Transform="web.release.config" Destination="$(DeployPath)\web.config" /> in the right item group
and then
make sure that target gets fired prior to the call to Package

That's where I got confused:
- Where should I place the <TransformXml ... /> section and how to I find out which is the "the right ItemGroup"
- How do I "make sure that target gets fired prior to the call to Package"

Any help would be much appreciated
To KaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Eddie ShipmanAll-around developerCommented:
What we do  is create the 2 config files and use something like this to change the variable information in each.  This way we don't actually have to create a full config for each mode.

We use Paypal as a payment processor and for our debug mode, we use the "sandbox" url.
Our master has the value setup like this to work with our dev environment:
<add key="PAYFLOW_HOST" value="pilot-payflowpro.paypal.com" />

Open in new window


In our Release config this code changes the value:
<add key="PAYFLOW_HOST" value="payflowpro.paypal.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

Open in new window


In the debug config it looks like this:
<add key="PAYFLOW_HOST" value="pilot-payflowpro.paypal.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.