Skip to content

Comments

.NET Samples - Simplify sample invocaiton and miscellaneous clean-up#4064

Closed
crickman wants to merge 3 commits intomainfrom
crickman/dotnet-samples-portable
Closed

.NET Samples - Simplify sample invocaiton and miscellaneous clean-up#4064
crickman wants to merge 3 commits intomainfrom
crickman/dotnet-samples-portable

Conversation

@crickman
Copy link
Contributor

@crickman crickman commented Feb 19, 2026

Motivation and Context

As I started down the path of re-organizing the .NET samples, I noticed the usage of the <TargetFrameworks> property was unnecessarily complicating invocation.

Description

  • Replaced <TargetFrameworks>net10.0</TargetFrameworks> with <TargetFramework>net10.0</TargetFramework>. This eliminates the need to specify --framework net10.0 when running the sample. In short, dotnet run --framework net10.0 becomes dotnet run. High likelihood that someone's first experience running a sample is an error that says:

    Unable to run your project
    Your project targets multiple frameworks. Specify which framework to run using '--framework'.

    Not a great experience. (Samples were only targeting net10.0 anyway.)

  • Removed common definition of UserSecretsId from dotnet/samples/Directory.Build.props and pushed this property to the sample .csproj.

  • Removed dead code under dotnet/Shared/Samples (dead code bad, mkay)

  • Moved SampleEnvironment from dotnet/Shared/Demos to dotnet/Shared/Samples and clarified README (We don't have a "Demos" folder...we do have a "Samples" folder.)

  • Marginally streamlined implementation and messaging of SampleEnvironment

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@crickman crickman added the samples Issue relates to the samples label Feb 19, 2026
@crickman crickman moved this to In Review in Agent Framework Feb 19, 2026
@crickman crickman self-assigned this Feb 19, 2026
@crickman crickman changed the title .NET Samples - Increase sample portability and miscellaneous clean-up .NET Samples - Simplify sample invocaiton and miscellaneous clean-up Feb 19, 2026
@crickman crickman marked this pull request as ready for review February 19, 2026 04:49
Copilot AI review requested due to automatic review settings February 19, 2026 04:49
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 simplifies .NET sample invocation by changing from multi-targeting to single-targeting and performs miscellaneous clean-up. The primary motivation is to eliminate the need to specify --framework net10.0 when running samples, improving the first-time user experience.

Changes:

  • Changed all sample .csproj files from <TargetFrameworks> (plural) to <TargetFramework> (singular) for net10.0, eliminating the need to specify --framework when running samples
  • Removed common UserSecretsId from Directory.Build.props and added it explicitly to Declarative Workflow samples that need it
  • Deleted unused sample utility code (XunitLogger.cs, TextOutputHelperExtensions.cs, TestConfiguration.cs, OrchestrationSample.cs, BaseSample.cs)
  • Moved SampleEnvironment.cs from Shared/Demos to Shared/Samples and improved its implementation with better affirmative value handling and console color management
  • Updated README documentation to reflect the new structure
  • Simplified asset file patterns and removed unused package references

Reviewed changes

Copilot reviewed 168 out of 168 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
dotnet/samples/Directory.Build.props Updated default target framework and changed shared code path from Demos to Samples
dotnet/src/Shared/Samples/SampleEnvironment.cs Improved implementation with HashSet for affirmative values and better console color handling
dotnet/src/Shared/Samples/README.md New documentation for SampleEnvironment (contains spelling errors noted below)
dotnet/src/Shared/Demos/README.md Removed old Demos folder documentation
Multiple .csproj files (120+ files) Changed TargetFrameworks to TargetFramework for single-targeting
Declarative workflow .csproj files Added explicit UserSecretsId where needed
dotnet/src/Shared/Samples/*.cs Deleted unused sample utility classes
FoundryAgents_Step15_ComputerUse.csproj Simplified asset file copy pattern from individual files to wildcard
A2AAgent_PollingForTaskCompletion.csproj Removed unused System.Net.ServerSentEvents package
A2AServer.csproj Removed conditional ItemGroup that's no longer needed with single-targeting
HostedWorkflow/Program.cs Updated placeholder comment to proper description

Comment on lines +1 to +12
# SampleEnvironemnt.cs

Efficient sample project utilities.
`SampleEnvironemnt.cs` defines a helper that overrides `System.Environment` class for a project.
This override version has an enhanced `GetEnvironmentVariable` method that prompts the user
to enter a value if the environment variable is not set.

To use this in your project, add the following to your `.csproj` file:
Sample code is still fully copyable to another project. This override just allow for a simplified experience
for users who are new and just getting started.

This file is already included in all samples via `/dotnet/samples/Directory.Build.props`.

To explicitly use `SampleEnvironemnt.cs` outside of this repo, add the following to your `.csproj` file:
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The filename contains a typo: "SampleEnvironemnt" should be "SampleEnvironment" (missing 'n' in "Environment"). This typo appears in the title and is repeated throughout the document on lines 1, 3, and 12.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

</ItemGroup>

<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)\..\src\Shared\Demos\*.cs" LinkBase="" Visible="false" />
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The path in line 20 still references the old "Demos" folder but should reference "Samples" instead, consistent with the PR's goal of moving SampleEnvironment from Demos to Samples. The correct path should be: $(MSBuildThisFileDirectory)\..\src\Shared\Samples\*.cs

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

<TargetFrameworks>net10.0;net472</TargetFrameworks>
<UserSecretsId>5ee045b0-aea3-4f08-8d31-32d1a6f8fed0</UserSecretsId>
<TargetFramework>net10.0</TargetFramework>
<TargetFrameworks>net10.0</TargetFrameworks>
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

Both TargetFramework (line 12) and TargetFrameworks (line 13) are set to the same value "net10.0". This appears redundant. Consider removing line 13 <TargetFrameworks>net10.0</TargetFrameworks> since individual projects now explicitly set <TargetFramework>net10.0</TargetFramework> and this default shouldn't need the plural version.

Suggested change
<TargetFrameworks>net10.0</TargetFrameworks>

Copilot uses AI. Check for mistakes.
@@ -1,11 +1,22 @@
# Throw
# SampleEnvironemnt.cs
Copy link

Copilot AI Feb 19, 2026

Choose a reason for hiding this comment

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

The title contains a typo: "invocaiton" should be "invocation".

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@copilot open a new pull request to apply changes based on this feedback

Copy link
Contributor

Copilot AI commented Feb 19, 2026

@crickman I've opened a new pull request, #4070, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 19, 2026

@crickman I've opened a new pull request, #4071, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 19, 2026

@crickman I've opened a new pull request, #4072, to work on those changes. Once the pull request is ready, I'll request review from you.

Copy link
Contributor

Copilot AI commented Feb 19, 2026

@crickman I've opened a new pull request, #4073, to work on those changes. Once the pull request is ready, I'll request review from you.

Copilot AI mentioned this pull request Feb 19, 2026
4 tasks
@crickman crickman closed this Feb 19, 2026
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Feb 19, 2026
@crickman
Copy link
Contributor Author

I'm actually going to split this along separation of concerns.

@crickman crickman moved this from Done to Planned in Agent Framework Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation .NET samples Issue relates to the samples

Projects

Status: Planned

Development

Successfully merging this pull request may close these issues.

3 participants