You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I want to test my shared project (.shproj) in my .NET Core 3.1 test project, I must also explicitly include .NET Standard 2.0 symbols (NETSTANDARD; NETSTANDARD2_0; NETSTANDARD2_0_OR_GREATER; NETSTANDARD1_6_OR_GREATER; NETSTANDARD1_5_OR_GREATER; NETSTANDARD1_4_OR_GREATER; NETSTANDARD1_3_OR_GREATER; NETSTANDARD1_2_OR_GREATER; NETSTANDARD1_1_OR_GREATER; NETSTANDARD1_0_OR_GREATER) in my test project because this shared project is part of a larger class library that targets also .NET Standard 2.0 and the code depends on these symbols being defined. This causes a build of my .NET Core 3.1 test project to fail with the following errors:
1>C:\Users\Stipo.nuget\packages\polyfill\7.5.0\contentFiles\cs\netstandard2.0\Polyfill\StringPolyfill.cs(23,16,23,20): error CS0121: The call is ambiguous between the following methods or properties: 'string.Join(char, params string?[])' and 'string.Join(string?, params string?[])'
1>C:\Users\Stipo.nuget\packages\polyfill\7.5.0\contentFiles\cs\netstandard2.0\Polyfill\StringPolyfill.cs(34,16,34,20): error CS0121: The call is ambiguous between the following methods or properties: 'string.Join(char, params object?[])' and 'string.Join(string?, params object?[])'
1>C:\Users\Stipo.nuget\packages\polyfill\7.5.0\contentFiles\cs\netstandard2.0\Polyfill\StringPolyfill.cs(45,16,45,20): error CS0121: The call is ambiguous between the following methods or properties: 'string.Join(char, string?[], int, int)' and 'string.Join(string?, string?[], int, int)'
1>C:\Users\Stipo.nuget\packages\polyfill\7.5.0\contentFiles\cs\netstandard2.0\Polyfill\StringPolyfill.cs(56,16,56,20): error CS0121: The call is ambiguous between the following methods or properties: 'string.Join(char, IEnumerable)' and 'string.Join(string?, IEnumerable)'
because .NET Core 3.1 has string.Join overloads with both string and char separator parameter.
One solution would be to use new string([separator]) instead of new([separator]) in the StringPolyfill.cs.
But the better solution would be to use the #if with the ! not operator and with the list of symbols for the 'Applies to' table rows consistently in the entire Polyfill source code.
So, #if NETSTANDARD2_0 || NETFRAMEWORK in the StringPolyfill.cs would be replaced
with #if !(NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER) because the 'Applies to' table of the string.Join(Char, String[]) method has the following rows:
Another example is public static bool Contains(this string target, char value) from the Polyfill_String.cs.
Instead of #if NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0
use #if !(NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER) because the 'Applies to' table of the string.Contains(Char) method has the following rows:
Shproj are still supported but they don't get much love since since the same thing can be done with globbing.
But that is irrelevant. We have a shared code that our class library imports and we have a test project that also imports and tests that shared code. Class library also targets .NET Standard 2.0 so we have NETSTANDARD* symbols in that shared code. In our test project we test the behavior of the .NET Standard shared code by targeting .NET Core 3.1. Since NETSTANDARD* symbols are not automatically defined in the test project we define them explicitly and that breaks the build of the Polyfill code since both NETSTANDARD* and NETCOREAPP* symbols are defined.
If the ! not operator and symbols for the 'Applies to' table rows would be used consistenly in the Polyfill source code, the problem would not occur.
Describe the bug
When I want to test my shared project (.shproj) in my .NET Core 3.1 test project, I must also explicitly include .NET Standard 2.0 symbols (NETSTANDARD; NETSTANDARD2_0; NETSTANDARD2_0_OR_GREATER; NETSTANDARD1_6_OR_GREATER; NETSTANDARD1_5_OR_GREATER; NETSTANDARD1_4_OR_GREATER; NETSTANDARD1_3_OR_GREATER; NETSTANDARD1_2_OR_GREATER; NETSTANDARD1_1_OR_GREATER; NETSTANDARD1_0_OR_GREATER) in my test project because this shared project is part of a larger class library that targets also .NET Standard 2.0 and the code depends on these symbols being defined. This causes a build of my .NET Core 3.1 test project to fail with the following errors:
because .NET Core 3.1 has string.Join overloads with both string and char separator parameter.
One solution would be to use
new string([separator])
instead ofnew([separator])
in the StringPolyfill.cs.But the better solution would be to use the #if with the ! not operator and with the list of symbols for the 'Applies to' table rows consistently in the entire Polyfill source code.
So,
#if NETSTANDARD2_0 || NETFRAMEWORK
in the StringPolyfill.cs would be replacedwith
#if !(NETCOREAPP2_0_OR_GREATER || NETSTANDARD2_1_OR_GREATER)
because the 'Applies to' table of the string.Join(Char, String[]) method has the following rows:Another example is
public static bool Contains(this string target, char value)
from the Polyfill_String.cs.Instead of
#if NETFRAMEWORK || NETSTANDARD2_0 || NETCOREAPP2_0
use
#if !(NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER)
because the 'Applies to' table of the string.Contains(Char) method has the following rows:Using this approach consistently in the entire Polyfill source code aligns it better with the .NET documentation.
Minimal Repro
Extract the PolyfillSolution.zip and try building the MySharedProjectTest project.
The text was updated successfully, but these errors were encountered: