Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Oct 27, 2025

Summary: Fix Default Output Path Issue During Aspire Deploy

The issue occurs when aspire deploy or aspire do <step> is called without an explicit --output-path. Previously, various parts of the code assumed OutputPath would always be set, causing failures.

Solution (Rebased on latest main)

Following feedback, the fix now sets defaults at the PipelineContext level and simplifies the code:

  1. Default OutputPath is set in PipelineContext constructor to Path.Combine(Environment.CurrentDirectory, "aspire-output") when null

  2. Added IntermediateOutputPath property to PipelineContext for temporary build artifacts

    • Uses Directory.CreateTempSubdirectory to create temp folders
    • For known apphosts: creates subfolder with prefix aspire-{appHostSha} using IConfiguration["AppHost:PathSha256"]
    • For unknown apphosts: creates subfolder with prefix aspire
  3. Removed PublishingContextUtils class entirely

    • Inlined the simple logic directly in Docker and Kubernetes environment resources
    • Logic: if multiple compute environments, append environment name to output path; otherwise use root output path
  4. Removed CLI default output path logic

    • PublishCommand no longer sets a default output path to "aspire-output"
    • Default is now only set in PipelineContext, ensuring consistency
  5. Changed OutputPath from nullable to non-nullable since it always has a default value

Testing Results

  • CLI tests (DeployCommand): 6/6 passed ✅
  • Kubernetes tests: 10/10 passed ✅
  • Docker tests: 56/56 passed ✅

Files Changed

  • src/Aspire.Hosting/Pipelines/PipelineContext.cs: Added defaults for OutputPath and IntermediateOutputPath using Directory.CreateTempSubdirectory
  • src/Aspire.Hosting/Pipelines/PipelineStepContext.cs: Exposed IntermediateOutputPath, changed OutputPath to non-nullable
  • src/Shared/PublishingContextUtils.cs: Deleted - logic inlined where needed
  • src/Aspire.Hosting.Azure/AzureEnvironmentResource.cs: Removed exception for null OutputPath
  • src/Aspire.Hosting.Docker/DockerComposeEnvironmentResource.cs: Inlined output path logic, removed PublishingContextUtils usage
  • src/Aspire.Hosting.Docker/Aspire.Hosting.Docker.csproj: Removed PublishingContextUtils.cs reference
  • src/Aspire.Hosting.Kubernetes/KubernetesEnvironmentResource.cs: Inlined output path logic, removed PublishingContextUtils usage
  • src/Aspire.Hosting.Kubernetes/Aspire.Hosting.Kubernetes.csproj: Removed PublishingContextUtils.cs reference
  • src/Aspire.Hosting.Docker/DockerComposePublishingContext.cs: Removed null check exception
  • src/Aspire.Hosting.Kubernetes/KubernetesPublishingContext.cs: Removed null check exception
  • src/Aspire.Hosting/Cli/Commands/PublishCommand.cs: Removed default output path logic (now handled in PipelineContext)

The fix ensures consistent and predictable output paths across all publish/deploy commands, with defaults set at a single location in PipelineContext.

Original prompt

This section details on the original issue you should resolve

<issue_title>Default output path set from CLI not respected during aspire deploy</issue_title>
<issue_description>The default output path that should be set during aspire deploy is not respected on the host side. Things work fine if you call aspire publish at the top level but not if you do aspire do publish-step.

Instead of throwing an exception when the OutputPath is set, use a fallback value that is the CWD + aspire-output in the PublishingContext for each resource.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Update PublishingContextUtils.GetEnvironmentOutputPath to use fallback when OutputPath is null
- Fallback is Path.Combine(Environment.CurrentDirectory, "aspire-output")
- Add comprehensive tests for null and non-null output paths
- Add tests for single and multiple environment scenarios

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix default output path handling during aspire deploy Fix default output path fallback for aspire deploy Oct 27, 2025
Copilot AI requested a review from captainsafia October 27, 2025 20:50
@github-actions
Copy link
Contributor

github-actions bot commented Oct 27, 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 -- 12414

Or

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

1 similar comment
@github-actions
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 -- 12414

Or

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

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

@copilot We need to fix all the of the checks when initializing the output path:

Unify the handling for output path across all these areas.

Copy link
Member

Choose a reason for hiding this comment

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

Delete this test file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in commit 5ce261a.

- Azure: Use fallback to Path.Combine(Environment.CurrentDirectory, "aspire-output") when OutputPath is null
- Docker: Remove null check exception since PublishingContextUtils.GetEnvironmentOutputPath guarantees non-null
- Kubernetes: Remove null check exception since PublishingContextUtils.GetEnvironmentOutputPath guarantees non-null
- Delete PublishingContextUtilsTests.cs as requested

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 28, 2025

@copilot We need to fix all the of the checks when initializing the output path:

Unified output path handling across all three locations in commit 5ce261a:

  • Azure: Added fallback to Path.Combine(Environment.CurrentDirectory, "aspire-output") when OutputPath is null
  • Docker: Removed exception since PublishingContextUtils.GetEnvironmentOutputPath guarantees non-null
  • Kubernetes: Removed exception since PublishingContextUtils.GetEnvironmentOutputPath guarantees non-null

@davidfowl
Copy link
Member

@copilot Let's do this generally at the PipelineStepContext level and set a default top level when creating it. Let's also add an IntermediateOutputPath and default that to a temporary folder derived from apphost path (IConfiguration["AppHost:PathSha256"]).

…utputPath

- Set OutputPath default to Path.Combine(Environment.CurrentDirectory, "aspire-output") in PipelineContext constructor
- Add IntermediateOutputPath property to PipelineContext, defaulting to Path.Combine(Path.GetTempPath(), "aspire", appHostSha)
- IntermediateOutputPath uses IConfiguration["AppHost:PathSha256"] for consistent temporary folder per apphost
- Change OutputPath from nullable to non-nullable since it always has a default value
- Simplify PublishingContextUtils to use non-nullable OutputPath
- Update Azure, Docker, and Kubernetes to use non-nullable OutputPath
- Remove redundant null checks and exceptions

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot Let's do this generally at the PipelineStepContext level and set a default top level when creating it. Let's also add an IntermediateOutputPath and default that to a temporary folder derive...

Implemented in commit 7a481ce:

  • Set default OutputPath at PipelineContext level to Path.Combine(Environment.CurrentDirectory, "aspire-output") when null
  • Added IntermediateOutputPath property to PipelineContext, defaulting to Path.Combine(Path.GetTempPath(), "aspire", appHostSha) using IConfiguration["AppHost:PathSha256"]
  • Changed OutputPath to non-nullable since it now always has a default value
  • Simplified all consuming code to use non-nullable OutputPath

Copilot AI changed the title Fix default output path fallback for aspire deploy Set default OutputPath and add IntermediateOutputPath at PipelineContext level Oct 31, 2025
Copilot AI requested a review from davidfowl October 31, 2025 01:11
…and remove CLI default output path

- Use Directory.CreateTempSubdirectory for IntermediateOutputPath instead of manual path construction
- Remove PublishingContextUtils class entirely and inline logic where needed
- Inline GetEnvironmentOutputPath logic in Docker and Kubernetes environment resources
- Remove PublishingContextUtils.cs file and references from .csproj files
- Remove special case logic in PublishCommand that sets default output path to "aspire-output"
- Output path now defaults in PipelineContext only, not in CLI

Co-authored-by: davidfowl <95136+davidfowl@users.noreply.github.com>
@davidfowl
Copy link
Member

@copilot Redo this change in the face of the merge conflcit

Copy link
Contributor Author

Copilot AI commented Oct 31, 2025

@copilot Redo this change in the face of the merge conflcit

Rebased all changes onto latest main in commit ffacbc0. All changes have been reapplied cleanly on top of the latest main branch. Tests pass successfully:

  • CLI DeployCommand tests: 6/6 ✅
  • Docker tests: 56/56 ✅
  • Kubernetes tests: 10/10 ✅

The branch is ready but I need assistance force-pushing the rebased branch since I don't have direct push access.

/// </summary>
public string IntermediateOutputPath { get; } = GetIntermediateOutputPath(serviceProvider);

private static string GetIntermediateOutputPath(IServiceProvider serviceProvider)
Copy link
Member

Choose a reason for hiding this comment

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

How does this directory get cleaned up?

Copy link
Member

Choose a reason for hiding this comment

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

We dont clean anything up. I think it should be relative to your app folder tbh but I just want to flow a property through so we can begin to use it.

private Task PublishAsync(PipelineStepContext context)
{
var outputPath = PublishingContextUtils.GetEnvironmentOutputPath(context, this);
// Inline logic from PublishingContextUtils.GetEnvironmentOutputPath
Copy link
Member

Choose a reason for hiding this comment

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

Why not continue using the shared Utils method?

Copy link
Member

Choose a reason for hiding this comment

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

yea I didn't rrealize what it did originally.

@davidfowl
Copy link
Member

Making a new PR

@dotnet-policy-service dotnet-policy-service bot added this to the 13.0 milestone Oct 31, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Dec 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default output path set from CLI not respected during aspire deploy

4 participants