替换之前的 MSBuild 备份文件(带时间戳)
我目前使用 Web 部署项目通过各种 MSBuild 任务更新现有网站
使站点脱机:
<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>
更新文件:
<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>
但是,我还想做的是在覆盖任何内容之前将现有站点备份到带时间戳的 zip(或 7zip)文件中,例如,如果在 2011 年 10 月 3 日 10:35 完成,文件将命名为 \\servername\f$\web\example.com\backup201110031035.7z
包含 wwwroot 文件夹的内容(在使站点脱机并删除 bin 目录之前)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSBuild 社区任务 支持通过
Zip< 压缩和获取(格式化的)当前时间分别是 /code> 和
Time
任务。安装 MSBuild 社区任务并将其导入到您的项目后,您可以通过将以下内容添加到
BeforeBuild
目标的开头来创建备份 zip 文件。The MSBuild Community Tasks provide support for both, zipping and getting the (formatted) current time through the
Zip
andTime
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.