Skip to content

Commit

Permalink
Add | Adding Net6 support and dropping netcoreapp3.1 (#1704)
Browse files Browse the repository at this point in the history
  • Loading branch information
JRahnama committed Oct 22, 2022
1 parent f5eb391 commit 20d4c19
Show file tree
Hide file tree
Showing 44 changed files with 280 additions and 217 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Expand Up @@ -140,6 +140,9 @@ dotnet_diagnostic.CA1063.severity = silent
# CA2100: Review SQL queries for security vulnerabilities
dotnet_diagnostic.CA2100.severity = silent

# CA1416: Validate platform compatibility
dotnet_diagnostic.CA1416.severity = silent

[*.{csproj,vcxproj,vcxproj.filters,proj,nativeproj,locproj}]
indent_size = 2

Expand Down
12 changes: 6 additions & 6 deletions BUILDGUIDE.md
Expand Up @@ -102,7 +102,7 @@ msbuild -t:RunTests -p:configuration=Release
To specify custom target framework, use `TF` property:

```bash
msbuild -t:RunTests -p:configuration=Release -p:TF=net5.0
msbuild -t:RunTests -p:configuration=Release -p:TF=net7.0
msbuild -t:RunTests -p:configuration=Release -p:TF=net48
# Runs tests for specified target framework.
# TargetNetCoreVersion and TargetNetFxVersion are not to be used with TF property, they will take precedence over TF if provided.
Expand Down Expand Up @@ -285,9 +285,9 @@ msbuild -t:BuildTestsNetFx -p:TargetNetFxVersion=net462
```

```bash
msbuild -t:BuildTestsNetCore -p:TargetNetCoreVersion=netcoreapp3.1
msbuild -t:BuildTestsNetCore -p:TargetNetCoreVersion=net6.0
# Build the tests for custom TargetFramework (.NET Core)
# Applicable values: netcoreapp3.1 | net5.0 | net6.0
# Applicable values: net6.0 | net7.0 | net6.0
```

### Running Tests with custom target framework (traditional)
Expand All @@ -297,9 +297,9 @@ dotnet test -p:TargetNetFxVersion=net462 ...
# Use above property to run Functional Tests with custom TargetFramework (.NET Framework)
# Applicable values: net462 (Default) | net462 | net47 | net471 net472 | net48

dotnet test -p:TargetNetCoreVersion=netcoreapp3.1 ...
dotnet test -p:TargetNetCoreVersion=net6.0 ...
# Use above property to run Functional Tests with custom TargetFramework (.NET Core)
# Applicable values: netcoreapp3.1 | net5.0 | net6.0
# Applicable values: net6.0 | net7.0 | net6.0
```

## Using Managed SNI on Windows
Expand Down Expand Up @@ -389,7 +389,7 @@ Configure `runnerconfig.json` file with connection string and preferred settings

```bash
cd src\Microsoft.Data.SqlClient\tests\PerformanceTests
dotnet run -c Release -f netcoreapp3.1|net5.0
dotnet run -c Release -f net6.0|net7.0
```

_Only "**Release** Configuration" applies to Performance Tests_
94 changes: 47 additions & 47 deletions RunTests.cmd

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions build.proj
Expand Up @@ -16,11 +16,11 @@
<IsEnabledWindows Condition="'$(TargetsUnix)' == 'true'">false</IsEnabledWindows>
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsWindows)' == 'true'">Windows</TestOS>
<TestOS Condition="'$(TestTargetOS)' == '' AND '$(TargetsUnix)' == 'true'">Unix</TestOS>
<TF Condition="$(TF) == ''">netcoreapp3.1</TF> <!-- Default Target Framework -->
<TFGroup Condition="$(TF.StartsWith('net4'))">netfx</TFGroup>
<TFGroup Condition="$(TFGroup) == ''">netcore</TFGroup>
<TargetGroup Condition="$(TF.StartsWith('net4'))">netfx</TargetGroup>
<TargetGroup Condition="$(TargetGroup) == ''">netcoreapp</TargetGroup>
<TF Condition="$(TF) == ''">net6.0</TF> <!-- Default Target Framework -->
<TFGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TF)))' == '.NETFramework'">netfx</TFGroup>
<TFGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TF)))' == '.NETCoreApp'">netcore</TFGroup>
<TargetGroup Condition="'$(TFGroup)' == 'netfx'" >netfx</TargetGroup>
<TargetGroup Condition="'$(TFGroup)' == 'netcore'">netcoreapp</TargetGroup>
<TargetNetCoreVersion Condition="$(TargetGroup) == 'netcoreapp' AND $(TargetNetCoreVersion) == ''">$(TF)</TargetNetCoreVersion>
<TargetNetFxVersion Condition="$(TargetGroup) == 'netfx' AND $(TargetNetFxVersion) == ''">$(TF)</TargetNetFxVersion>
<GenerateNuget Condition="'$(GenerateNuget)' == ''">true</GenerateNuget>
Expand Down
Expand Up @@ -4,8 +4,8 @@
<AssemblyName>Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider</AssemblyName>
<AddOnName>AzureKeyVaultProvider</AddOnName>
<ProjectGuid>{9073ABEF-92E0-4702-BB23-2C99CEF9BDD7}</ProjectGuid>
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp')) OR $(TargetFramework.StartsWith('netstandard'))">netcoreapp</TargetGroup>
<TargetGroup Condition="$(TargetFramework.StartsWith('net4'))">netfx</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETCoreApp' OR '$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETStandard'">netcoreapp</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETFramework'">netfx</TargetGroup>
<Configurations>Debug;Release;</Configurations>
<Platforms>AnyCPU;x86;x64</Platforms>
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform)\$(AddOnName)</IntermediateOutputPath>
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.Data.SqlClient/add-ons/Directory.Build.props
Expand Up @@ -18,7 +18,7 @@
<PropertyGroup>
<TargetNetFxVersion Condition="'$(TargetNetFxVersion)' == ''">net462</TargetNetFxVersion>
<TargetNetStandardVersion Condition="'$(TargetNetStandardVersion)' == ''">netstandard2.0</TargetNetStandardVersion>
<TargetNetCoreVersion Condition="'$(TargetNetCoreVersion)' == ''">netcoreapp3.1</TargetNetCoreVersion>
<TargetNetCoreVersion Condition="'$(TargetNetCoreVersion)' == ''">net6.0</TargetNetCoreVersion>
</PropertyGroup>

<ItemGroup>
Expand All @@ -36,7 +36,7 @@
<Otherwise>
<PropertyGroup>
<TargetFrameworks Condition="'$(TestTargetOS)' == 'Windowsnetstandard' OR '$(TestTargetOS)' == 'Unixnetstandard'">netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition="'$(TestTargetOS)' == 'Windowsnetcoreapp' OR '$(TestTargetOS)' == 'Unixnetcoreapp'">netcoreapp3.1</TargetFrameworks>
<TargetFrameworks Condition="'$(TestTargetOS)' == 'Windowsnetcoreapp' OR '$(TestTargetOS)' == 'Unixnetcoreapp'">net6.0</TargetFrameworks>
<TargetFrameworks Condition="'$(TestTargetOS)' == 'Windowsnetfx'">net462</TargetFrameworks>
</PropertyGroup>
</Otherwise>
Expand Down
Expand Up @@ -1432,7 +1432,9 @@ public sealed partial class SqlException : System.Data.Common.DbException
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/State/*'/>
public byte State { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/GetObjectData/*'/>
#if !NET6_0_OR_GREATER
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
#endif
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo si, System.Runtime.Serialization.StreamingContext context) { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/ToString/*'/>
public override string ToString() { throw null; }
Expand Down Expand Up @@ -1762,9 +1764,18 @@ public sealed partial class SqlTransaction : System.Data.Common.DbTransaction
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Rollback1/*'/>
public override void Rollback() { }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Rollback2/*'/>
#if NET6_0_OR_GREATER
public override void Rollback(string transactionName) { }
#else
public void Rollback(string transactionName) { }
#endif

/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Save/*'/>
#if NET6_0_OR_GREATER
public override void Save(string savePointName) { }
#else
public void Save(string savePointName) { }
#endif
}
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRetryingEventArgs.xml' path='docs/members[@name="SqlRetryingEventArgs"]/SqlRetryingEventArgs/*' />
public sealed class SqlRetryingEventArgs : System.EventArgs
Expand Down
@@ -1,23 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition="$(ReferenceType)=='NetStandard' AND $(TargetNetStandardVersion)=='netstandard2.1'">netstandard2.1</TargetFrameworks>
<IntermediateOutputPath>$(ObjFolder)$(Configuration)\$(AssemblyName)\ref\</IntermediateOutputPath>
<OutputPath>$(BinFolder)$(Configuration)\$(AssemblyName)\ref\</OutputPath>
<DocumentationFile>$(OutputPath)\$(TargetFramework)\Microsoft.Data.SqlClient.xml</DocumentationFile>
<Product>Core $(BaseProduct)</Product>
<Configurations>Debug;Release;</Configurations>
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
<TargetGroup Condition="$(TargetFramework.StartsWith('netstandard'))">netstandard</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETCoreApp'">netcoreapp</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETStandard'">netstandard</TargetGroup>
<Platforms>AnyCPU;x64;x86</Platforms>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard' AND !$(TargetFramework.StartsWith('netstandard1.')) AND $(TargetFramework) != 'netstandard2.0'">
<DefineConstants>$(DefineConstants);NETSTANDARD21_AND_ABOVE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<DefineConstants>$(DefineConstants);NETCOREAPP</DefineConstants>
</PropertyGroup>
<ItemGroup>
<Compile Include="Microsoft.Data.SqlClient.cs" />
<Compile Include="Microsoft.Data.SqlClient.Manual.cs" />
Expand All @@ -31,4 +25,4 @@
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="$(MicrosoftIdentityClientVersion)" />
</ItemGroup>
</Project>
</Project>
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>Microsoft.Data.SqlClient</AssemblyName>
<TargetFrameworks>netcoreapp3.1;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks>net6.0;netstandard2.0;netstandard2.1</TargetFrameworks>
<TargetFrameworks Condition="$(ReferenceType)=='NetStandard' AND $(TargetNetStandardVersion)=='netstandard2.1'">netstandard2.1</TargetFrameworks>
<GeneratePlatformNotSupportedAssemblyMessage Condition="'$(OSGroup)' == 'AnyOS'">Microsoft.Data.SqlClient is not supported on this platform.</GeneratePlatformNotSupportedAssemblyMessage>
<OSGroup Condition="'$(OSGroup)' == ''">$(OS)</OSGroup>
<TargetsWindows Condition="'$(OSGroup)'=='Windows_NT'">true</TargetsWindows>
<TargetsUnix Condition="'$(OSGroup)'=='Unix'">true</TargetsUnix>
<!-- Allow explicit addition of the Compile files instead of all project files to be included by Default -->
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<TargetGroup Condition="$(TargetFramework.StartsWith('netcoreapp'))">netcoreapp</TargetGroup>
<TargetGroup Condition="$(TargetFramework.StartsWith('netstandard'))">netstandard</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETCoreApp'">netcoreapp</TargetGroup>
<TargetGroup Condition="'$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))'=='.NETStandard'">netstandard</TargetGroup>
<Configurations>Debug;Release;</Configurations>
<Platforms>AnyCPU;x64;x86</Platforms>
<IntermediateOutputPath>$(ObjFolder)$(Configuration).$(Platform)\$(AssemblyName)\netcore\</IntermediateOutputPath>
Expand All @@ -19,12 +19,6 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<Product>Core $(BaseProduct)</Product>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
<DefineConstants>$(DefineConstants);NETCOREAPP;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard'">
<DefineConstants>$(DefineConstants);NETSTANDARD;</DefineConstants>
</PropertyGroup>
<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
Expand Down
Expand Up @@ -79,7 +79,15 @@ public override byte[] DecryptColumnEncryptionKey(string masterKeyPath, string e

// Parse the path and get the X509 cert
X509Certificate2 certificate = GetCertificateByPath(masterKeyPath, isSystemOp: true);
int keySizeInBytes = certificate.PublicKey.Key.KeySize / 8;

RSA RSAPublicKey = certificate.GetRSAPublicKey();
int keySizeInBytes;
#if NETCOREAPP || NETSTANDARD2_1
DSA DSAPublicKey = certificate.GetDSAPublicKey();
keySizeInBytes = RSAPublicKey is not null ? RSAPublicKey.KeySize / 8 : DSAPublicKey.KeySize / 8;
#else
keySizeInBytes= RSAPublicKey.KeySize / 8;
#endif

// Validate and decrypt the EncryptedColumnEncryptionKey
// Format is
Expand Down Expand Up @@ -172,7 +180,15 @@ public override byte[] EncryptColumnEncryptionKey(string masterKeyPath, string e

// Parse the certificate path and get the X509 cert
X509Certificate2 certificate = GetCertificateByPath(masterKeyPath, isSystemOp: false);
int keySizeInBytes = certificate.PublicKey.Key.KeySize / 8;

RSA RSAPublicKey = certificate.GetRSAPublicKey();
int keySizeInBytes;
#if NETCOREAPP || NETSTANDARD2_1
DSA DSAPublicKey = certificate.GetDSAPublicKey();
keySizeInBytes = RSAPublicKey is not null ? RSAPublicKey.KeySize / 8 : DSAPublicKey.KeySize / 8;
#else
keySizeInBytes= RSAPublicKey.KeySize / 8;
#endif

// Construct the encryptedColumnEncryptionKey
// Format is
Expand Down
Expand Up @@ -3769,8 +3769,9 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r
SqlCommand command = (SqlCommand)state;
bool processFinallyBlockAsync = true;
bool decrementAsyncCountInFinallyBlockAsync = true;
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
// Check for any exceptions on network write, before reading.
Expand Down Expand Up @@ -3842,7 +3843,9 @@ private void PrepareForTransparentEncryption(CommandBehavior cmdBehavior, bool r
bool processFinallyBlockAsync = true;
bool decrementAsyncCountInFinallyBlockAsync = true;
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
// Check for any exceptions on network write, before reading.
Expand Down
Expand Up @@ -3472,7 +3472,9 @@ private bool TryReadInternal(bool setTimeout, out bool more)
SqlStatistics statistics = null;
using (TryEventScope.Create("SqlDataReader.TryReadInternal | API | Object Id {0}", ObjectID))
{
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif

try
{
Expand Down Expand Up @@ -4848,7 +4850,7 @@ public override Task<bool> ReadAsync(CancellationToken cancellationToken)
context = new ReadAsyncCallContext();
}

Debug.Assert(context.Reader == null && context.Source == null && context.Disposable == null, "cached ReadAsyncCallContext was not properly disposed");
Debug.Assert(context.Reader == null && context.Source == null && context.Disposable == default, "cached ReadAsyncCallContext was not properly disposed");

context.Set(this, source, registration);
context._hasMoreData = more;
Expand Down
Expand Up @@ -81,7 +81,9 @@ public void Initialize()
SqlInternalConnection connection = _connection;
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | Object Id {0}, Client Connection Id {1}, delegating transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
if (connection.IsEnlistedInTransaction)
Expand Down Expand Up @@ -144,7 +146,9 @@ public byte[] Promote()
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, promoting transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
lock (connection)
Expand Down Expand Up @@ -252,7 +256,9 @@ public void Rollback(SinglePhaseEnlistment enlistment)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Client Connection Id {1}, rolling back transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
lock (connection)
Expand Down Expand Up @@ -337,7 +343,9 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment)
{
SqlConnection usersConnection = connection.Connection;
SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Client Connection Id {1}, committing transaction.", ObjectID, usersConnection?.ClientConnectionId);
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
lock (connection)
Expand Down
Expand Up @@ -2283,7 +2283,9 @@ internal bool TryGetFedAuthTokenLocked(SqlFedAuthInfo fedAuthInfo, DbConnectionP
bool authenticationContextLocked = false;

// Prepare CER to ensure the lock on authentication context is released.
#if !NET6_0_OR_GREATER
RuntimeHelpers.PrepareConstrainedRegions();
#endif
try
{
// Try to obtain a lock on the context. If acquired, this thread got the opportunity to update.
Expand Down
Expand Up @@ -119,7 +119,11 @@ public override void Rollback()
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/RollbackTransactionName/*' />
#if NET6_0_OR_GREATER
public override void Rollback(string transactionName)
#else
public void Rollback(string transactionName)
#endif
{
using (DiagnosticTransactionScope diagnosticScope = s_diagnosticListener.CreateTransactionRollbackScope(_isolationLevel, _connection, InternalTransaction, transactionName))
{
Expand Down Expand Up @@ -151,7 +155,11 @@ public void Rollback(string transactionName)
}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Save/*' />
#if NET6_0_OR_GREATER
public override void Save(string savePointName)
#else
public void Save(string savePointName)
#endif
{
ZombieCheck();

Expand Down

0 comments on commit 20d4c19

Please sign in to comment.