We help IT Professionals succeed at work.
Get Started

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

204 Views
Last Modified: 2016-07-23
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
Comment
Watch Question
All-around developer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE