Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add | Adding Net6 support and dropping netcoreapp3.1 #1704

Merged
merged 4 commits into from Oct 22, 2022

Conversation

JRahnama
Copy link
Member

@JRahnama JRahnama commented Aug 9, 2022

This PR is ready for review. The tests are passing on a parallel pipeline built for net6.

There are two major changes in this PR:

  1. Support for netcoreapp3.1 is dropped.
  2. Support for net6.0 is added.

I have left comments inside the changes wherever I was not sure, or change needed some explanation.

tools/props/Versions.props Outdated Show resolved Hide resolved
tools/props/Versions.props Outdated Show resolved Hide resolved
@JRahnama JRahnama added 📃 Documentation Use this label for any documentation changes and removed 📃 Documentation Use this label for any documentation changes labels Aug 10, 2022
@JRahnama JRahnama added this to To Do in SqlClient v5.1 Aug 10, 2022
@JRahnama JRahnama modified the milestones: 5.1.0, 5.1.0-preview1 Aug 10, 2022
@JRahnama JRahnama marked this pull request as ready for review September 6, 2022 23:40
@JRahnama JRahnama changed the title Draft | Adding Net6 support to the driver Add | Adding Net6 support to the driver Sep 6, 2022
@ErikEJ
Copy link
Contributor

ErikEJ commented Sep 25, 2022

Fingers crossed this gets in soon!

@JRahnama
Copy link
Member Author

Fingers crossed this gets in soon!

I will do my best to add net6 to our pipelines to see if the tests are passing fine.

@codecov
Copy link

codecov bot commented Sep 28, 2022

Codecov Report

Base: 71.49% // Head: 65.38% // Decreases project coverage by -6.10% ⚠️

Coverage data is based on head (cb9cbc2) compared to base (02daa6f).
Patch coverage: 71.42% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1704      +/-   ##
==========================================
- Coverage   71.49%   65.38%   -6.11%     
==========================================
  Files         290      290              
  Lines       61109    61236     +127     
==========================================
- Hits        43692    40042    -3650     
- Misses      17417    21194    +3777     
Flag Coverage Δ
addons 0.00% <ø> (-92.39%) ⬇️
netcore 69.25% <71.42%> (-5.83%) ⬇️
netfx 63.65% <81.81%> (-5.67%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs 62.42% <0.00%> (-21.44%) ⬇️
...core/src/Microsoft/Data/SqlClient/SqlDataReader.cs 71.36% <ø> (-1.90%) ⬇️
...icrosoft/Data/SqlClient/SqlDelegatedTransaction.cs 45.12% <ø> (-1.11%) ⬇️
...crosoft/Data/SqlClient/SqlInternalConnectionTds.cs 72.76% <ø> (-0.13%) ⬇️
...ore/src/Microsoft/Data/SqlClient/SqlTransaction.cs 90.00% <ø> (ø)
...c/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs 53.61% <ø> (ø)
...t/src/Microsoft/Data/Common/AdapterUtil.Windows.cs 66.66% <ø> (ø)
...SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs 67.56% <ø> (-0.83%) ⬇️
...viderBase/DbConnectionPoolAuthenticationContext.cs 41.66% <ø> (ø)
...ft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs 88.37% <ø> (ø)
... and 74 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

tools/props/Versions.props Outdated Show resolved Hide resolved
tools/props/Versions.props Outdated Show resolved Hide resolved
<dependency id="System.Text.Encoding.CodePages" version="6.0.0" exclude="Compile" />
<dependency id="System.Text.Encodings.Web" version="6.0.0" />
<dependency id="System.Resources.ResourceManager" version="4.3.0" />
<dependency id="System.Security.Cryptography.Cng" version="5.0.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please reflect dependency version updates in this file, for all groups.

@@ -140,6 +140,8 @@ dotnet_diagnostic.CA1063.severity = silent
# CA2100: Review SQL queries for security vulnerabilities
dotnet_diagnostic.CA2100.severity = silent

dotnet_diagnostic.CA1416.severity = silent
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET 5.0 added new attributes, SupportedOSPlatformAttribute and UnsupportedOSPlatformAttribute, to annotate platform-specific APIs. Both attributes can be instantiated with or without version numbers as part of the platform name. They can also be applied multiple times with different platforms. However, SqlClient currently is following a different structure for adding related files for different platforms.

#elif NETCOREAPP
public override void Rollback(string transactionName)
#endif
{ }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after net5.0 System.Data.Common.DbTransaction added Rollback(string) and Save(string). NetStandard does not support that change.

</PropertyGroup>
<PropertyGroup Condition="'$(TargetGroup)' == 'netstandard'">
<DefineConstants>$(DefineConstants);NETSTANDARD;</DefineConstants>
</PropertyGroup>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using bult-in constants instead of creating new ones.

#else
keySizeInBytes= RSAPublicKey.KeySize / 8;
#endif

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PublicKey.Key is obsolete. Currently GetRSAPublicKey is being used but using DSAKey might be added in future.

@@ -223,7 +223,7 @@ public static void Test_WithDecimalValue_ShouldReturnDecimal()
var cmd = new SqlCommand("select @foo", conn);
cmd.Parameters.AddWithValue("@foo", new SqlDecimal(0.5));
var result = (decimal)cmd.ExecuteScalar();
Assert.Equal(result, (decimal)0.5);
Assert.Equal((decimal)0.5, result);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

upgrading xunit to 2.4.2 discovered these mistakes. expected values needs to be the first and actual value has to come second.

@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be changed to <TargetFramework> and it will eliminate the need to specifying framework on build time on test pipelines.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using TargetFramework would mean that we don't build this for netfx, is that correct? and if so is it not being needed for netfx intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, This is for tests builds on Unix,. Currently when you try to build the database for the test suit, Northwind, you need to run this project by specifying the dotnet run -f net6.0, by doing so the need to specifying the TFM in dotnet command goes away.

@@ -48,7 +48,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="$(SystemRuntimeInteropServicesRuntimeInformationVersion)" />
<PackageReference Include="xunit" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(XunitVersion)" />
<PackageReference Include="xunit.runner.visualstudio" Version="$(xunitrunnervisualstudioVersion)" />
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xunit.runner.visualstudio now has a different version than xunit itself.

@@ -3,7 +3,7 @@
<PropertyGroup Condition="'$(GeneratePlatformNotSupportedAssembly)' == 'true' OR '$(GeneratePlatformNotSupportedAssemblyMessage)' != ''">
<!-- Tell ResolveMatchingContract to run and resolve contract to project reference -->
<ResolveMatchingContract>true</ResolveMatchingContract>
<NotSupportedSourceFile>$(IntermediateOutputPath)$(AssemblyName).notsupported.cs</NotSupportedSourceFile>
<NotSupportedSourceFile>$(IntermediateOutputPath)\$(TargetFramework)\$(AssemblyName).notsupported.cs</NotSupportedSourceFile>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since System.Data.Common.DbTransaction is changed for net5 by adding RollBack(string) and Save(string) we cannot have one file for netcore and netstandard. It will complain that there is no suitable method to be overridden for netstandard. Taking the notsupported file inside each framework solves that issue. I would appreciate all other ideas regarding the impact of this change.
@cheenamalhotra @David-Engel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One notsupported.cs file for each build target is the safe way to do this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may not be understanding the problem, but in Npgsql this is just a tiny #ifdef:

#if NET5_0_OR_GREATER
    public override void Save(string name)
#else
    public void Save(string name)
#endif
    {

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@roji I noticed I did not provide more input on the question. As you have mentioned we have done the same in the code. The problem/question starts when generating notsupported files using GenAPI. Previously there was one Microsoft.Data.SqlClient.notSupported file for netcore and netstandards and one for netfx. By this change GenAPI complains that there is no suitable method to override for these 2 methods. I made the pattern so each TFM gets a not supported file and I was wondering if that will cause some issues in future.

@JRahnama JRahnama requested review from ErikEJ, Wraith2, cheenamalhotra and lcheunglci and removed request for ErikEJ and Wraith2 October 20, 2022 06:17
@JRahnama JRahnama requested review from ErikEJ and Wraith2 and removed request for ErikEJ October 20, 2022 06:18
@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 20, 2022

LGTM

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 20, 2022

228 changed files??

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 20, 2022

Looks good to me in general. It's a complex set of changes so I'm sure we'll find runtime things that need to be fixed once we've got this merged but i think we just need to get on and track those down as we find them.

@JRahnama
Copy link
Member Author

228 changed files??

that was a mistake I did while addressing some conflicts. The PR has been opened for a very long time and there were several conflicts. I had to force push a new clone to fix that issue. it is 38 files.

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 20, 2022

@JRahnama yeah. I realised. Looking forward to getting this in so work on DateOnly and TimeOnly can get done before EF Core 8.

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 20, 2022

@JRahnama yeah. I realised. Looking forward to getting this in so work on DateOnly and TimeOnly can get done before EF Core 8.

If you want to do Date and Time i'll work on SqlBatch

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 20, 2022

@Wraith2 Sure, willing to give it a try.

@JRahnama JRahnama changed the title Add | Adding Net6 support to the driver Add | Adding Net6 support and dropping netcoreapp3.1 Oct 20, 2022
SqlClient v5.1 automation moved this from To Do to Review Approved Oct 21, 2022
@JRahnama JRahnama merged commit 20d4c19 into dotnet:main Oct 22, 2022
SqlClient v5.1 automation moved this from Review Approved to Done Oct 22, 2022
@Wraith2
Copy link
Contributor

Wraith2 commented Oct 22, 2022

Yay!

@ErikEJ
Copy link
Contributor

ErikEJ commented Oct 22, 2022

Amazing!

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 24, 2022

I think a reference got missed somewhere around the functional tests. If I try to build locally I get this:

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1805,5): error : Project 'E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\add-ons\AzureKeyVaultProv
ider\Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.csproj' targets 'net6.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v3.1'. [E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj]

build script i use is buildandrun.bat from above root.

@echo off

set netcore=net6.0
set config=Release

msbuild /t:clean
msbuild /p:Configuration=%config%
msbuild /t:BuildTestsNetCore /p:TargetNetCoreVersion=%netcore% /p:Configuration=%config%

call :pauseOnError  dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" /p:Platform="AnyCPU" /p:Configuration="%config%" /p:TestTargetOS="Windowsnetcoreapp" /p:TargetNetCoreVersion=%netcore%  --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests"

goto :eof

:pauseOnError
%*
if ERRORLEVEL 1 pause
goto :eof

@JRahnama
Copy link
Member Author

JRahnama commented Oct 24, 2022

I think a reference got missed somewhere around the functional tests. If I try to build locally I get this:

C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(1805,5): error : Project 'E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\add-ons\AzureKeyVaultProv
ider\Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.csproj' targets 'net6.0'. It cannot be referenced by a project that targets '.NETCoreApp,Version=v3.1'. [E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj]

build script i use is buildandrun.bat from above root.

@echo off

set netcore=net6.0
set config=Release

msbuild /t:clean
msbuild /p:Configuration=%config%
msbuild /t:BuildTestsNetCore /p:TargetNetCoreVersion=%netcore% /p:Configuration=%config%

call :pauseOnError  dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" /p:Platform="AnyCPU" /p:Configuration="%config%" /p:TestTargetOS="Windowsnetcoreapp" /p:TargetNetCoreVersion=%netcore%  --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonwindowstests"

goto :eof

:pauseOnError
%*
if ERRORLEVEL 1 pause
goto :eof

Interesting. Can you try building the test with -p:TF=net6.0 or as you have been doing /p:TF=net6.0 instead of TargetNetCoreVersion to see if that solves the issue?

@Wraith2
Copy link
Contributor

Wraith2 commented Oct 24, 2022

Using TF works for netfx. for net6.0 it seems to mostly work but then can't find the output functional tests.

Test run for E:\Programming\csharp7\SqlClient\artifacts\Project\bin\Windows_NT\Debug.AnyCpu.FunctionalTests\net6.0\FunctionalTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

The test source file "E:\Programming\csharp7\SqlClient\artifacts\Project\bin\Windows_NT\Debug.AnyCpu.FunctionalTests\net6.0\FunctionalTests.dll" provided was not found.
     1>Project "E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlC
       lient.Tests.csproj" on node 1 (VSTest target(s)).
     1>DispatchToInnerBuildsWithVSTestTarget:
         Build continuing because "ContinueOnError" on the task "MSBuild" is set to "ErrorAndContinue".
     1>Done Building Project "E:\Programming\csharp7\SqlClient\src\Microsoft.Data.SqlClient\tests\FunctionalTests\Micro
       soft.Data.SqlClient.Tests.csproj" (VSTest target(s)) -- FAILED.

@JRahnama
Copy link
Member Author

@Wraith2 I was not able to reproduce the issue you mentioned, and pipelines are working well. I saw that error while I was working on the pipeline. It was because TargetGroup was not defined properly. Can you make a fresh clone and test the scenario again please?

@JRahnama JRahnama deleted the net6-build branch October 31, 2022 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants