4

I'm struggling to get web.config transformations working with automated builds.

We have a reasonably large solution, containing one ASP.NET web application and eight class libraries. We have three developers working on the project and, up to now, each has "published" the solution to a local folder then used file copy to deploy to a test server. I'm trying to put an automated build/deploy solution in place using TFS 2010.

I created a build definition and added a call to msdeploy.exe in the build process template, to get the application deployed to the test server. So far, so good!

I then tried to implement web.config transforms and I just can't get them to work. If I build and publish locally on my PC, the "publish" folder has the correct, transformed web.config file.

Using team build, the transformation just does not happen, and I just have the base web.config file.

I tried adding a post-build step in the web application's project file, as others have suggested, similar to:

<target name="AfterBuild">
<TransformXml Source="Web.generic.config"
             Transform="$(ProjectConfigTransformFileName)"
             Destination="Web.Config" />
</target>

but this fails beacuse the source web.config file has an "applicationSettings" section. I get the error

Could not find schema information for the element 'applicationSettings'.

I've seen suggstions around adding arguments to the MSBuild task in the build definition like

/t:TransformWebConfig /p:Configuration=Debug

But this falls over when the class library projects are built, presumably because they don't have a web.config file.

Any ideas? Like others, I thought this would "just work", but apparently not. This is the last part I need to get working and it's driving me mad. I'm not an msbuild expert, so plain and simple please!

Thanks in advance.

Doug

Doug
  • 457
  • 5
  • 17

2 Answers2

3

I just went through this. Our build was a bit more complicated in that we have 8 class libraries and 9 web applications in one solution. But the flow is the same.

First off get rid of your after build target. You won't need that.

You need to use the MSDeployPublish service. This will require that it be installed and configured properly on the destination server. Check the following links for info on this part:

Note that the server in question MUST be configured properly with the correct user rights. The following sites helped me get that properly set up.

http://william.jerla.me/post/2010/03/20/Configuring-MSDeploy-in-IIS-7.aspx
http://vishaljoshi.blogspot.com/2010/11/team-build-web-deployment-web-deploy-vs.html
How can I get TFS2010 to run MSDEPLOY for me through MSBUILD?

The next part requires that your build definition have the correct MSBuild parameters set up to do the publish. Those parameters are entered in the Process > 3.Advanced > MS Build Arguments line of the build definition. Here's a hint:

(don't change the following for any reason)
/p:DeployOnBuild=True 
/p:DeployTarget=MsDeployPublish 
/p:CreatePackageOnPublish=False 
/p:MSDeployPublishMethod=WMSVC 
/p:SkipExtraFilesOnServer=True
/p:AllowUntrustedCertificate=True 

(These control where it's going)

/p:MSDeployServiceUrl="https://testserver.domain:8172/msdeploy.axd" 
/p:UserName=testserver\buildaccount 
/p:Password=buildacctpassword 
/p:DeployIisAppPath="MyApp - TESTING" 

Obviously the user will have to be configured in IIS on the target server to be allowed access to that axd (see previous links). And the IisAppPath is the name of the website on the target server.

You won't have to do anything special for the config transformations as the build itself will take care of that for you. Just have the correct setting in the line at Process > 1. Required > Items to Build > Configurations To Build.

Community
  • 1
  • 1
NotMe
  • 87,343
  • 27
  • 171
  • 245
  • 1
    Just a side note. There were two hard parts in all of this. The first was getting the MSDeployService properly installed on the web server. The second was figuring out all of the right MSBuild parameters. Some of those sites Doug mentioned are targeted towards building and deploying on the same machine so their parameters don't work. All in all, the first pass through took me about 6 hours to figure out. Now that it's set up, I can create a new build definition in about 5 minutes. – NotMe Dec 01 '10 at 15:18
  • Great post Chris, I also worked through all of this (took me a bit longer partly due to some oddities on server, partly due to using hosted tfs), but really good summary of the subject. Chrs. – MemeDeveloper Jul 03 '12 at 03:12
  • Another side note: I set this up on a new server last week. The latest installer for MSDeploy is MUCH better than the previous one. – NotMe Jul 03 '12 at 21:04
1

Instead of trying to do the deploy by adding tasks myself into the build process template, I followed advice in Vishal Joshi's blog post here.

Now the entire project is built and deployed and the web.config transformations work also. Brilliant!

I now have another problem to solve! The web application references web services and the build process results in an XmlSerializers dll. However, although this is built OK, it does not get deployed to the web host. I think this needs a new post!

Doug

Doug
  • 457
  • 5
  • 17
  • Found the answer to my XmlSerializers problem here http://stackoverflow.com/questions/3636103/tfs-2010-creating-net-4-0-xmlserializers-dll-for-net-3-5-application – Doug Dec 01 '10 at 16:52