Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting web.config properties during build (not through publishing)

I'm trying to deploy an app using a Web Setup Project. The problem I'm running into is that the web.config file is never transformed. According to this post it's by design that transformation only takes place during a publish. How do I get the web.config properties to update correctly if building the Setup Project in turn calls the other assemblies build command?

like image 683
Dan Avatar asked May 06 '11 15:05

Dan


2 Answers

I fixed it by adding a dummy web.Template.config file like Andriy K suggested in this post, and then calling TransformXml during my BeforeBuild event like so:

<Target Name="BeforeBuild">
<TransformXml Source="$(WebFolderName)Web.Template.config"
              Transform="$(WebFolderName)Web.$(Configuration).config"
              Destination="$(WebFolderName)Web.config" />
</Target>
like image 58
Dan Avatar answered Oct 13 '22 00:10

Dan


The simplest option is to install a command-line xslt utility and launch it in the post-build action of your project. You could also use one of the many MSBuild XSLT tasks and add it into the .csproj file. (It's just an MSBuild script file; there are comments already in there near the bottom explaining how to customize the build.)

You could also perform either of these steps in the pre-build action of your setup project, instead of the post-build action of your web application. If you also use the publishing wizard, this second option may work better as it won't interfere with the normal XSLT transforming going on in the publisher.

Microsoft XSLT command-line utility: http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2fb55371-c94e-4373-b0e9-db4816552e41&displaylang=en

Example MSBuild XSLT Task: http://www.arlt.eu/blog/2007/10/01/msbuild-xslt-task/

like image 27
Michael Edenfield Avatar answered Oct 12 '22 23:10

Michael Edenfield