Skip to content

Commit b14a793

Browse files
authored
Fix SupportsTargetFramework for tests - 7.0.3xx (#30235)
2 parents f6760cc + 59447ae commit b14a793

File tree

2 files changed

+39
-47
lines changed

2 files changed

+39
-47
lines changed

src/Tests/Microsoft.NET.Publish.Tests/GivenThatWeWantToPublishAHelloWorldProject.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,16 @@ public void It_publishes_portable_apps_to_the_publish_folder_and_the_app_should_
7070
}
7171

7272
[Theory]
73+
[InlineData("netcoreapp1.1")]
7374
[InlineData("netcoreapp2.0")]
7475
[InlineData(ToolsetInfo.CurrentTargetFramework)]
7576
public void It_publishes_self_contained_apps_to_the_publish_folder_and_the_app_should_run(string targetFramework)
7677
{
78+
if (!EnvironmentInfo.SupportsTargetFramework(targetFramework))
79+
{
80+
return;
81+
}
82+
7783
var rid = EnvironmentInfo.GetCompatibleRid(targetFramework);
7884

7985
var helloWorldAsset = _testAssetsManager

src/Tests/Microsoft.NET.TestFramework/EnvironmentInfo.cs

Lines changed: 33 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,21 @@ public static string GetCompatibleRid(string targetFramework = null)
5454
// able to run on the current OS
5555
public static bool SupportsTargetFramework(string targetFramework)
5656
{
57-
var nugetFramework = NuGetFramework.Parse(targetFramework);
57+
NuGetFramework nugetFramework = null;
58+
try
59+
{
60+
nugetFramework = NuGetFramework.Parse(targetFramework);
61+
}
62+
catch
63+
{
64+
return false;
65+
}
66+
67+
if (nugetFramework == null)
68+
{
69+
return false;
70+
}
71+
5872
string currentRid = RuntimeInformation.RuntimeIdentifier;
5973

6074
string ridOS = currentRid.Split('.')[0];
@@ -125,9 +139,9 @@ public static bool SupportsTargetFramework(string targetFramework)
125139
{
126140
string restOfRid = currentRid.Substring(ridOS.Length + 1);
127141
string ubuntuVersionString = restOfRid.Split('-')[0];
128-
if (float.TryParse(ubuntuVersionString, out float ubuntuVersion))
142+
if (float.TryParse(ubuntuVersionString, System.Globalization.CultureInfo.InvariantCulture, out float ubuntuVersion))
129143
{
130-
if (ubuntuVersion > 16.04)
144+
if (ubuntuVersion > 16.04f)
131145
{
132146
if (nugetFramework.Version < new Version(2, 0, 0, 0))
133147
{
@@ -144,59 +158,31 @@ public static bool SupportsTargetFramework(string targetFramework)
144158
{
145159
string restOfRid = currentRid.Substring(ridOS.Length + 1);
146160
string osxVersionString = restOfRid.Split('-')[0];
147-
// From a string such as "10.14", get the second part, e.g. "14"
148-
if (osxVersionString.Contains('.'))
161+
if (float.TryParse(osxVersionString, System.Globalization.CultureInfo.InvariantCulture, out float osxVersion))
149162
{
150-
string osxVersionString2 = osxVersionString.Split('.')[1];
151-
if (int.TryParse(osxVersionString2, out int osxVersion))
163+
// .NET Core 1.1 - 10.11, 10.12
164+
// .NET Core 2.0 - 10.12+
165+
if (osxVersion <= 10.11f)
152166
{
153-
// .NET Core 1.1 - 10.11, 10.12
154-
// .NET Core 2.0 - 10.12+
155-
if (osxVersion <= 11)
156-
{
157-
if (nugetFramework.Version >= new Version(2, 0, 0, 0))
158-
{
159-
return false;
160-
}
161-
}
162-
else if (osxVersion == 12)
163-
{
164-
if (nugetFramework.Version < new Version(2, 0, 0, 0))
165-
{
166-
return false;
167-
}
168-
}
169-
else if (osxVersion > 12)
167+
if (nugetFramework.Version >= new Version(2, 0, 0, 0))
170168
{
171-
// .NET Core 2.0 is out of support, and doesn't seem to work with OS X 10.14
172-
// (it finds no assets for the RID), even though the support page says "10.12+"
173-
if (nugetFramework.Version < new Version(2, 1, 0, 0))
174-
{
175-
return false;
176-
}
169+
return false;
177170
}
178171
}
179-
}
180-
else
181-
{
182-
if (int.TryParse(osxVersionString, out int osxVersionMajor))
172+
else if (osxVersion == 10.12f)
183173
{
184-
// .NET 5 <= 11.0
185-
// .NET 6 <= 12
186-
// .NET 7 <= 13
187-
if (osxVersionMajor == 12)
174+
if (nugetFramework.Version < new Version(2, 0, 0, 0))
188175
{
189-
if (nugetFramework.Version < new Version(6, 0, 0, 0))
190-
{
191-
return false;
192-
}
176+
return false;
193177
}
194-
else if (osxVersionMajor > 12)
178+
}
179+
else if (osxVersion > 10.12f)
180+
{
181+
// .NET Core 2.0 is out of support, and doesn't seem to work with OS X 10.14
182+
// (it finds no assets for the RID), even though the support page says "10.12+"
183+
if (nugetFramework.Version < new Version(2, 1, 0, 0))
195184
{
196-
if (nugetFramework.Version < new Version(7, 0, 0, 0))
197-
{
198-
return false;
199-
}
185+
return false;
200186
}
201187
}
202188
}

0 commit comments

Comments
 (0)