Skip to content

Commit 17f80b6

Browse files
authored
Add .NET 5.0 target (#2246)
1 parent a6933a3 commit 17f80b6

File tree

4 files changed

+37
-28
lines changed

4 files changed

+37
-28
lines changed

src/Stripe.net/Infrastructure/Public/SystemNetHttpClient.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ public class SystemNetHttpClient : IHttpClient
2525
public const int DefaultMaxNumberRetries = 2;
2626

2727
private const string StripeNetTargetFramework =
28-
#if NETSTANDARD2_0
28+
#if NET5_0
29+
"net5.0"
30+
#elif NETSTANDARD2_0
2931
"netstandard2.0"
3032
#elif NET461
3133
"net461"

src/Stripe.net/Infrastructure/RuntimeInformation.cs

+22-25
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,15 @@ internal static class RuntimeInformation
2121

2222
internal static bool IsFullFramework => FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase);
2323

24-
internal static bool IsNetCore => FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(typeof(object).Assembly.Location);
24+
internal static bool IsNetCore
25+
=> ((Environment.Version.Major >= 5) || FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase))
26+
&& !string.IsNullOrEmpty(typeof(object).Assembly.Location);
2527

2628
/// <summary>
2729
/// "The north star for CoreRT is to be a flavor of .NET Core" -> CoreRT reports .NET Core everywhere.
2830
/// </summary>
2931
internal static bool IsCoreRT
30-
=> FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase)
32+
=> ((Environment.Version.Major >= 5) || FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase))
3133
&& string.IsNullOrEmpty(typeof(object).Assembly.Location); // but it's merged to a single .exe and .Location returns null here ;)
3234

3335
internal static bool IsRunningInContainer => string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
@@ -110,27 +112,7 @@ internal static string GetFullFrameworkVersion()
110112

111113
internal static string MapToReleaseVersion(string servicingVersion)
112114
{
113-
// the following code assumes that .NET 4.5 is the oldest supported version
114-
if (string.Compare(servicingVersion, "4.5.1") < 0)
115-
{
116-
return "4.5";
117-
}
118-
119-
if (string.Compare(servicingVersion, "4.5.2") < 0)
120-
{
121-
return "4.5.1";
122-
}
123-
124-
if (string.Compare(servicingVersion, "4.6") < 0)
125-
{
126-
return "4.5.2";
127-
}
128-
129-
if (string.Compare(servicingVersion, "4.6.1") < 0)
130-
{
131-
return "4.6";
132-
}
133-
115+
// the following code assumes that .NET 4.6.1 is the oldest supported version
134116
if (string.Compare(servicingVersion, "4.6.2") < 0)
135117
{
136118
return "4.6.1";
@@ -161,15 +143,30 @@ internal static string MapToReleaseVersion(string servicingVersion)
161143

162144
internal static string GetNetCoreVersion()
163145
{
164-
string runtimeVersion = TryGetCoreRuntimeVersion(out var version) ? version.ToString() : "?";
146+
if (TryGetCoreRuntimeVersion(out var version) && version >= new Version(5, 0))
147+
{
148+
return $".NET {version}";
149+
}
150+
else
151+
{
152+
string runtimeVersion = version != default ? version.ToString() : "?";
165153

166-
return $".NET Core {runtimeVersion}";
154+
return $".NET Core {runtimeVersion}";
155+
}
167156
}
168157

169158
internal static bool TryGetCoreRuntimeVersion(out Version version)
170159
{
171160
// we can't just use System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
172161
// because it can be null and it reports versions like 4.6.* for .NET Core 2.*
162+
163+
// for .NET 5+ we can use Environment.Version
164+
if (Environment.Version.Major >= 5)
165+
{
166+
version = Environment.Version;
167+
return true;
168+
}
169+
173170
string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
174171
if (TryGetVersionFromRuntimeDirectory(runtimeDirectory, out version))
175172
{

src/Stripe.net/Stripe.net.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<Version>39.29.0</Version>
99
<LangVersion>8</LangVersion>
1010
<Authors>Stripe, Jayme Davis</Authors>
11-
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
11+
<TargetFrameworks>net5.0;netstandard2.0;net461</TargetFrameworks>
1212
<AssemblyName>Stripe.net</AssemblyName>
1313
<PackageId>Stripe.net</PackageId>
1414
<PackageTags>stripe;payment;credit;cards;money;gateway;paypal;braintree</PackageTags>
@@ -39,6 +39,11 @@
3939
<CodeAnalysisRuleSet>..\_stylecop\StyleCopRules.ruleset</CodeAnalysisRuleSet>
4040
</PropertyGroup>
4141

42+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
43+
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
44+
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
45+
</ItemGroup>
46+
4247
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
4348
<PackageReference Include="Microsoft.Bcl.AsyncInterfaces" Version="1.1.0" />
4449
<PackageReference Include="Newtonsoft.Json" Version="11.0.1" />

src/StripeTests/StripeTests.csproj

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\..\netfx.props" />
33

44
<PropertyGroup>
5-
<TargetFrameworks>netcoreapp3.1;netcoreapp2.1;net461</TargetFrameworks>
5+
<TargetFrameworks>net5.0;netcoreapp3.1;netcoreapp2.1;net461</TargetFrameworks>
66
<AssemblyName>StripeTests</AssemblyName>
77
<LangVersion>8</LangVersion>
88
<PackageId>StripeTests</PackageId>
@@ -27,6 +27,11 @@
2727
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" />
2828
</ItemGroup>
2929

30+
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
31+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
32+
<PackageReference Include="System.Linq.Async" Version="4.1.1" />
33+
</ItemGroup>
34+
3035
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
3136
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
3237
<PackageReference Include="System.Linq.Async" Version="4.1.1" />

0 commit comments

Comments
 (0)