Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 14, 2025

This PR implements the Aspire Single-File AppHost template as requested in the original design discussions. The template provides a minimal, single-file approach to creating Aspire AppHost applications for scenarios where a full project structure is not needed.

Key Features

Template Structure:

  • Creates only a single apphost.cs file with complete minimal distributed application setup using the #:sdk directive format
  • No .csproj, appsettings.json, or launchSettings.json files (as single-file hosts don't need them)
  • No Visual Studio integration (ide.host.json removed since VS doesn't support single-file scenarios)

Version and Feature Gating:

  • Only available for Aspire 9.5+ and .NET 10+
  • Gated behind the singlefileAppHostEnabled CLI feature flag
  • Template only appears when the feature is explicitly enabled

CLI Integration:

  • Template name: aspire-apphost-singlefile
  • Localized description: "Single-file AppHost (experimental)"
  • Seamless integration with existing Aspire CLI template system

Usage

# Enable the experimental feature
aspire config set features:singlefileAppHostEnabled true

# Create a new single-file AppHost
aspire new aspire-apphost-singlefile -n MySingleFileHost

This creates a minimal apphost.cs file with complete SDK directives:

#:sdk Microsoft.NET.Sdk
#:sdk Aspire.AppHost.Sdk@aspireVersion
#:package Aspire.Hosting.AppHost@aspireVersion
#:property PublishAot=false

var builder = DistributedApplication.CreateBuilder(args);

builder.Build().Run();

Implementation Details

The template follows the existing Aspire template patterns:

  • Located in src/Aspire.ProjectTemplates/templates/aspire-apphost-singlefile/
  • Includes proper version symbols and source conditions
  • Auto-generated localization files for international support
  • Integrated with the DotNetTemplateFactory using the existing feature flag infrastructure

Changes Made

  • Template Files: Complete template structure with version 9.5 support
  • CLI Integration: Added feature flag check in DotNetTemplateFactory.cs
  • Localization: Template description properly localized using existing TemplatingStrings infrastructure
  • Test Infrastructure: Updated CliTestHelper.cs to support the new IFeatures dependency injection
  • File Format: Updated template to use lowercase filename (apphost.cs) with complete SDK directive format including:
    • Microsoft.NET.Sdk - Base .NET SDK
    • Aspire.AppHost.Sdk@aspireVersion - Aspire AppHost SDK
    • Aspire.Hosting.AppHost@aspireVersion - Required Aspire hosting package
    • PublishAot=false - Disable AOT for compatibility

The implementation is minimal and focused, providing exactly what was requested: a single-file AppHost template that integrates cleanly with the existing Aspire ecosystem while being appropriately gated for experimental use.

Created from VS Code via the GitHub Pull Request extension.

Created from VS Code via the GitHub Pull Request extension.

Created from VS Code via the GitHub Pull Request extension.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI changed the title [WIP] Implementation of Aspire Single-File AppHost Template Implement Aspire Single-File AppHost template with CLI feature flag integration Sep 14, 2025
@Copilot Copilot AI requested a review from mitchdenny September 14, 2025 23:47
Copilot finished work on behalf of mitchdenny September 14, 2025 23:47
@mitchdenny mitchdenny closed this Sep 15, 2025
@mitchdenny mitchdenny reopened this Sep 15, 2025
@Copilot Copilot AI requested a review from mitchdenny September 15, 2025 01:12
Copilot finished work on behalf of mitchdenny September 15, 2025 01:12
@Copilot Copilot AI requested a review from mitchdenny September 15, 2025 02:52
Copilot finished work on behalf of mitchdenny September 15, 2025 02:52
@mitchdenny
Copy link
Member

@DamianEdwards would be good to get your eyes on the template changes here, I am way out of my depth with template.json :)

@davidfowl
Copy link
Member

Single file supports launch settings via {app}.run.json where {app}.cs is the file. That would let us mimic what we have today with normal projects.

@mitchdenny
Copy link
Member

So maybe we don't automatically set the environment variables inside the CLI? This would preserve the ability to do dotnet new apphost-singlefile and have it work?

@mitchdenny mitchdenny force-pushed the copilot/vscode1757892604932 branch 3 times, most recently from c6b7d27 to 624f7bc Compare September 16, 2025 22:52
@mitchdenny mitchdenny marked this pull request as ready for review September 17, 2025 00:41
@@ -5,5 +5,6 @@
the Aspire.AppHost.Sdk -->
<SkipAspireWorkloadManifest>true</SkipAspireWorkloadManifest>
<IsAspireHost>true</IsAspireHost>
<PublishAot>false</PublishAot>
Copy link
Member

Choose a reason for hiding this comment

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

This isn't working for me when I try it locally. I think file-based apps get this property explicitly written to their virtual project file which would override this. We might have to move this to our targets file instead. I'm trying that in #11445

Copy link
Member

Choose a reason for hiding this comment

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

If it works can you apply to this PR?

@mitchdenny mitchdenny force-pushed the copilot/vscode1757892604932 branch from 091c7d4 to 8e4d42a Compare September 17, 2025 02:29
@mitchdenny mitchdenny force-pushed the copilot/vscode1757892604932 branch from 8e4d42a to 091c7d4 Compare September 17, 2025 02:31
@mitchdenny mitchdenny changed the base branch from mitchdenny/singlefile-template to main September 17, 2025 02:37
@mitchdenny mitchdenny force-pushed the copilot/vscode1757892604932 branch from 091c7d4 to 32a0df1 Compare September 17, 2025 02:38
Copy link
Contributor

github-actions bot commented Sep 17, 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 -- 11393

Or

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

@davidfowl davidfowl merged commit 885f771 into main Sep 17, 2025
311 checks passed
@davidfowl davidfowl deleted the copilot/vscode1757892604932 branch September 17, 2025 07:43
@davidfowl
Copy link
Member

testeed

@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.

4 participants