Proj0054: Avoid changing compiler tools
MSBuild allows overriding the compiler tools via project properties. The following properties are detected by this rule:
| Lang. | Property |
|---|---|
| C# | <CscToolExe> |
| C# | <CscToolPath> |
| VB.NET | <VbcToolExe> |
| VB.NET | <VbcToolPath> |
| F# | <DotnetFscCompilerPath> |
Overriding the compiler tools can lead to unexpected behavior, especially when the project is built on different machines or environments. The compiler that is used may differ from the one expected by the SDK, leading to hard-to-diagnose build failures or subtle runtime issues. It also makes it harder to onboard new developers, as the toolchain is no longer determined by the SDK version alone.
Non-compliant
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<CscToolPath>C:\custom-roslyn\</CscToolPath>
<CscToolExe>csc.exe</CscToolExe>
</PropertyGroup>
</Project>
Compliant
If changing the compiler tools is necessary, it should be done via the command line:
dotnet build /p:CscToolPath=C:\custom-roslyn\ /p:CscToolExe=csc.exe