Background I have created a Directory.Build.props
in my root repo folder with the following contents:
(背景信息我在根repo文件夹中创建了Directory.Build.props
,其内容如下:)
<Project>
<PropertyGroup>
<LangVersion>7.3</LangVersion>
</PropertyGroup>
</Project>
I need to prevent the usage of C# 8 syntax within our codebase, since it is targeting .Net 4.7.2 The above file sets the LangVersion
property for each project within the solution.
(我需要防止在我们的代码库中使用C#8语法,因为它的目标是.Net 4.7.2。上面的文件为解决方案中的每个项目设置LangVersion
属性。)
The problem
(问题)
Our codebase is big.
(我们的代码库很大。)
Many projects within one single solution with many programmers working in differents and / or adding new ones, this is not a problem itself but rather the fact that any programmer can override the LangVersion
within their own .csproj
file. (在一个解决方案中的许多项目中,有许多程序员从事不同的工作和/或添加新的程序员,这本身不是问题,而是任何程序员都可以在自己的.csproj
文件中覆盖LangVersion
的事实。)
I know we can stop those changes in the code review phase or by sending reminders every hour to all the programmers telling them not to use C# 8 for this specific project.
(我知道我们可以在代码审查阶段停止这些更改,也可以每小时向所有程序员发送提醒,告诉他们不要为该特定项目使用C#8,从而停止这些更改。)
But I was wondering if I could just celebrate their boldness by giving them a nice and handsome compiler error. (但是我想知道是否可以通过给他们一个漂亮而英俊的编译器错误来庆祝它们的大胆。)
Maybe with a custom code analizer with Roslyn?
(也许使用Roslyn的自定义代码分析器?)
Is there any way? (有什么办法吗?)
ask by taquion translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…