To improve the ability of this code fix to preserve compatibility with older versions of Visual Studio, it should only use the nameof operator in cases where the project specifies Visual Studio 2015 (or newer) as the preferred compiler. The easiest way to detect this is with the ToolsVersion attribute of the project file.
Here is an example where ToolsVersion is set to 14:
In the latter case, compatibility going back to Visual Studio 2010 is important for the project, but it would still be useful to have access to this code fix.
To improve the ability of this code fix to preserve compatibility with older versions of Visual Studio, it should only use the
nameof
operator in cases where the project specifies Visual Studio 2015 (or newer) as the preferred compiler. The easiest way to detect this is with theToolsVersion
attribute of the project file.Here is an example where
ToolsVersion
is set to 14:https://github.com/DotNetAnalyzers/DefaultValueDiagnostic/blob/master/DefaultParameterDiagnostic/DefaultParameterDiagnostic/DefaultParameterDiagnostic.csproj#L2
Here is an example where the
ToolsVersion
is set to 4:https://github.com/openstacknetsdk/openstack.net/blob/master/src/corelib/corelib.v3.5.csproj#L2
In the latter case, compatibility going back to Visual Studio 2010 is important for the project, but it would still be useful to have access to this code fix.