Refactor and update sample project build.#3816
Conversation
Scope: Make samples build with nor or minimal changes to actual snippets usied in docs. Added namespaces to organize code and prevent naming conflicts. Used filename as namespace, and for files with names of classes, added "CS" to namespace Adjusted `using` directives to include necessary references to make build pass. Wrapped code snippets in conditional compilation directives for mostly .NET Framework-specific APIs. Made some changes to the .csproj file to enable local "dotnet build" - happy to revert as needed.
There was a problem hiding this comment.
Pull request overview
This PR refactors sample code files to enable building with minimal changes to documentation snippets. The primary changes include adding namespace declarations to prevent naming conflicts and wrapping .NET Framework-specific code in conditional compilation directives.
- Adds unique namespaces to all sample files, typically using the filename as the namespace name (with "CS" suffix for files with class names)
- Wraps .NET Framework-specific code in
#if NETFRAMEWORKdirectives - Adds missing
usingdirectives required for compilation - Updates project configuration to support multi-targeting (net8.0 and net462)
Reviewed changes
Copilot reviewed 228 out of 228 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| TransactionIsolationLevels.cs | Changed namespace from generic to filename-based |
| SqlVectorExample.cs | Added namespace, missing using directives, and changed async to sync method call |
| SqlUserDefinedType*.cs | Added namespaces and changed namespace references from Microsoft.Data.SqlClient.Server to Microsoft.SqlServer.Server |
| SqlRowUpdatingEventArgs.cs, SqlParameterCollection_*.cs, SqlDataAdapter_SelectCommand.cs, etc. | Wrapped .NET Framework-specific code in conditional compilation directives |
| SqlDataReader_DataDiscoveryAndClassification.cs | Fixed typo in Console method name |
| SqlDataAdapter_Properties.cs | Removed nested namespace and unnecessary using directive |
| SqlCommand_ExecuteNonQuery_SP_DML.cs | Removed unused variable declaration |
| SqlDataAdapter_SPIdentityReturn.cs | Changed Int to int for type consistency |
| SqlConfigurableRetryLogic_SqlCommand.cs | Added wrapper classes to separate code snippets |
| SqlClientEventSource.cs, SqlClientDiagnosticCounter.cs | Added namespaces and missing using directives |
| RegisterCustomKeyStoreProvider_*.cs | Added namespaces, using directives, and stub implementations for custom providers |
| SqlUserDefinedTypeAttribute_Type1.cs | Fixed typo in Convert.Toint method calls |
| Microsoft.Data.SqlClient.Samples.csproj | Added multi-targeting configuration and package reference |
| ConnectionStrings_Encrypt.cs | Renamed parameter for clarity |
doc/samples/Microsoft.SqlServer.Server/csharp/SqlUserDefinedTypeAttribute_Type1.cs
Show resolved
Hide resolved
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
@paulmedynski Do you have time to respond? |
|
@dotnet/sqlclientdevteam - Can we get some more eyes on this and respond to some of my comments? |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
This pull request has been marked as stale due to inactivity for more than 30 days. If you would like to keep this pull request open, please provide an update or respond to any comments. Otherwise, it will be closed automatically in 7 days. |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
@paulmedynski @cheenamalhotra Comments addressed I stayed on .NET 8 for now, as using .NET 10 caused package downgrade errors This is the resolved version numbers in latest main, curious about 6.1.2 and not 6.1.4 ?
|
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3816 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|

Scope: Make samples build with nor or minimal changes to actual snippets used in docs.
Added namespaces to organize code and prevent naming conflicts. Used filename as namespace, and for files with names of classes, added "CS" to namespace
Adjusted
usingdirectives to include necessary references to make build pass.Wrapped code snippets in conditional compilation directives for mostly .NET Framework-specific APIs.
Made some changes to the .csproj file to enable local "dotnet build" - happy to revert as needed.
I will comment on any other type of changes made to a few samples.
Unsure about the sample for Microsoft.SqlServer.Server, but can revert these if needed. (and not build them)
Related to issue #3725