<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="https://stackoverflow.com/questions/8127/pre-build-task-deleting-the-working-copy-in-cruisecontrol-net">Pre-build task - deleting the working copy in CruiseControl.NET</a>  </p>
</blockquote>



<p>I would like to delete my working directory during the cruisecontrol build process...I'm sure this is easy, but I have been unable to find an example of it...</p>

<p>If you know how to create a directory, that would be useful as well.</p>

<p>Thanks.</p>

[{'answer_id': 26931, 'author': 'Brad Wilson', 'author_id': 1554, 'author_profile': 'https://Stackoverflow.com/users/1554', 'pm_score': 2, 'selected': False, 'text': "<p>One of two ways.</p>\n\n<ol>\n<li>If you're already using an MSBuild file or something similar, add the action to the MSBuild file.</li>\n<li>Instead of directly executing some command, create a batch file that executes that command and then deletes the directory, and have CCnet call that batch file instead.</li>\n</ol>\n"}, {'answer_id': 26958, 'author': 'Sir Rippov the Maple', 'author_id': 2822, 'author_profile': 'https://Stackoverflow.com/users/2822', 'pm_score': 0, 'selected': False, 'text': '<p>My guess is that you want to delete the working directory <em>before</em> CruiseControl.NET gets the latest code from source control. If this is the case, then the only way to accomplish this is to write a custom source control provider for CruiseControl.NET that first deletes the working directory and then gets the latest code. Have a look at CruiseControl.NET\'s source code for examples of how to write a source control provider.</p>\n\n<p>If you want to delete the working directory <em>after</em> the latest code is retrieved from source control, then you can use CruiseControl.NET\'s <a href="http://confluence.public.thoughtworks.org/display/CCNET/Executable+Task" rel="nofollow noreferrer">executable task</a> by running "cmd /c del directoryname".</p>\n'}, {'answer_id': 26968, 'author': 'Ian Patrick Hughes', 'author_id': 2213, 'author_profile': 'https://Stackoverflow.com/users/2213', 'pm_score': 0, 'selected': False, 'text': '<p>In the ASP.NET work, for me, the easiest way I do it (which allows me to hit either MSBUild or NAnt depending upon the project) was to roll my own exe that takes an argument which I pass in with a bat file fired by CC.NET. It\'s not the safest thing in the world, but if you have total control over your automated build machine; it\'s not too shabby. Quick and reusable.</p>\n\n<p>Drop in the exe somewhere that does the recursive delete:\n<br><br><code>\nstatic void Main(string[] args)</p>\n\n<pre><code>{\n        for (int n = 0; n &lt; args.Length; n++)\n        {\n            if (Directory.Exists(args[n].ToString()))\n            {\n                Directory.Delete(args[n].ToString(), true);\n            }\n\n        }\n\n\n}\n</code></pre>\n\n<p></code>\n<br><br>\nDrop it in somewhere multiple files can pass arguments to it and just write a custom .bat file for each project. So my task block looks like this:\n<br><br></p>\n\n<pre>\n&lt;tasks&gt;\n    &lt;msbuild&gt;\n        &lt;executable&gt;C:\\WINDOWS\\Microsoft.NET\\Framework\\v3.5\\MSBuild.exe&lt;/executable&gt;\n        &lt;workingDirectory&gt;Z:\\WorkingDirectory&lt;/workingDirectory&gt;\n        &lt;projectFile&gt;YourSolution.sln&lt;/projectFile&gt;\n        &lt;logger&gt;C:\\Program Files\\CruiseControl.NET\\server\\ThoughtWorks.CruiseControl.MsBuild.dll&lt;/logger&gt;\n    &lt;/msbuild&gt;\n    &lt;exec&gt;\n        &lt;executable&gt;Z:\\SomePathToBuildScripts\\YourCustomBat.bat&lt;/executable&gt;\n    &lt;/exec&gt;\n&lt;/tasks&gt;\n</pre>\n\n<p><br><br>\nThen the final step is setting up that .bat file to perform the delete/rebuild functions after use. In the bat file just make sure you rebuild ("MD") the directories you deleted if youexpect to publish a site back to them. On our dev boxes I found this to be the best way to prevent the beloved Frankenbuild.</p>\n'}, {'answer_id': 27202, 'author': 'Tom Mayfield', 'author_id': 2314, 'author_profile': 'https://Stackoverflow.com/users/2314', 'pm_score': 0, 'selected': False, 'text': '<p>The way I\'ve done this in the past is to not have CC.Net checkout source itself. Instead, there are two <code>&lt;msbuild&gt;</code> elements for the project, the first one calling a build target that runs <a href="http://svn.collab.net/repos/svn/trunk/contrib/client-side/svn-clean" rel="nofollow noreferrer">svn-clean.pl</a> (compiled to .exe), and then updates the source using svn.exe.  The second <code>&lt;msbuild&gt;</code> element starts the main build process.</p>\n\n<p>You can easily replace svn-clean with a delete command.  For my projects, deleting chaff from a checkout has always been faster than checking out a fresh working copy.</p>\n\n<p>The two msbuild elements are necessary because the main project build file is often updated. This is important because updates to your build file(s) will only be reloaded if you start a new msbuild process.</p>\n\n<p>This setup breaks down when I (very rarely) move or change the dependencies of that clean-and-update build target to the extent that the msbuild process would need to reload for valid instructions to run the clean-and-update target.  When this happens, I stop CC.Net before committing, go into the CC.Net server, and do an \'svn update\' by hand.</p>\n\n<p>Sidelight: It could well be that CC.Net has a natural clean-before-build operation by now.  I\'ve since moved to TeamCity, which is configurable to do this every build or only when the developer chooses (e.g., when you know you\'ve made a change that would not update cleanly--svn moves of directories with build products comes to mind).</p>\n'}]
['https://Stackoverflow.com/questions/26925', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1638/']