Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 15, 2025

This PR completes the single file AppHost implementation in the RunCommand by adding proper feature flag validation and cleaning up redundant logic.

Changes Made

Feature Flag Validation

  • Added validation that the singlefileAppHostEnabled feature flag is enabled when a .cs file is detected as an AppHost
  • Returns a clear error message when the feature is disabled but a single file AppHost is attempted
  • Maintains consistency with the ProjectLocator which already checks this feature flag

Code Cleanup

  • Removed redundant !isSingleFileAppHost check in the build logic (was checked at lines 130 and 142)
  • Streamlined the build skip logic for single file AppHosts to avoid unnecessary nested conditions

Error Handling

  • Added SingleFileAppHostFeatureNotEnabled error string to resources with proper localization support
  • Updated both .resx and .Designer.cs files following the project's resource management patterns

Test Coverage

  • Added test case RunCommand_WhenSingleFileAppHostAndFeatureDisabled_ReturnsNonZeroExitCode to verify proper error handling
  • All existing tests continue to pass (358/358)

Behavior

Before: The RunCommand would attempt to process .cs files returned by ProjectLocator without validating if the feature was enabled, potentially leading to inconsistent behavior.

After: The RunCommand now properly validates the feature flag and provides clear feedback:

# Feature disabled (default)
$ aspire run --project apphost.cs
❌ Single file AppHost feature is not enabled. To use .cs AppHost files, enable the feature using configuration.

# Feature enabled
$ features__singlefileAppHostEnabled=true aspire run --project apphost.cs
# Proceeds with single file AppHost execution

Configuration

The feature can be enabled via:

  • Environment variable: features__singlefileAppHostEnabled=true
  • JSON configuration in .aspire/settings.json:
{
  "features": {
    "singlefileAppHostEnabled": true
  }
}

This change ensures the RunCommand implementation is fully consistent with the ProjectLocator's feature flag handling while maintaining backward compatibility and providing clear user feedback.

Created from VS Code via the GitHub Pull Request extension.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

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

If anyone wants to following along at home, here is an apphost.cs file that will work with this change:

#:sdk Microsoft.NET.Sdk
#:sdk Aspire.AppHost.Sdk@9.5.0-preview.1.25460.2
#:package Aspire.Hosting.AppHost@9.5.0-preview.1.25460.2
#:property PublishAot=false

var builder = DistributedApplication.CreateBuilder(args);

builder.Build().Run();

@Copilot Copilot AI changed the title [WIP] Modifications to RunCommand for AppHost File Handling Implement feature flag validation and cleanup for single file AppHost support in RunCommand Sep 15, 2025
@Copilot Copilot AI requested a review from mitchdenny September 15, 2025 03:26
Copilot finished work on behalf of mitchdenny September 15, 2025 03:26
Copy link
Contributor

github-actions bot commented Sep 15, 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 -- 11397

Or

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

1 similar comment
Copy link
Contributor

🚀 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 -- 11397

Or

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

@davidfowl
Copy link
Member

@mitchdenny why do we need both sdks?

@mitchdenny
Copy link
Member

Yeah without it it doesn't understand PackageReference at this point.

@mitchdenny mitchdenny force-pushed the copilot/vscode1757905630284 branch from c992623 to 4c9b359 Compare September 17, 2025 06:38
@mitchdenny mitchdenny force-pushed the copilot/vscode1757905630284 branch from 1277387 to 34ad423 Compare September 17, 2025 07:51
@mitchdenny mitchdenny marked this pull request as ready for review September 17, 2025 08:02
@Copilot Copilot AI review requested due to automatic review settings September 17, 2025 08:02
Copy link
Contributor

@Copilot 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 completes the single file AppHost implementation in the RunCommand by adding proper feature flag validation and cleaning up redundant logic. The changes ensure that when a .cs file is detected as an AppHost, the feature flag is properly validated before proceeding with execution.

Key changes:

  • Added feature flag validation with clear error messaging when single file AppHost is disabled
  • Cleaned up redundant build logic checks and streamlined control flow
  • Added comprehensive localization support for the new error message

Reviewed Changes

Copilot reviewed 18 out of 19 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/Aspire.Cli/Commands/RunCommand.cs Main implementation adding feature flag validation and logic cleanup for single file AppHost support
src/Aspire.Cli/DotNet/DotNetCliRunner.cs Updated CLI argument construction to handle single file AppHost execution
src/Aspire.Cli/Resources/ErrorStrings.resx Added new error string for single file AppHost feature validation
src/Aspire.Cli/Resources/xlf/*.xlf Added localized translations for the new error message across multiple languages
tests/Aspire.Cli.Tests/Commands/RunCommandTests.cs Added test coverage for feature flag validation error scenario
src/Aspire.Cli/Utils/AppHostHelper.cs Minor whitespace cleanup
Files not reviewed (1)
  • src/Aspire.Cli/Resources/ErrorStrings.Designer.cs: Language not supported

@mitchdenny mitchdenny merged commit ff3ceac into main Sep 17, 2025
311 checks passed
@mitchdenny mitchdenny deleted the copilot/vscode1757905630284 branch September 17, 2025 11:36
@dotnet-policy-service dotnet-policy-service bot added this to the 9.5 milestone Sep 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants