Q:

Problem with Team Build 2010 and web.config transformation

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

A:

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.

