Our team have seen a few instances recently where code written by one specific dev doesn't build on the other devs' PCs, but we are struggling to figure out why. We all use VS2022, and the solution in question is a .NET 6 WPF application. I'm assuming the problem relates in some way to the .NET 6 SDK versions we're using, but I'm not sure where to check or how to verify this.
Here's one example of such a problem. The dev in question added an interface with internal
members, along with a concrete implementation were those members were 'public'. This built fine on his PC, yet the rest of us saw this error:
Property xyz cannot implicitly implement a non-public property from interface IFoobar
Here's another (more obscure) example, which appeared in this method signature:
private bool Run(
Isotope isotope,
[CallerArgumentExpression(nameof(isotope))] string isotopeName = null)
Again this code built fine on that one dev's PC, while the rest of us saw this error:
Cannot resolve symbol 'isotope'
(Note, the error was reported on the second argument line).
Thoughts welcome on what the cause might be!
Using
nameof
inside the an attribute on a method or parameter requires at least .NET 7 SDK (though[CallerArgumentExpression("isotope")]
should work for .NET 6). See the Extendednameof
scope feature spec for C# 11.By default the latest installed SDK is used so if the newer language feature has not required changes in the CLR the project should compile and run successfully. It seems that the developer has .NET 7 or .NET 8 SDK installed (run
dotnet --list-sdks
to check).You can check the SDK version used to build the project by running
dotnet --version
from the project folder.Note that you can force the same SDK version to be used for build by adding
global.json
file to project/solution. For example the following will force the same major version:Also possibly restricting C# language version used to C# 10 will do the trick also.