Legend

Class
Struct
Enum
Interface
Delegate
Constructor
Method
Property
Event
Field

Static method: int RunPostBuildChecks(string, params Assembly[])

Declaration

public static int RunPostBuildChecks(
    string sourcePath,
    params Assembly[] assemblies
)

Summary

Runs all post-build checks defined in the specified assemblies. This is intended to be run as a post-build event. See remarks for details.

Parameters

stringsourcePath Specifies the path to the folder containing the C# source files.
Assembly[]assemblies Specifies the compiled assemblies from which to run post-build checks.

Returns

1 if any errors occurred, otherwise 0.

Remarks

In non-DEBUG mode, does nothing and returns 0.

Intended use is as follows:

  • Add the following line to your project's post-build event:

    "$(TargetPath)" --post-build-check "$(SolutionDir)."
  • Add the following code at the beginning of your project's Main() method:

    if (args.Length == 2 && args[0] == "--post-build-check")
        return PostBuildChecker.RunPostBuildChecks(args[1], Assembly.GetExecutingAssembly());

    If your project entails several assemblies, you can specify additional assemblies in the call to PostBuildChecker.RunPostBuildChecks(string, params Assembly[]). For example, you could specify typeof(SomeTypeInMyLibrary).Assembly.

  • Add post-build check methods to any type where they may be relevant. For example, you might use code similar to the following:

    #if DEBUG
        private static void PostBuildCheck(IPostBuildReporter rep)
        {
            if (somethingWrong())
                rep.Error("Error XYZ occurred.", "class", "Gizmo");
        }
    #endif

    The method is expected to have one parameter of type IPostBuildReporter, a return type of void, and it is expected to be static and non-public. Errors and warnings can be reported by calling methods on said IPostBuildReporter object. (In the above example, PostBuildChecker will attempt to find a class called Gizmo to link the error message to a location in the source.) Throwing an exception will also report an error.