简体   繁体   English

我可以根据C#版本制定预处理器指令吗?

[英]Can I make a preprocessor directive dependent on the C# version?

Is it possible to define a compile time constant that would say if code is compiled by C# 5 or C# 6? 是否可以定义一个编译时间常数,该常数将说明代码是由C#5还是C#6编译的? For example: 例如:

<DefineConstants Condition=" '$(???LanguageVersion???)' != 'v6.0' ">
     NOT_RUNNING_ON_6
</DefineConstants>

The constants defined in the project file are all set by MSBuild. 项目文件中定义的常量全部由MSBuild设置。 Which doesn't know the compiler version. 哪个不知道编译器版本。 It also only delegates all those properties to the Csc task. 它还仅将所有这些属性委派给Csc任务。 Since the compiler doesn't set constants based on the version, you simply cannot do that. 由于编译器不会根据版本设置常量,因此您根本无法做到这一点。

You could use a custom build process wrapper that determines the compiler version and changes the project file accordingly, though. 不过,您可以使用自定义构建过程包装程序来确定编译器版本并相应地更改项目文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM