.NET Samples - Simplify sample invocaiton and miscellaneous clean-up#4064
.NET Samples - Simplify sample invocaiton and miscellaneous clean-up#4064
Conversation
There was a problem hiding this comment.
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
.csprojfiles from<TargetFrameworks>(plural) to<TargetFramework>(singular) for net10.0, eliminating the need to specify--frameworkwhen running samples - Removed common
UserSecretsIdfromDirectory.Build.propsand 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.csfromShared/DemostoShared/Samplesand 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 |
| # 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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
There was a problem hiding this comment.
@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" /> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
@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> |
There was a problem hiding this comment.
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.
| <TargetFrameworks>net10.0</TargetFrameworks> |
| @@ -1,11 +1,22 @@ | |||
| # Throw | |||
| # SampleEnvironemnt.cs | |||
There was a problem hiding this comment.
The title contains a typo: "invocaiton" should be "invocation".
There was a problem hiding this comment.
@copilot open a new pull request to apply changes based on this feedback
|
I'm actually going to split this along separation of concerns. |
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.0when running the sample. In short,dotnet run --framework net10.0becomesdotnet 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.0anyway.)Removed common definition of
UserSecretsIdfromdotnet/samples/Directory.Build.propsand pushed this property to the sample.csproj.Removed dead code under
dotnet/Shared/Samples(dead code bad, mkay)Moved
SampleEnvironmentfromdotnet/Shared/Demostodotnet/Shared/Samplesand clarifiedREADME(We don't have a "Demos" folder...we do have a "Samples" folder.)Marginally streamlined implementation and messaging of
SampleEnvironmentContribution Checklist