如何设置pubxml以在发布后删除临时文件

时间:2013-05-28 09:20:18

标签: asp.net visual-studio-2012

在VS 2012中使用Update 2,我有一个我发布的网站。新发布向导配置为将站点发布到磁盘上的文件夹。在检查我的临时文件夹上的内容时,我运行了我的网站发布。我看到发布者在%TEMP%\ WebSitePublish上创建了一个文件夹,并在那里创建了3个网站副本:

r:\temp\WebSitePublish\web-1279598559\obj\Debug\AspnetCompileMerge\Source\
r:\temp\WebSitePublish\web-1279598559\obj\Debug\AspnetCompileMerge\TempBuildDir\
r:\temp\WebSitePublish\web-1279598559\obj\Debug\Package\

由于我的网站很大(1.6GB),因此每个文件夹总共需要1.6GB和4.8GB。 虽然我认为即使在发布期间这也浪费了磁盘空间,但我无法与MS争论他们实施发布的方式。唯一困扰我的是,即使在关闭VS IDE之后,r:\ temp \ WebSitePublish \ web-1279598559文件夹仍保留并仍然占用4.8GB。如何让发布者在完成发布后删除它的临时文件?

此网站的pubxml是:

<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>x86</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <publishUrl>C:\PrecompiledWeb\Site</publishUrl>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <PrecompileBeforePublish>True</PrecompileBeforePublish>
    <EnableUpdateable>True</EnableUpdateable>
    <DebugSymbols>True</DebugSymbols>
    <WDPMergeOption>CreateSeparateAssembly</WDPMergeOption>
    <UseFixedNames>True</UseFixedNames>
  </PropertyGroup>
</Project>

1 个答案:

答案 0 :(得分:1)

我认为您可以在.csproj文件中设置“构建目标”(可能在.pubxml文件中?),例如Why does MSBuild ignore my BeforePublish target?How can I prevent hidden .svn folder from being copied from the _bin_deployableAssemblies folder?@sayed-ibrahim-hashimi有很多关于构建目标的答案。

根据我的经验,弄清楚要附加什么目标是很棘手的,因为不同的Visual Studio版本之间存在一些流失,但我认为你想要这样的东西:

  <!-- these are your instructions; name is arbitrary, `AfterTargets` says when -->
  <Target Name="CleanTempDirectory" AfterTargets="AfterPublish">
    <!-- use 'importance=high' to show in the Output window (?) -->
    <Message Text="Cleaning up publish temp directories" Importance="high" />

    <!-- here, specify the directory(ies) to clear; can use build event macros -->
    <CreateItem Include="$(ProjectDir)App_Data\*\*">
      <Output ItemName="GeneratedFiles" TaskParameter="Include" />
    </CreateItem>
    <Delete Files="@(GeneratedFiles)" />
  </Target>

这里的重要部分是:

  • AfterTargets - 指定何时应该运行此任务(而AfterPublish应该是不言自明的;我认为这是正确的)
  • CreateItem - 扫描给定目录glob并将列表设置为变量@(GeneratedFiles)
  • Delete - 删除CreateItem
  • 创建的列表
相关问题