-
Notifications
You must be signed in to change notification settings - Fork 699
Add NuGet.config creation to solution initialization in aspire init
#11921
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
base: main
Are you sure you want to change the base?
Conversation
aspire init
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 11921 Or
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 11921" |
@copilot this change duplicates some logic that already exists in |
Refactored the NuGet.config prompting logic into a new
All duplicate code has been removed, and all 423 tests pass. Changes in commit e5e0c2f. |
Co-authored-by: mitchdenny <[email protected]>
… class Co-authored-by: mitchdenny <[email protected]>
ebe72ea
to
872cc30
Compare
…t is added to solution.
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
Adds NuGet.config creation/prompting to solution-based aspire init and centralizes the logic to remove duplication with aspire new.
- Introduces NuGetConfigPrompter to encapsulate create/update and prompting behavior.
- Refactors DotNetTemplateFactory and InitCommand to use the shared helper.
- Adds solution init call to ensure explicit channel sources are offered when initializing into an existing solution directory.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
src/Aspire.Cli/Packaging/NuGetConfigPrompter.cs | New helper class encapsulating NuGet.config prompting and creation logic. |
src/Aspire.Cli/Templating/DotNetTemplateFactory.cs | Replaces inline NuGet.config logic with NuGetConfigPrompter usage; removes duplicated helper. |
src/Aspire.Cli/Commands/InitCommand.cs | Adds NuGet.config prompting during solution init and a wrapper method delegating to NuGetConfigPrompter. |
Fix: Add NuGet.config creation for solution initialization in
aspire init
Problem
When
aspire init
is used with a solution file, it doesn't create/update a NuGet.config file. The single-file AppHost path already does this correctly viaPromptToCreateOrUpdateNuGetConfigAsync
, but the solution path skips this step.Solution
Created a shared
NuGetConfigPrompter
helper class to eliminate code duplication betweenInitCommand
andDotNetTemplateFactory
, ensuring consistent NuGet.config creation behavior across both commands.Changes Made
1. Created
NuGetConfigPrompter
helper classFile:
src/Aspire.Cli/Packaging/NuGetConfigPrompter.cs
PromptToCreateOrUpdateAsync
: Prompts user before creating/updating (for in-place creation)CreateOrUpdateWithoutPromptAsync
: Creates/updates without prompting (for subdirectory creation)2. Updated
InitCommand
to use the shared helperFile:
src/Aspire.Cli/Commands/InitCommand.cs
CreateOrUpdateNuGetConfigAsync
methodNuGetConfigPrompter.PromptToCreateOrUpdateAsync
for solution directory3. Refactored
DotNetTemplateFactory
to use the shared helperFile:
src/Aspire.Cli/Templating/DotNetTemplateFactory.cs
PromptToCreateOrUpdateNuGetConfigAsync
to useNuGetConfigPrompter
TryFindNuGetConfigInDirectory
helper methodBenefits
InitCommand
andDotNetTemplateFactory
aspire init
andaspire new
commandsTesting
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.