问题描述
有谁知道一个实用程序来预处理的不编译它的C#源文件,以类似的方式在GCC使用-E标志?我试图使用GCC - 它成功处理#如果
指令,但它扼流圈上的任何#地区
指令...
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...
在理想情况下,我希望能够通过一个cs文件运行该工具,以消除任何#如果
计算结果为假,并任选能够标志是否删除/触动意见,#地区
,的#pragma 指令等。
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.
任何想法/帮助赞赏
推荐答案
原来使用GNU C预处理器(CPP),直接(而非通过GCC)提供了对输出更多的控制。用这种方法,我能够处理以合适的方式将源文件...
It turns out using the GNU C preprocessor (cpp) directly (rather than via gcc) provides more control over the output. Using this, I was able to process the source files in a suitable fashion...
下面是一个例子:
cpp -C -P -DSUBPROJECT Input.cs Output.cs
我就先提供与Visual Studio做同样的事情在C / C ++编译器,但一会儿......
I tried to get the C/C++ compiler provided with Visual Studio to do something similar, but gave up after a while...
这篇关于难道一个C#预处理工具存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!