Skip to content

Commit

Permalink
SNOW-798828: Target .NET Standard 2.0 (#867)
Browse files Browse the repository at this point in the history
### Description
Change the target framework to .NET Standard 2.0

### Checklist
- [ ] Code compiles correctly
- [ ] Code is formatted according to [Coding
Conventions](../CodingConventions.md)
- [ ] Created tests which fail without the change (if possible)
- [ ] All tests passing (`dotnet test`)
- [ ] Extended the README / documentation, if necessary
- [ ] Provide JIRA issue id (if possible) or GitHub issue id in PR name
  • Loading branch information
sfc-gh-ext-simba-lf authored Jun 20, 2024
1 parent 1465bda commit 393762a
Show file tree
Hide file tree
Showing 12 changed files with 85 additions and 53 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:
cancel-in-progress: true

# uncomment to run the tests sequentially
#SEQUENTIAL_ENV: SEQUENTIAL_TEST_RUN
# SEQUENTIAL_ENV: SEQUENTIAL_TEST_RUN

jobs:
test-windows:
Expand All @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
dotnet: ['net8.0','net6.0', 'net472', 'net471']
dotnet: ['net6.0', 'net7.0', 'net8.0', 'net462', 'net471', 'net472', 'net48', 'net481']
cloud_env: ['AZURE', 'GCP', 'AWS']
steps:
- name: Checkout code
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
strategy:
fail-fast: false
matrix:
dotnet: ['net6.0', 'net8.0']
dotnet: ['net6.0', 'net7.0', 'net8.0']
cloud_env: ['AZURE', 'GCP', 'AWS']
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -151,7 +151,7 @@ jobs:
strategy:
fail-fast: false
matrix:
dotnet: ['net6.0', 'net8.0']
dotnet: ['net6.0', 'net7.0', 'net8.0']
cloud_env: ['AZURE', 'GCP', 'AWS']
steps:
- uses: actions/checkout@v4
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@

The Snowflake .NET connector supports the the following .NET framework and libraries versions:

- .NET Framework 4.6.2
- .NET Framework 4.7.1
- .NET Framework 4.7.2
- .NET Framework 4.8
- .NET Framework 4.8.1
- .NET 6.0
- .NET 7.0
- .NET 8.0

Disclaimer: While the connector targets netstandard2.0 and may work with versions in its [support matrix](https://learn.microsoft.com/en-us/dotnet/standard/net-standard?tabs=net-standard-2-0#select-net-standard-version), only the versions listed above are supported and tested by the connector

Please refer to the [Notice](#notice) section below for information about safe usage of the .NET Driver

# Coding conventions for the project
Expand Down Expand Up @@ -144,7 +150,7 @@ Logging description and configuration:
were not performed where the insecureMode flag was set to false, which is the default setting.
From version v2.1.5 CRL is working back as intended.

Note that the driver is now targeting .NET 6.0. When upgrading, you might also need to run “Update-Package -reinstall” to update the dependencies.
Note that the driver is now targeting .NET Standard 2.0. When upgrading, you might also need to run “Update-Package -reinstall” to update the dependencies.

See more:
* [Security Policy](SECURITY.md)
Expand Down
8 changes: 3 additions & 5 deletions Snowflake.Data.Tests/Snowflake.Data.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;net471;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">net6.0;net8.0</TargetFrameworks>
<RuntimeFrameworkVersion>6.0.0</RuntimeFrameworkVersion>
<RuntimeFrameworkVersion Condition="'$(TargetFramework)' == 'net8.0'">8.0.0</RuntimeFrameworkVersion>
<TargetFrameworks>net6.0;net7.0;net8.0;net462;net471;net472;net48;net481</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">net6.0;net7.0;net8.0;</TargetFrameworks>
<Title>Snowflake.Data.Tests</Title>
<Description>Snowflake Connector for .NET</Description>
<Company>Snowflake Computing, Inc</Company>
Expand Down
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/UnitTests/ArrowResultChunkTest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

Expand Down
16 changes: 12 additions & 4 deletions Snowflake.Data.Tests/UnitTests/ArrowResultSetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,18 @@ public void TestGetText()
[Test]
public void TestGetTextWithOneChar()
{
var testValues =
TestDataGenarator.AsciiCodes.ToCharArray()
.Append(TestDataGenarator.SnowflakeUnicode)
.ToArray();
char[] testValues;

#if NET462
var charArr = TestDataGenarator.AsciiCodes.ToList();
charArr.Add(TestDataGenarator.SnowflakeUnicode);
testValues = charArr.ToArray();
#else
testValues =
TestDataGenarator.AsciiCodes.ToCharArray()
.Append(TestDataGenarator.SnowflakeUnicode)
.ToArray();
#endif

PrepareTestCase(SFDataType.TEXT, 0, testValues);

Expand Down
36 changes: 36 additions & 0 deletions Snowflake.Data.Tests/UnitTests/SFEnvironmentTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using NUnit.Framework;
using Snowflake.Data.Core;

namespace Snowflake.Data.Tests.UnitTests
{
[TestFixture]
class SFEnvironmentTest
{
[Test]
public void TestRuntimeExtraction()
{
// Arrange
string expectedRuntime = ".NET";
string expectedVersion;

#if NETFRAMEWORK
expectedRuntime += "Framework";
expectedVersion = "4.8";
#elif NET6_0
expectedVersion = "6.0";
#elif NET7_0
expectedVersion = "7.0";
#elif NET8_0
expectedVersion = "8.0";
#endif

// Act
var actualRuntime = SFEnvironment.ExtractRuntime();
var actualVersion = SFEnvironment.ExtractVersion();

// Assert
Assert.AreEqual(expectedRuntime, actualRuntime);
Assert.AreEqual(expectedVersion, actualVersion);
}
}
}
4 changes: 0 additions & 4 deletions Snowflake.Data.Tests/Util/SnowflakeDbExceptionAssert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ public static void HasHttpErrorCodeInExceptionChain(Exception exception, HttpSta
case SnowflakeDbException se:
return se.ErrorCode == (int)expected;
case HttpRequestException he:
#if NETFRAMEWORK
return he.Message.Contains(((int)expected).ToString());
#else
return he.StatusCode == expected;
#endif
default:
return false;
}
Expand Down
1 change: 0 additions & 1 deletion Snowflake.Data/Core/ArrowResultChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ public override UTF8Buffer ExtractCell(int rowIndex, int columnIndex)
throw new NotSupportedException();
}

[Obsolete("ExtractCell with columnIndex is deprecated", false)]
public override UTF8Buffer ExtractCell(int columnIndex)
{
throw new NotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,6 @@ private static void StartBrowser(string url)
}

// The following code is learnt from https://brockallen.com/2016/09/24/process-start-for-urls-on-net-core/
#if NETFRAMEWORK
// .net standard would pass here
Process.Start(new ProcessStartInfo(url) { UseShellExecute = true });
#else
// hack because of this: https://github.com/dotnet/corefx/issues/10361
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Expand All @@ -226,7 +222,6 @@ private static void StartBrowser(string url)
{
throw new SnowflakeDbException(SFError.UNSUPPORTED_PLATFORM);
}
#endif
}

private static string ValidateAndExtractToken(HttpListenerRequest request)
Expand Down
6 changes: 1 addition & 5 deletions Snowflake.Data/Core/Authenticator/OktaAuthenticator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

Expand Down Expand Up @@ -82,11 +82,7 @@ async Task IAuthenticator.AuthenticateAsync(CancellationToken cancellationToken)
s_logger.Debug("step 4: Get SAML response from SSO");
var samlRestRequest = BuildSamlRestRequest(ssoUrl, onetimeToken);
samlRawResponse = await session.restRequester.GetAsync(samlRestRequest, cancellationToken).ConfigureAwait(false);
#if NETFRAMEWORK
_rawSamlTokenHtmlString = await samlRawResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
#else
_rawSamlTokenHtmlString = await samlRawResponse.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
#endif
s_logger.Debug("step 5: Verify postback URL in SAML response");
VerifyPostbackUrl();

Expand Down
31 changes: 19 additions & 12 deletions Snowflake.Data/Core/RestParams.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using System;
using System.Reflection;
using System.Runtime.InteropServices;

namespace Snowflake.Data.Core
{
Expand Down Expand Up @@ -59,23 +59,30 @@ static SFEnvironment()
ClientEnv = new LoginRequestClientEnv()
{
application = System.Diagnostics.Process.GetCurrentProcess().ProcessName,
osVersion = System.Environment.OSVersion.VersionString,
#if NETFRAMEWORK
netRuntime = "NETFramework",
netVersion = "4.7.1",
#else
netRuntime = "NETCore",
netVersion ="2.0",
#endif
osVersion = Environment.OSVersion.VersionString,
netRuntime = ExtractRuntime(),
netVersion = ExtractVersion(),
};

DriverVersion = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
DriverVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
DriverName = ".NET";
}

//temporary change for pretend as ODBC
internal static string DriverName { get; set; }
internal static string DriverVersion { get; set; }
internal static LoginRequestClientEnv ClientEnv { get; private set; }

internal static string ExtractRuntime()
{
return RuntimeInformation.FrameworkDescription.Substring(0, RuntimeInformation.FrameworkDescription.LastIndexOf(' ')).Replace(" ", "");
}

internal static string ExtractVersion()
{
var version = RuntimeInformation.FrameworkDescription.Substring(RuntimeInformation.FrameworkDescription.LastIndexOf(' ')).Replace(" ", "");
int secondPeriodIndex = version.IndexOf('.', version.IndexOf('.') + 1);
return version.Substring(0, secondPeriodIndex);
}
}
}
13 changes: 2 additions & 11 deletions Snowflake.Data/Snowflake.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net6.0;net471;net472</TargetFrameworks>
<TargetFrameworks Condition="'$(OS)' != 'Windows_NT'">net6.0;net8.0</TargetFrameworks>
<TargetFramework>netstandard2.0</TargetFramework>
<Title>Snowflake.Data</Title>
<PackageId>Snowflake.Data</PackageId>
<PackageLicenseUrl>https://github.com/snowflakedb/snowflake-connector-net/blob/master/LICENSE</PackageLicenseUrl>
Expand All @@ -26,7 +25,7 @@
<ItemGroup>
<PackageReference Include="Apache.Arrow" Version="14.0.2" />
<PackageReference Include="AWSSDK.S3" Version="3.7.0.4" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.6.0" />
<PackageReference Include="Google.Cloud.Storage.V1" Version="4.10.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.0" />
<PackageReference Include="Azure.Storage.Common" Version="12.12.0" />
<PackageReference Include="Mono.Unix" Version="7.1.0-final.1.21458.1" />
Expand All @@ -37,14 +36,6 @@
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net471' Or '$(TargetFramework)' == 'net472'">
<Reference Include="System.Net.Http" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(Configuration)' != 'Release'">
<InternalsVisibleTo Include="Snowflake.Data.Tests" />
<!--needed by Moq to be able to mock internal interfaces-->
Expand Down

0 comments on commit 393762a

Please sign in to comment.