-
Notifications
You must be signed in to change notification settings - Fork 733
Add AddCSharpApp method to add C# file-based apps & projects #11502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11502Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11502" |
|
Are you going to try and land this for 9.5? |
@mitchdenny I'm going to make it experimental, but, it does touch a few things as it basically re-uses all of the existing infra for projects, but teaches them about the new stuff for file-based apps in a few places. So, I think this is likely too risky to take in 9.5 unless others feel more confident than me 😄 |
|
I think punting for 9.6 is right. We can then make file-based AddProject work at the same time. |
Sorry, what do you mean by this? |
|
Add the moment AddProject(path) does not work because we don't build the .NET project (unless you are using VS obviously). |
|
OK I just re-read the code and it seems we pass |
- Modified Sdk.in.props to auto-import Microsoft.NET.Sdk - Refined Sdk.in.targets to streamline implicit references and removed workaround targets for file-based apps no longer needed as of rc.2. - Introduced CSharpAppResource class to represent C# projects or file-based apps which doesn't suppress build of the project. - Updated DcpExecutor to handle file-based apps with appropriate run commands. - Enhanced IProjectMetadata to include suppress build functionality. - Improved ProjectResourceBuilderExtensions to support adding C# projects or file-based apps. - Updated project templates to reflect changes in SDK references. - Added unit tests for resource icon resolution to cover file extensions.
deff701 to
474a6b3
Compare
… Redis package reference and update project file structure
There was a problem hiding this 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 adds a new AddCSharpApp extension method that enables adding C# projects and file-based apps to the Aspire application model. The implementation supports three input types: paths to .cs files (file-based apps), .csproj files, or directories containing a single .csproj. Additionally, the PR updates the Aspire.AppHost.Sdk to support simplified project file syntax where the SDK can be specified directly in the Project element's Sdk attribute, automatically importing Microsoft.NET.Sdk and the Aspire.Hosting.AppHost package reference.
Key changes:
- Introduced
AddCSharpAppAPI with support for C# projects and file-based apps (.cs files) - Updated project build behavior to track whether build suppression is needed via new
SuppressBuildproperty onIProjectMetadata - Modified AppHost SDK to auto-import Microsoft.NET.Sdk and implicitly reference Aspire.Hosting.AppHost package
- Enhanced CLI update logic to handle both old and new SDK reference formats
Reviewed Changes
Copilot reviewed 46 out of 47 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Shared/RepoTesting/Aspire.RepoTesting.props | Updated condition to use case-insensitive check for 'AppHost' suffix |
| tests/Aspire.Templates.Tests/BuildAndRunTemplateTests.cs | Added tests for CPM and explicit SDK reference scenarios |
| tests/Aspire.Hosting.Tests/Snapshots/MSBuildTests.ValidateMetadataSources.verified.txt | Updated snapshot with new SuppressBuild property and corrected comment |
| tests/Aspire.Dashboard.Tests/Model/ResourceIconHelpersTests.cs | Added test cases for .cs file icon resolution |
| tests/Aspire.Cli.Tests/Projects/ProjectUpdaterTests.cs | Added tests for SDK attribute and element format updates |
| src/Shared/LaunchProfiles/LaunchProfileExtensions.cs | Added support for .run.json files for file-based apps |
| src/Aspire.ProjectTemplates/templates/aspire-starter/13.0/Aspire-StarterApplication.1.AppHost/Aspire-StarterApplication.1.AppHost.csproj | Updated to use new SDK syntax and removed explicit AppHost package reference |
| src/Aspire.ProjectTemplates/templates/aspire-empty/13.0/AspireApplication.1.AppHost/AspireApplication.1.AppHost.csproj | Updated to use new SDK syntax and removed explicit AppHost package reference |
| src/Aspire.ProjectTemplates/templates/aspire-apphost/13.0/Aspire.AppHost1.csproj | Updated to use new SDK syntax and removed explicit AppHost package reference |
| src/Aspire.Hosting/Utils/DotnetSdkUtils.cs | New utility class for detecting .NET SDK version |
| src/Aspire.Hosting/ProjectResourceOptions.cs | Added FileBasedAppResourceOptions class (placeholder) |
| src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs | Added AddCSharpApp methods and updated configuration loading |
| src/Aspire.Hosting/IProjectMetadata.cs | Added SuppressBuild and IsFileBasedApp properties, enhanced ProjectMetadata to resolve directory paths |
| src/Aspire.Hosting/Dcp/DcpExecutor.cs | Updated to handle file-based apps and conditional build suppression |
| src/Aspire.Hosting/ApplicationModel/CSharpAppResource.cs | New resource type for C# apps |
| src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets | Added SuppressBuild property to generated metadata, corrected comment |
| src/Aspire.Dashboard/Model/ResourceIconHelpers.cs | Added .cs extension to C# icon mapping |
| src/Aspire.Cli/Projects/ProjectUpdater.cs | Enhanced to handle both SDK attribute and element formats |
| src/Aspire.AppHost.Sdk/SDK/Sdk.in.targets | Simplified to add implicit AppHost package reference for all projects |
| src/Aspire.AppHost.Sdk/SDK/Sdk.in.props | Updated to auto-import Microsoft.NET.Sdk, commented out some file-based app properties |
| playground/FileBasedApps/* | New playground project demonstrating file-based app functionality |
| playground/Directory.Build.targets | Fixed relative path to Analyzers project |
| Directory.Packages.props | Reorganized package versions with framework-specific conditions |
tests/Aspire.Hosting.Tests/Snapshots/MSBuildTests.ValidateMetadataSources.verified.txt
Outdated
Show resolved
Hide resolved
src/Aspire.Hosting.AppHost/build/Aspire.Hosting.AppHost.in.targets
Outdated
Show resolved
Hide resolved
|
Verified. @mitchdenny We'll want to update |
|
@davidfowl this PR already does that, or am I missing something? |
|
OHHh I didnt see that part. |
Description
Adds new hosting method
AddCSharpAppthat can be used to add:e.g.
Project building has been updated to track whether a project resource requires building or not. Project resources added via the generated
IProjectMetadatatypes that come from<ProjectReference />items in the AppHost .csproj will continue to have build suppressed, as will existing path-based project resources added viaAddProject("../some/path.csproj"). Projects added using the newly addedAddCSharpAppmethod will not have build suppressed anymore when running from the command-line. The existing restrictions around .csproj files being added to the app model that aren't in the solution the AppHost project is in are not addressed by these changes.Also updates the
Aspire.AppHost.Sdkand project templates to support only specifying theAspire.AppHost.Sdkas the project SDK in which case theMicrosoft.NET.Sdkis auto-imported and theAspire.Hosting.AppHostpackage reference is implicitly referenced. Setting the project to use theMicrosoft.NET.Sdkand importing theAspire.AppHost.Sdkvia an<Sdk />item is still supported of course. Aspire CLIaspire updateis updated to support this syntax too.e.g.
Fixes #11498
Checklist
<remarks />and<code />elements on your triple slash comments?