I currently use a web deployment project to update an existing web site through various MSBuild tasks
Taking site offline:
<Target Name="BeforeBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<CreateItem Include="..\website\App_Code\override\App_Offline.htm">
<Output TaskParameter="Include" ItemName="AppOffline" />
</CreateItem>
<Copy SourceFiles="@(AppOffline)" DestinationFiles="@(AppOffline->'\\servername\f$\web\example.com\wwwroot\%(RecursiveDir)%(Filename)%(Extension)')" />
<RemoveDir Directories="\\servername\f$\web\example.com\wwwroot\bin\" />
</Target>
Update files:
<Target Name="AfterBuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<CreateItem Include=".\Release\**\*">
<Output TaskParameter="Include" ItemName="ReleaseFiles" />
</CreateItem>
<Copy SourceFiles="@(ReleaseFiles)" ContinueOnError="true" SkipUnchangedFiles="true" DestinationFiles="@(ReleaseFiles->'\\servername\f$\web\example.com\wwwroot\%(RecursiveDir)%(Filename)%(Extension)')" />
<Delete Files="\\servername\f$\web\example.com\wwwroot\App_Offline.htm" />
</Target>
However, what I also want to do is backup the existing site before overwriting anything, into a timestamped zip (or 7zip) file, e.g. if done on 3rd October 2011 at 10:35 file would be named \\servername\f$\web\example.com\backup201110031035.7z containing the contents of the wwwroot folder (before taking the site offline and deleting the bin directory)
The MSBuild Community Tasks provide support for both, zipping and getting the (formatted) current time through the Zip and Time tasks respectively.
Once the MSBuild community tasks are installed and imported to your project, you can create a backup zip file by adding the following to the beginning of your BeforeBuild target.
<ItemGroup>
<FilesToZip Include="\\servername\f$\web\example.com\wwwroot\**\*.*" />
</ItemGroup>
<Time Format="yyyyMMddhhmm">
<Output TaskParameter="FormattedTime" PropertyName="Timestamp" />
</Time>
<Zip
Files="@(FilesToZip)"
ZipFileName="\\servername\f$\web\example.com\backup$(Timestamp).zip"
WorkingDirectory="\\servername\f$\web\example.com\wwwroot" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With