0

in VS 2012 with Update 2 i have a web site which i publish. the new publish wizard was configured to publish the site to a folder on my disk. while checking something on my temp files folder i ran a publish of my site. i saw that the publisher creates a folder on %TEMP%\WebSitePublish and in there creates 3 copies of the site:

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\

since my web site is huge (1.6GB) each of these folders take 1.6GB and 4.8 GB in total. while i think this is wasting disk space even during a publish, i can't argue with MS about the way they implemented the publish. the only thing that does bother me is that even after closing the VS IDE, the r:\temp\WebSitePublish\web-1279598559 folder remains and still occupies 4.8GB. How can i make the publisher delete it's temp files after it finishes the publish?

my pubxml for this site is this:

<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>
Dani Avni
  • 423
  • 5
  • 14
  • this may be a dumb question but why is your website 1.6GB? – drzaus Feb 12 '14 at 21:20
  • I have a lot of login screens for various brandings of installations of our system. each login screen contains images, documents and some of them have flash. when installing my site I have a tool that deletes all unneeded logins based on the specific installation. this brings the whole site to 1.6GB on develop machine and about 70MB on a typical production machine – Dani Avni Feb 13 '14 at 06:40

1 Answers1

1

I think you can set up a 'build target' in your .csproj file (maybe in the .pubxml file instead?), like Why does MSBuild ignore my BeforePublish target? or How can I prevent hidden .svn folder from being copied from the _bin_deployableAssemblies folder?. @sayed-ibrahim-hashimi has a lot of answers regarding build targets.

In my experience it's been tricky to figure out what target to attach to, since there has been some churn between different Visual Studio releases, but I think you want something like:

  <!-- 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>

The important parts here are:

  • AfterTargets -- specifies when this task should be run (and AfterPublish should be self-explanatory; I think that's the right one)
  • CreateItem -- scan the given directory glob and set a list to the variable @(GeneratedFiles)
  • Delete -- delete the list created by CreateItem
Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201