The MSBuild project is deployed to the local config folder
I am having trouble finding the correct way to use MSBuild to build a web project and output a project with only deployable files (i.e. no .cs, .csproj, .Debug.config, etc.), but published a local folder that I can then FTP, RoboCopy (or whatever) to a secondary location.
The published output must have a Web.config file pre-converted to match the specified configuration and conversion configuration files (such as Web.Debug.config) not included in the output. I don't need any fancy publishing for IIS, database deployments or anything like that, I just want a clean filesystem that I can test. Please note that this cannot be done with visual tools as I want to run it as part of an automated build process.
I can create a web deployment package but I cannot get WebDeploy to work because it no longer handles the quoted command line options (it seems to be some kind of error) and the directory structure has spaces, so I was hoping to accomplish the whole task with MSBuild, as MSBuild seems to have its own potential for converting the config file ( TransformXml
), which is the only real bit of proper deployment functionality I would use.
source to share
Got it eventually. The following build script does the trick:
<?xml version="1.0"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<PropertyGroup>
<OutputDir>obj\website-output</OutputDir>
</PropertyGroup>
<Target Name="PrepareDeploy">
<ItemGroup>
<DeployableFiles Include="App_Code/**/*.*;App_Data/**/*.*;Areas/**/Views/**/*.*;bin/**/*.*;Views/**/*.*;*.aspx;*.asax;*.html;*.htm;sitemap.xml;*.ico;*.png" Exclude="App_Data/**/*.log" />
</ItemGroup>
<RemoveDir ContinueOnError="true" Directories="$(OutputDir)" />
<MSBuild Projects="Website.csproj" />
<MakeDir ContinueOnError="true" Directories="$(OutputDir)" />
<Copy SourceFiles="@(DeployableFiles)" DestinationFiles="@(DeployableFiles->'$(OutputDir)\%(RelativeDir)%(Filename)%(Extension)')" />
<TransformXml Source="Web.config" Transform="Web.$(Configuration).config" Destination="$(OutputDir)\web.config" />
</Target>
</Project>
source to share