Cleanbuild Sample

Sample Overview

This sample illustrates obtaining standard output and standard error from a console application without deadlocking. 

The sample can be used to clean up a Shared Source CLI (SSCLI) build environment of all files generated during the build. It does this by using the tar application to list the contents of the SSCLI TAR file and comparing that list to the existing files in the sscli directory.  A script is generated that will delete the files that were not originally included with the archive; running that script deletes the build-generated files.

Caution: The script created by this sample will delete files.  The user takes responsibility for understanding the functionality of the sample and for reading the deletion script before running it.

When the sample runs, it asks the user for the following information:

The sample uses a class named ConsoleProcess that is a wrapper class over the Process class. The advantage of the ConsoleProcess class is that it provides WaitForOutput() methods for both standard error and standard output as well as access to the underlying Process object that has the WaitForExit() method. This allows the developer to wait until the process is terminated and all output is finished before working with the output. The console output synchronization is handled using ThreadPool objects and ManualResetEvent instances.

After the user has executed the sample application, it stores the input settings in an XML file in the directory in which it was run. Subsequent executions will use this information automatically.

The sample also supports the following command-line options that can be used to override the settings stored in the settings file:

Option Description
-? Outputs usage banner to the console.
-d:deletionfilepath Specifies location of the deletion batch file or script in deletionfilepath.
-e:SSCLIrootdirectory Specifies the path to the SSCLI root directory in SSCLIrootdirectory.
-k Kills the current settings file.
-t:TarFilePath Specifies the path to the TAR file in TarFilePath.
-v Turns on verbose mode.

Sample Source and Build Output Locations

The sample source is found in sscli\samples\utilities\cleanbuild. 

The source file is:

The build output location is %TARGETCOMPLUS%\samples\utilities\cleanbuild. The output file is an executable assembly named cleanbuild.exe.

Building the Sample

All samples are built from the buildall script. 

You can also build all the samples by switching to the root of the sample directory, sscli\samples, and typing build -c.

You can build this specific sample by switching to the sample directory and typing build -c.

Running the Sample

These steps require that the Shared Source CLI (SSCLI) be already built and functional.

  1. Run env.bat, or source the env.csh or env.sh script files, depending on your platform.
  2. Switch to the %TARGETCOMPLUS%\samples\utilities\cleanbuild directory.
  3. Type the following command:

    clix cleanbuild.exe


Copyright (c) 2002 Microsoft Corporation. All rights reserved.