Skip to content

Commit d4464ec

Browse files
committed
User Story 37654: Create Abstractions package
- Added empty Extensions package with some sample class and docs to demonstrate packaging. - Created CI stage to build, test, pack, and publish the Extensions NuGet package. - Updated downstream CI stages/jobs to use the Extensions package. - Updated build.proj Clean target to not delete packages/ dir. - Updated BUILDGUIDE with instructions for the Extensions package. - Cleaned up stale BUIDGUIDE sections. - Added temporary GitHub Discussion content so the team can review before posting it as a real Discussion. - Disable .pdb file inclusion in the application package. - Renamed Extensions package to Abstractions. - Updated README related to extensions design.
1 parent 30a2351 commit d4464ec

32 files changed

+1228
-173
lines changed

.editorconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ indent_size = 2
163163
indent_size = 2
164164

165165
# Xml files
166-
[*.{xml,stylecop,resx,ruleset}]
166+
[*.{xml,stylecop,resx,ruleset,slnx}]
167167
indent_size = 2
168168

169169
# Xml config files

BUILDGUIDE.md

Lines changed: 43 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -16,40 +16,47 @@ Once the environment is setup properly, execute the desired set of commands belo
1616

1717
### Targets
1818

19+
The following build targets are defined in `build.proj`:
20+
1921
|Target|Description|
2022
|-|-|
2123
|`BuildAllConfigurations`|Default target. Builds the .NET Framework and .NET drivers for all target frameworks and operating systems.|
24+
|`BuildAbstractionsPackage`|Restore, build, and pack the Abstractions package, publishing the resulting NuGet into `packages/`.|
2225
|`BuildNetCore`|Builds the .NET driver for all target frameworks.|
2326
|`BuildNetCoreAllOS`|Builds the .NET driver for all target frameworks and operating systems.|
2427
|`BuildNetFx`|Builds the .NET Framework driver for all target frameworks.|
2528
|`BuildTestsNetCore`|Builds tests for the .NET driver.|
2629
|`BuildTestsNetFx`|Builds tests for the .NET Framework driver.|
27-
|`Clean`|Cleans generated files.|
28-
|`Restore`|Restores Nuget packages.|
30+
|`Clean`|Cleans generated files, except for NuGet packages published to `packages/`.|
31+
|`CleanAll`|Cleans all generated files.|
32+
|`Restore`|Restores NuGet packages.|
2933
|`RunTests`|Runs the unit, functional, and manual tests for the .NET Framework and .NET drivers|
3034
|`RunUnitTests`|Runs just the unit tests for the .NET Framework and .NET drivers|
3135
|`RunFunctionalTests`|Runs just the functional tests for the .NET Framework and .NET drivers|
3236
|`RunManualTests`|Runs just the manual tests for the .NET Framework and .NET drivers|
3337
|`BuildAkv`|Builds the Azure Key Vault Provider package for all supported platforms.|
3438

35-
3639
### Parameters
40+
41+
The following parameters may be defined as MSBuild properties to configure the
42+
build:
43+
3744
|Name|Supported Values|Default|Description|
3845
|-|-|-|-|
3946
|`Configuration`|`Debug`, `Release`|`Debug`|Sets the release configuration.|
40-
|`BuildNetFx`|`true`, `false`|`true` (Windows), `false` (other)|If false, skips building the .NET Framework driver on Windows.|
4147
|`OSGroup`|`Unix`, `Windows_NT`, `AnyOS`|typically defaults to the client system's OS, unless using `BuildAllConfigurations` or an `AnyOS` specific target|The operating system to target.|
4248
|`Platform`|`AnyCPU`, `x86`, `x64`, `ARM`, `ARM64`|`AnyCPU`|May only be set when using package reference type or running tests.|
4349
|`TestSet`|`1`, `2`, `3`, `AE`|all|Build or run a subset of the manual tests. Omit (default) to target all tests.|
4450
|`DotnetPath`|Absolute file path to an installed `dotnet` version.|The system default specified by the path variable|Set to run tests using a specific dotnet version (e.g. C:\net6-win-x86\)|
4551
|`TF`|`net8.0`, `net462`, `net47`, `net471`, `net472`, `net48`, `net481`|`net8.0` in netcore, `net462` in netfx|Sets the target framework when building or running tests. Not applicable when building the drivers.|
4652
|`ResultsDirectory`|An absolute file path|./TestResults relative to current directory|Specifies where to write test results.|
4753

48-
4954
## Example Workflows using MSBuild (Recommended)
55+
5056
Using the default configuration and running all tests:
5157

5258
```bash
59+
msbuild -t:BuildAbstractionsPackage
5360
msbuild
5461
msbuild -t:BuildTestsNetFx -p:TF=net462
5562
msbuild -t:BuildTestsNetCore
@@ -59,28 +66,31 @@ msbuild -t:RunTests
5966
Using the Release configuration:
6067

6168
```bash
62-
msbuild -p:configuration=Release
63-
msbuild -t:BuildTestsNetFx -p:TF=net462 -p:configuration=Release
64-
msbuild -t:BuildTestsNetCore -p:configuration=Release
65-
msbuild -t:RunTests -p:configuration=Release
69+
msbuild -t:BuildAbstractionsPackage -p:Configuration=Release
70+
msbuild -p:Configuration=Release
71+
msbuild -t:BuildTestsNetFx -p:TF=net462 -p:Configuration=Release
72+
msbuild -t:BuildTestsNetCore -p:Configuration=Release
73+
msbuild -t:RunTests -p:Configuration=Release
6674
```
6775

6876
Running only the unit tests:
6977

7078
```bash
79+
msbuild -t:BuildAbstractionsPackage
7180
msbuild
7281
msbuild -t:BuildTestsNetFx -p:TF=net462
7382
msbuild -t:BuildTestsNetCore
7483
msbuild -t:RunUnitTests
7584
```
7685

77-
Using a specific dotnet version/architecture:
86+
Using a specific .NET runtime to run tests:
7887

7988
```bash
80-
msbuild -p:configuration=Release
81-
msbuild -t:BuildTestsNetFx -p:TF=net462 -p:configuration=Release
82-
msbuild -t:BuildTestsNetCore -p:configuration=Release
83-
msbuild -t:RunTests -p:configuration=Release -p:DotnetPath=C:\net8-win-x86\
89+
msbuild -t:BuildAbstractionsPackage
90+
msbuild
91+
msbuild -t:BuildTestsNetFx -p:TF=net462
92+
msbuild -t:BuildTestsNetCore
93+
msbuild -t:RunTests -p:DotnetPath=C:\net8-win-x86\
8494
```
8595

8696
### Running Manual Tests
@@ -119,15 +129,13 @@ Manual Tests require the below setup to run:
119129
|IsManagedInstance | (Optional) When set to `true` **TVP** related tests will use on non-Azure bs files to compare test results. this is needed when testing against Managed Instances or TVP Tests will fail on Test set 3. The default value is `false`. |
120130
|PowerShellPath | The full path to PowerShell.exe. This is not required if the path is present in the PATH environment variable. | `D:\\escaped\\absolute\\path\\to\\PowerShell.exe` |
121131

122-
123132
## Example workflows using the Dotnet SDK
124133

125-
#### Run Functional Tests
134+
### Run Functional Tests
126135

127136
- Windows (`netfx x86`):
128137

129138
```bash
130-
msbuild
131139
dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="x86" -p:Configuration="Release" -p:TestTargetOS="Windowsnetfx" --no-build -v n --filter "category!=nonnetfxtests&category!=failing&category!=nonwindowstests"
132140
```
133141

@@ -152,7 +160,8 @@ dotnet test "src\Microsoft.Data.SqlClient\tests\FunctionalTests\Microsoft.Data.S
152160
```bash
153161
dotnet test "src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj" -p:Platform="AnyCPU" -p:Configuration="Release" -p:TestTargetOS="Unixnetcoreapp" --no-build -v n --filter "category!=nonnetcoreapptests&category!=failing&category!=nonlinuxtests&category!=nonuaptests"
154162
```
155-
#### Run Manual Tests
163+
164+
### Run Manual Tests
156165

157166
- Windows (`netfx x86`):
158167

@@ -194,35 +203,40 @@ dotnet test "src\Microsoft.Data.SqlClient\tests\ManualTests\Microsoft.Data.SqlCl
194203

195204
Tests can be built and run with custom "Reference Type" property that enables different styles of testing:
196205

197-
- "Project" => Build and run tests with Microsoft.Data.SqlClient as Project Reference
198-
- "Package" => Build and run tests with Microsoft.Data.SqlClient as Package Reference with configured "TestMicrosoftDataSqlClientVersion" in "Versions.props" file.
206+
- "Project" => Build and run tests with Microsoft.Data.SqlClient as a Project Reference
207+
- "Package" => Build and run tests with Microsoft.Data.SqlClient as a Package Reference with configured "TestMicrosoftDataSqlClientVersion" in "Versions.props" file.
199208

200209
> ************** IMPORTANT NOTE BEFORE PROCEEDING WITH "PACKAGE" REFERENCE TYPE ***************
201210
> CREATE A NUGET PACKAGE WITH BELOW COMMAND AND ADD TO LOCAL FOLDER + UPDATE NUGET CONFIG FILE TO READ FROM THAT LOCATION
202211
>
203212
> ```bash
204-
> msbuild -p:configuration=Release
213+
> msbuild -t:BuildAbstractionsPackage -p:Configuration=Release
214+
> msbuild -p:Configuration=Release
205215
> ```
206216
207217
A non-AnyCPU platform reference can only be used with package reference type. Otherwise, the specified platform will be replaced with AnyCPU in the build process.
208218
209219
### Building Tests with Reference Type
210220
211-
For .NET, all 4 reference types are supported:
221+
For .NET:
212222
213223
```bash
224+
# Project is the default reference type. The below commands are equivalent:
225+
msbuild -t:BuildTestsNetCore
214226
msbuild -t:BuildTestsNetCore -p:ReferenceType=Project
215-
# Default setting uses Project Reference.
216227
228+
# Package reference type:
217229
msbuild -t:BuildTestsNetCore -p:ReferenceType=Package
218230
```
219231
220-
For .NET Framework, below reference types are supported:
232+
For .NET Framework:
221233

222234
```bash
235+
# Project is the default reference type. The below commands are equivalent:
236+
msbuild -t:BuildTestsNetFx -p:TF=net462
223237
msbuild -t:BuildTestsNetFx -p:TF=net462 -p:ReferenceType=Project
224-
# Default setting uses Project Reference.
225238

239+
# Package reference type:
226240
msbuild -t:BuildTestsNetFx -p:TF=net462 -p:ReferenceType=Package
227241
```
228242

@@ -241,26 +255,25 @@ Tests can be built and run with custom Target Frameworks. See the below examples
241255
### Building Tests with custom target framework
242256

243257
```bash
244-
msbuild -t:BuildTestsNetFx -p:TF=net462
245258
# Build the tests for custom .NET Framework target
259+
msbuild -t:BuildTestsNetFx -p:TF=net462
246260
```
247261

248262
```bash
249-
msbuild -t:BuildTestsNetCore -p:TF=net8.0
250263
# Build the tests for custom .NET target
264+
msbuild -t:BuildTestsNetCore -p:TF=net8.0
251265
```
252266

253267
### Running Tests with custom target framework (traditional)
254268

255269
```bash
270+
# Run tests with custom .NET Framework target
256271
dotnet test -p:TargetNetFxVersion=net462 ...
257-
# Use above property to run Functional Tests with custom .NET Framework target
258272

273+
# Run tests with custom .NET target
259274
dotnet test -p:TargetNetCoreVersion=net8.0 ...
260-
# Use above property to run Functional Tests with custom .NET target
261275
```
262276

263-
264277
## Using Managed SNI on Windows
265278

266279
Managed SNI can be enabled on Windows by enabling the below AppContext switch:
@@ -285,20 +298,6 @@ When connecting to a server, if a protocol lower than TLS 1.2 is negotiated, a s
285298

286299
`Switch.Microsoft.Data.SqlClient.SuppressInsecureTLSWarning`
287300

288-
### Troubleshooting Docker issues
289-
290-
There may be times where connection cannot be made to SQL Server, we found below ideas helpful:
291-
292-
- Clear Docker images to create clean image from time-to-time, and clear docker cache if needed by running `docker system prune` in Command Prompt.
293-
294-
- If you face `Microsoft.Data.SqlClient.SNI.dll not found` errors when debugging, try updating the below properties in the netcore\Microsoft.Data.SqlClient.csproj file and try again:
295-
296-
```xml
297-
<OSGroup>Unix</OSGroup>
298-
<TargetsWindows>false</TargetsWindows>
299-
<TargetsUnix>true</TargetsUnix>
300-
```
301-
302301
## Collecting Code Coverage
303302

304303
### Using VSTest

NuGet.config

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
<configuration>
33
<packageSources>
44
<clear />
5-
<add key="sqlclient" value="https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/sqlclient/nuget/v3/index.json" />
5+
<!-- We use a curated, vetted ADO feed for our dependencies. -->
6+
<add key="curated" value="https://sqlclientdrivers.pkgs.visualstudio.com/public/_packaging/sqlclient/nuget/v3/index.json" />
67
</packageSources>
78
<auditSources>
89
<clear />
10+
11+
<!-- There is no curated, vetted ADO feed for auditing, so we use the official source. -->
912
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
1013
</auditSources>
1114
</configuration>

build.proj

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151

5252
<!-- Populate all managed projects -->
5353
<ItemGroup>
54+
<AbstractionsPackage Include="src/Microsoft.Data.SqlClient.Extensions/Abstractions/Abstractions.slnx" />
5455
<SqlServerLib Include="**/Microsoft.SqlServer.Server.csproj" />
5556
<NetFxDriver Include="**/netfx/**/Microsoft.Data.SqlClient*.csproj" Condition="'$(IsEnabledWindows)' == 'true'" />
5657
<NetCoreDriver Include="**/netcore/**/Microsoft.Data.SqlClient*.csproj" />
@@ -91,6 +92,32 @@
9192
<Target Name="BuildTestsNetCore" DependsOnTargets="RestoreTestsNetCore;BuildAKVNetCore;BuildUnitTestsNetCore;BuildFunctionalTestsNetCore;BuildManualTestsNetCore"/>
9293
<Target Name="BuildTestsNetFx" DependsOnTargets="RestoreTestsNetFx;BuildAKVNetFx;BuildUnitTestsNetFx;BuildFunctionalTestsNetFx;BuildManualTestsNetFx" Condition="$(IsEnabledWindows) == 'true'"/>
9394

95+
<!--
96+
The Abstractions package must be built and packed into the packages/
97+
directory before the MDS projects can be restored.
98+
99+
We cannot make the driver targets depend on this one because of the way
100+
MSBuild restores projects in "solution mode". It will attempt to restore
101+
all targets in the graph before building any of them, which fails because
102+
MDS depends on the Abstractions package being built and packed into packages/
103+
first.
104+
-->
105+
<Target Name="BuildAbstractionsPackage">
106+
<PropertyGroup>
107+
<!--
108+
Omit the AbstractionsPackageVersion property entirely if it is empty.
109+
Otherwise, the command-line property will override the default value,
110+
even if empty.
111+
-->
112+
<BuildProperties Condition="'$(AbstractionsPackageVersion)' != ''">AbstractionsPackageVersion=$(AbstractionsPackageVersion)</BuildProperties>
113+
</PropertyGroup>
114+
115+
<MSBuild
116+
Projects="@(AbstractionsPackage)"
117+
Targets="Restore;Build;Pack"
118+
Properties="$(BuildProperties)" />
119+
</Target>
120+
94121
<Target Name="RestoreSqlServerLib">
95122
<MSBuild Projects="@(SqlServerLib)" Targets="restore" />
96123
</Target>
@@ -346,13 +373,17 @@
346373
<Exec ConsoleToMsBuild="true" Command="$(TestCommand)" />
347374
</Target>
348375

349-
<!-- Clean -->
376+
<!-- Clean all intermediate outputs. -->
350377
<Target Name="Clean">
351-
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","artifacts", SearchOption.AllDirectories))' />
352-
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","bin", SearchOption.AllDirectories))' />
353-
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","obj", SearchOption.AllDirectories))' />
354-
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".","packages", SearchOption.AllDirectories))' />
355-
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".",".nuget", SearchOption.AllDirectories))' />
378+
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".", "artifacts", SearchOption.AllDirectories))' />
379+
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".", "bin", SearchOption.AllDirectories))' />
380+
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".", "obj", SearchOption.AllDirectories))' />
381+
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".", ".nuget", SearchOption.AllDirectories))' />
382+
</Target>
383+
384+
<!-- Clean all outputs, including NuGet packages. -->
385+
<Target Name="CleanAll" DependsOnTargets="Clean">
386+
<RemoveDir Directories='$([System.IO.Directory]::GetDirectories(".", "packages", SearchOption.AllDirectories))' />
356387
</Target>
357388

358389
<!-- AKV Targets ========================================================= -->

eng/pipelines/common/templates/jobs/ci-build-nugets-job.yml

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,13 @@ parameters:
1212
type: string
1313
default: ADO-MMS22-SQL19
1414

15-
- name: artifactName
15+
- name: abstractionsArtifactName
1616
type: string
17-
default: Artifacts
17+
default: Abstractions.Artifact
18+
19+
- name: mdsArtifactName
20+
type: string
21+
default: MDS.Artifact
1822

1923
- name: platform
2024
type: string
@@ -28,6 +32,11 @@ parameters:
2832
type: stepList
2933
default: []
3034

35+
- name: abstractionsPackageVersion
36+
displayName: Abstractions Package Version Override
37+
type: string
38+
default: ''
39+
3140
jobs:
3241
- job: build_nugets
3342

@@ -44,12 +53,22 @@ jobs:
4453
- ${{ if ne(parameters.prebuildSteps, '') }}:
4554
- ${{ parameters.prebuildSteps }} # extra steps to run before the build like downloading sni and the required configuration
4655

56+
# Download the Abstractions package artifacts and put them in the packages/
57+
# directory in the repo root. This is where the MDS NuGet.config file will
58+
# look for local packages.
59+
- task: DownloadPipelineArtifact@2
60+
displayName: Download Abstractions Package Artifact
61+
inputs:
62+
artifactName: ${{ parameters.abstractionsArtifactName }}
63+
targetPath: $(Build.SourcesDirectory)/packages
64+
4765
- template: ../steps/ci-project-build-step.yml@self
4866
parameters:
4967
platform: ${{ parameters.platform }}
5068
configuration: ${{ parameters.configuration }}
5169
operatingSystem: Windows
5270
build: all
71+
abstractionsPackageVersion: ${{parameters.abstractionsPackageVersion}}
5372

5473
- template: ../steps/generate-nuget-package-step.yml@self
5574
parameters:
@@ -70,8 +89,8 @@ jobs:
7089
installNuget: false
7190
displayName: 'Generate NuGet package AKV Provider'
7291

73-
- task: PublishBuildArtifacts@1
74-
displayName: 'Publish Artifact: Artifacts'
92+
- task: PublishPipelineArtifact@1
93+
displayName: 'Publish Pipeline Artifact'
7594
inputs:
76-
PathtoPublish: $(packagePath)
77-
ArtifactName: ${{ parameters.artifactName }}
95+
targetPath: $(packagePath)
96+
artifactName: ${{ parameters.mdsArtifactName }}

0 commit comments

Comments
 (0)