C#编译器:仅预处理(C# Compiler: Preprocess Only)

编程入门 行业动态 更新时间:2024-10-11 19:25:43
C#编译器:仅预处理(C# Compiler: Preprocess Only)

我计划将SubSpec (适用于<600行的xUnit的小型BDD扩展)分发为单个.cs文件而不是完整的dll。

SubSpec具有Silverlight和.NET风格,通过将其拉入CSC预处理器,从单个主文件构建SubSpec的发行版本将是理想的选择。 通过“发布版本”,我的意思是创建单个cs文件(不会有二进制版本)。 版本控制将由NuGet处理。

我知道C#编译器没有单独的预处理器(而是集成到管道中)。 是否有其他编译器/工具可以代替CSC使用?

I plan on distributing SubSpec ( a small BDD extension for xUnit which fits into < 600 lines) as a single .cs file instead of a full blown dll.

SubSpec has a Silverlight and .NET flavor, it would be ideal to build release versions of SubSpec from a single master file by pulling it through the CSC Preprocessor. By a "release version" I mean creating that single cs file (there will be no binary releases). Versioning will be handled by NuGet.

I understand that the C# compiler does not have a separate preprocessor (instead it's integrated into the pipeline). Are there other compilers/tools that I could use instead of CSC?

最满意答案

您的tools/install.ps1可以对C#文件执行所需的操作,因为它正在“安装”,因此它可以在包含期间处理它 - 可以通过在多个中使用嵌入式$(x)或$(expression)项目有条件地扩展的行字符串(可能通过将一组function扩展为C#代码作为[string] s形成表达式的组件),即模板化,或者您可以通过某些-replace s管道Get-Content 。 (你可能会看到人们使用T4的例子,但如果NuGet是送货卡车,不使用它是一种耻辱。如果你有冒险精神,你可以做一个真正的解析器(或者只是一个那个穷人的人也在那里。

另一种方法可能是使用partial类,并将右侧自定义文件中的install.ps1插槽放在主要部分旁边。

或者你只是没有努力尝试使用这样的技巧 优化你的#ifdef SILVERLIGHT 以重新找回你的马 。

Your tools/install.ps1 can do what it wants to the C# file as it's being 'installed' so it could process it during inclusion - that could be either by using embedded $(x) or $(expression) items in a multi-line string which expand conditionally (possibly by having a set of functions that expand to C# code as [string]s forming components of the expression), i.e., templating, or you can pipe the Get-Content through some -replaces. (You'll probably see examples around of people using T4 for that too, but if NuGet is the delivery truck, it's be a shame not to use it. If you're feeling adventurous, you could do a real parser (or just a poor man's one) in there too.

Another way may be to use partial classes and let the install.ps1 slot in the right customiser file beside the main one.

Or else you just havent tried hard enough to optimise out your #ifdef SILVERLIGHTs using tricks like this to get back on your horse.

更多推荐

本文发布于:2023-07-30 15:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338749.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:编译器   Compiler   Preprocess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!