Skip to content

Conversation

@davidfowl
Copy link
Member

@davidfowl davidfowl commented Dec 6, 2025

Description

This PR improves the Aspire CLI's handling of the new SDK-style project format and provides better migration support when updating AppHost projects.

  • Added support for parsing the new SDK format:
  • Handles multiple SDKs in the Sdk attribute (e.g., Aspire.AppHost.Sdk/13.0.1;Microsoft.NET.Sdk)
  • Migrates projects from the old element format to the new Sdk attribute format during updates
  • Preserves other SDKs when updating the Aspire SDK version in multi-SDK scenarios
  • Removes the obsolete Aspire.Hosting.AppHost package reference during updates (now included in the SDK)
  • Removes empty elements after package removal
  • Displays informative messages when migration actions are performed:
    • "Migrated to new project format: "
    • "Removed obsolete Aspire.Hosting.AppHost package reference"

Fixes #13000
Fixes #13348
Fixes #13332

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes

- Enhanced FallbackProjectParserTests to validate extraction of SDK version from new project format.
- Added tests for migrating from old SDK format to new format in ProjectUpdaterTests.
- Implemented logic to remove obsolete Aspire.Hosting.AppHost package reference during SDK updates.
- Ensured preservation of other SDKs in project attributes during updates.
- Introduced multiple test cases to verify the migration from old SDK format to new format.
- Added tests to ensure the preservation of other SDKs in the attribute and the removal of obsolete package references.
- Implemented checks for the correct updating of existing new format SDKs and the removal of empty ItemGroups after package removal.
- Verified that similar SDK names do not match and are handled correctly during the update process.
@davidfowl davidfowl requested review from Copilot and mitchdenny and removed request for Copilot December 6, 2025 10:00
@github-actions
Copy link
Contributor

github-actions bot commented Dec 6, 2025

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 13364

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 13364"

@davidfowl davidfowl changed the title Davidfowl/aspire update fixes Various fixes to aspire update Dec 6, 2025
Copilot AI review requested due to automatic review settings December 6, 2025 10:10
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 enhances the Aspire CLI update command to support the new SDK-style project format (<Project Sdk="Aspire.AppHost.Sdk/version">) and automatically migrates projects from the old format during updates. The changes include parsing improvements, automatic migration logic, removal of the obsolete Aspire.Hosting.AppHost package reference, and informative user messages during migration.

Key Changes:

  • Added support for parsing and updating the new SDK attribute format with version (e.g., Aspire.AppHost.Sdk/13.0.1)
  • Implemented automatic migration from old <Sdk Name="..."> element format to new Sdk attribute format
  • Added removal of obsolete Aspire.Hosting.AppHost package reference during updates
  • Added localized user-facing messages for migration actions

Reviewed changes

Copilot reviewed 37 out of 38 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
tests/Aspire.Cli.Tests/Projects/ProjectUpdaterTests.cs Updated existing tests to reflect that Aspire.Hosting.AppHost is no longer updated (removed during SDK migration); added 6 new comprehensive test cases for SDK migration scenarios
tests/Aspire.Cli.Tests/Projects/ProjectUpdaterTests.*.verified.xml Snapshot verification files for new migration test cases showing expected XML output after transformations
tests/Aspire.Cli.Tests/Projects/FallbackProjectParserTests.cs Modernized test infrastructure to use TemporaryWorkspace and async/await; added 4 new tests for new SDK format parsing
tests/Aspire.Cli.Tests/Projects/FallbackProjectParserTests.*.verified.json Snapshot verification files for parser tests showing expected JSON output
src/Aspire.Cli/Resources/UpdateCommandStrings.resx Added two new user-facing messages: MigratedToNewSdkFormat and RemovedObsoleteAppHostPackage
src/Aspire.Cli/Resources/UpdateCommandStrings.Designer.cs Auto-generated designer code synchronized with new resource strings
src/Aspire.Cli/Resources/xlf/UpdateCommandStrings.*.xlf Localization files updated with new strings marked for translation (state="new")
src/Aspire.Cli/Projects/ProjectUpdater.cs Core implementation: added migration detection, SDK attribute parsing/updating logic, package reference removal, and user message display
src/Aspire.Cli/Projects/FallbackProjectParser.cs Added parsing support for new SDK attribute format with version extraction logic
Files not reviewed (1)
  • src/Aspire.Cli/Resources/UpdateCommandStrings.Designer.cs: Language not supported

Comment on lines +7 to +9
<ItemGroup>

</ItemGroup>
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The snapshot file shows that the empty <ItemGroup> element is NOT being removed, contradicting the test name and comment which state "RemovesEmptyItemGroupAfterPackageRemoval". The verified XML still contains:

<ItemGroup>
    
</ItemGroup>

This indicates a bug in either:

  1. The IsEmptyOrWhitespace method that checks if an ItemGroup is empty
  2. The RemovePackageReference method's logic for removing empty ItemGroups

Looking at the implementation in ProjectUpdater.cs at line 485, it only removes the ItemGroup if it's empty. However, the snapshot suggests the ItemGroup still has whitespace nodes that aren't being properly identified as "empty".

Copilot uses AI. Check for mistakes.
Comment on lines +2464 to +2492
public async Task UpdateSdkVersionInCsprojAppHostAsync_RemovesEmptyItemGroupAfterPackageRemoval()
{
// Arrange - tests that empty ItemGroup is removed after Aspire.Hosting.AppHost removal
using var workspace = TemporaryWorkspace.Create(outputHelper);
var projectFile = Path.Combine(workspace.WorkspaceRoot.FullName, "AppHost.csproj");
var originalContent = """
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Aspire.AppHost.Sdk" Version="9.5.0" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.5.0" />
</ItemGroup>
</Project>
""";

await File.WriteAllTextAsync(projectFile, originalContent);

var package = new NuGetPackageCli { Id = "Aspire.AppHost.Sdk", Version = "13.0.2", Source = "nuget.org" };

// Act
await ProjectUpdater.UpdateSdkVersionInCsprojAppHostAsync(new FileInfo(projectFile), package);

// Assert
var updatedContent = await File.ReadAllTextAsync(projectFile);
await Verify(updatedContent, extension: "xml");
}
Copy link

Copilot AI Dec 6, 2025

Choose a reason for hiding this comment

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

The test is named RemovesEmptyItemGroupAfterPackageRemoval and the comment states "tests that empty ItemGroup is removed", but the actual verified output shows the empty <ItemGroup> is still present (lines 7-9 of the verified XML). Either:

  1. The test name and comment are incorrect and should reflect that empty ItemGroups are preserved, OR
  2. There's a bug in the implementation that needs to be fixed

The former seems unlikely given the deliberate naming. This test appears to be failing its intended purpose.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants