Hi,
Does anyone know of a utility to preprocess a C# source file without compiling it, in a similar fashion to using the -E flag in GCC? I tried using GCC - it successfully processes #if directives, but it chokes on any #region directives...
Ideally, I'd like to be able to run the tool over a .cs file to remove any #if blocks that evaluate to false, and optionally be able to flag whether to remove/leave intact comments, #region, #pragma directives etc.
To put this in context, I want to be able to a publish some source code that is part of a (much) larger project, whilst removing portions that are only relevant to the larger project. As an example, there are chunks of code that look like this:
#if (SUBPROJECT)
namespace SubProject
#else
namespace CompleteProject
#endif
{
public class SomeClass()
{
#if (!SUBPROJECT)
// This might call a method contained in an assembly that potentially
// won't be available to the sub-project, or maybe a method that hooks
// into a C library via P/Invoke...
string result = CallSomeCleverMethod();
#else
// This might call a method that performs a simplified version of the
// above, but does so without the above's assembly or P/Invoke
// dependencies...
string result = CallSomeSimpleMethod();
#endif
}
}
Please remember I'm not trying to do builds here - this is purely about publishing only a subset of a larger project's source code.
Any ideas/help appreciated.