Skip to content

Refactor and update sample project build.#3816

Open
ErikEJ wants to merge 4 commits intodotnet:mainfrom
ErikEJ:build-snippets
Open

Refactor and update sample project build.#3816
ErikEJ wants to merge 4 commits intodotnet:mainfrom
ErikEJ:build-snippets

Conversation

@ErikEJ
Copy link
Contributor

@ErikEJ ErikEJ commented Nov 29, 2025

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 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.

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

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.
Copilot AI review requested due to automatic review settings November 29, 2025 13:25
@ErikEJ ErikEJ requested a review from a team as a code owner November 29, 2025 13:25
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 NETFRAMEWORK directives
  • Adds missing using directives 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

@paulmedynski
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 5, 2025

"Can you add a comment to this effect?

Also, if you use #if false instead of the block comment /* */ then we still get nice IDE presentation and you can put comments about what isn't compiling adjacent to the offending lines."

Sure.

Will adding #if not disrupt the sample code??

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 5, 2025

Basically, for any files that did not have a namespace before, adding it to the top of the file is making sure that this does not interfere with any sample code.

@ErikEJ
Copy link
Contributor Author

ErikEJ commented Dec 5, 2025

@paulmedynski also not sure the samples are included in any build at the moment...

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

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.

@github-actions github-actions bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 5, 2026
@ErikEJ
Copy link
Contributor Author

ErikEJ commented Jan 5, 2026

@paulmedynski Do you have time to respond?

@paulmedynski paulmedynski removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Jan 5, 2026
@paulmedynski
Copy link
Contributor

@dotnet/sqlclientdevteam - Can we get some more eyes on this and respond to some of my comments?

@cheenamalhotra
Copy link
Member

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@cheenamalhotra cheenamalhotra added Waiting for Customer ⏳ Issues/PRs waiting for user response/action. and removed Waiting for Customer ⏳ Issues/PRs waiting for user response/action. labels Jan 13, 2026
@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 12, 2026
@cheenamalhotra
Copy link
Member

cheenamalhotra commented Feb 18, 2026

/azp run

cheenamalhotra
cheenamalhotra previously approved these changes Feb 18, 2026
@dotnet dotnet deleted a comment from azure-pipelines bot Feb 18, 2026
@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

@cheenamalhotra cheenamalhotra removed the Stale The Issue or PR has become stale and will be automatically closed shortly if no activity occurs. label Feb 18, 2026
@cheenamalhotra cheenamalhotra added this to the 7.0.0-preview4 milestone Feb 18, 2026
@ErikEJ
Copy link
Contributor Author

ErikEJ commented Feb 19, 2026

@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 ?

image

@paulmedynski
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 2 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments