替换之前的 MSBuild 备份文件(带时间戳)

发布于 2024-12-07 11:42:36 字数 1395 浏览 0 评论 0原文

我目前使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

铃予 2024-12-14 11:42:36

MSBuild 社区任务 支持通过 Zip< 压缩和获取(格式化的)当前时间分别是 /code> 和 Time 任务。

安装 MSBuild 社区任务并将其导入到您的项目后,您可以通过将以下内容添加到 BeforeBuild 目标的开头来创建备份 zip 文件。

<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" />

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" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文