Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Oct 6, 2025

Summary

Fixes the code snippets in the "WithCommand and WithWorkingDirectory APIs" section of the Aspire 9.5 release post that were causing compilation errors, and updates examples to better demonstrate the fluent-mutable nature of these new APIs.

Problem

The code examples were calling AddExecutable with only 2 parameters (name and executable), but the API requires at least 3 parameters to compile:

// This doesn't compile - missing required working directory parameter
var processor = builder.AddExecutable("data-processor", "python")
    .WithCommand("main.py --batch-size 100")
    .WithWorkingDirectory("/app/data-processing");

Error: No overload for method 'AddExecutable' takes 2 arguments [CS1501]

Solution

Fixed the compilation errors and updated examples to better demonstrate that WithCommand and WithWorkingDirectory enable fluent-mutable configuration of executable resources:

First example - Sets working directory directly in AddExecutable:

var processor = builder.AddExecutable("data-processor", "python", "/app/data-processing")
    .WithCommand("main.py --batch-size 100")
    .WithArgs("--config", "production.json");

Second example - Demonstrates mutability by changing the working directory after initial setup:

var buildTool = builder.AddExecutable("build-tool", "npm", ".")
    .WithCommand("run build:production")
    .WithWorkingDirectory("./frontend");

This approach makes it clear that these APIs allow you to modify command and working directory after resource creation, which is valuable for scenarios where configuration needs to be adjusted dynamically (related to dotnet/aspire#10649).

Changes

  • Fixed compilation errors by adding required working directory parameter to AddExecutable calls
  • Updated examples to demonstrate the fluent-mutable API pattern
  • Updated description text to clarify these APIs "enable fluent, mutable configuration of executable resources"
  • Verified compilation by building a test AppHost project with the corrected code

Fixes #2975

Co-authored-by: IEvangelist [email protected]

Original prompt

This section details on the original issue you should resolve

<issue_title>9.5 Release Post has a code snippet that does not compile</issue_title>
<issue_description>### Type of issue

Typo

Description

First congrats on another release 🚀
While reading the release post, I noticed a snippet that doesn't compile on Aspire 9.5 nor Aspire 9.5.1

The snippet can be found at https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9.5#withcommand-and-withworkingdirectory-apis

// Configure executable with custom command and working directory
var processor = builder.AddExecutable("data-processor", "python")
    .WithCommand("main.py --batch-size 100")
    .WithWorkingDirectory("/app/data-processing")
    .WithArgs("--config", "production.json");

// Executable with specific working directory for relative paths
var buildTool = builder.AddExecutable("build-tool", "npm")
    .WithCommand("run build:production")
    .WithWorkingDirectory("./frontend");

Throws the error:

No overload for method 'AddExecutable' takes 2 arguments[CS1501](https://msdn.microsoft.com/query/roslyn.query?appId=roslyn&k=k(CS1501))

The working directory is the 3rd argument of AddExecutable and I think that should fix it.
But then, it doesn't make sense to add it to the "WithCommand and WithWorkingDirectory APIs" section.

// Configure executable with custom command and working directory
var processor = builder.AddExecutable("data-processor", "python", "/app/data-processing")
    .WithCommand("main.py --batch-size 100")
    .WithArgs("--config", "production.json");

// Executable with specific working directory for relative paths
var buildTool = builder.AddExecutable("build-tool", "npm", "run build:production")
    .WithWorkingDirectory("./frontend");

Page URL

https://learn.microsoft.com/en-us/dotnet/aspire/whats-new/dotnet-aspire-9.5

Content source URL

https://github.com/dotnet/docs-aspire/blob/main/docs/whats-new/dotnet-aspire-9.5.md

Document Version Independent Id

e2e991b9-430a-41da-7b32-7c111e952fae

Platform Id

912ec644-ff51-25d7-c01c-7208e400c144

Article author

@IEvangelist

Related Issues</issue_description>

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

Fixes #4986

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


Internal previews

📄 File 🔗 Preview link
docs/whats-new/dotnet-aspire-9.5.md docs/whats-new/dotnet-aspire-9.5

@Copilot Copilot AI changed the title [WIP] 9.5 Release Post has a code snippet that does not compile Fix AddExecutable compilation errors in 9.5 release post Oct 6, 2025
@Copilot Copilot AI requested a review from IEvangelist October 6, 2025 12:58
Copilot finished work on behalf of IEvangelist October 6, 2025 12:58
Copy link
Member

@IEvangelist IEvangelist left a comment

Choose a reason for hiding this comment

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

These are the changes that should have been made.

@IEvangelist
Copy link
Member

At first, I assumed that all we needed to fix was adding the workingDirectory parameter to the AddExecutable call, but after re-reading this I agree with you @timdeschryver, how does this API make sense at all?

We already had finite control over executables, both the command and workingDirectory are available (required) parameters. These APIs just allow you to change them, which is kind of odd.

@IEvangelist
Copy link
Member

Ah, I see now... it's related to this dotnet/aspire#10649

@IEvangelist
Copy link
Member

Hey @copilot please update this pr, considering the related issue and the extended API, making it more obvious that this .WithCommnd and .WithWorkingDirectory are enabling a fluent-mutable API around the IResourceBuilder<ExecutableResource> type. See all comments.

Copy link
Contributor Author

Copilot AI commented Oct 6, 2025

Hey @copilot please update this pr, considering the related issue and the extended API, making it more obvious that this .WithCommnd and .WithWorkingDirectory are enabling a fluent-mutable API aro...

Updated the examples to better demonstrate the fluent-mutable API:

  • First example now sets the working directory directly in AddExecutable without using WithWorkingDirectory
  • Second example demonstrates mutability by changing the working directory after initial setup
  • Updated the description to clarify these APIs enable mutable configuration of executable resources

Commit: Updated examples in the latest commit.

@Copilot Copilot AI changed the title Fix AddExecutable compilation errors in 9.5 release post Fix AddExecutable compilation errors and improve API demonstration in 9.5 release post Oct 6, 2025
@Copilot Copilot AI requested a review from IEvangelist October 6, 2025 23:11
Copilot finished work on behalf of IEvangelist October 6, 2025 23:11
@IEvangelist IEvangelist marked this pull request as ready for review October 7, 2025 13:22
@Copilot Copilot AI review requested due to automatic review settings October 7, 2025 13:22
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 pull request fixes compilation errors in the Aspire 9.5 release documentation and improves the demonstration of new fluent API features. The issue was that code snippets for AddExecutable were missing the required working directory parameter, causing compilation failures.

Key changes:

  • Fixed compilation errors by providing the required third parameter to AddExecutable calls
  • Updated examples to better demonstrate the fluent-mutable nature of the new WithCommand and WithWorkingDirectory APIs
  • Clarified the description text to emphasize the APIs enable "fluent, mutable configuration"

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.

9.5 Release Post has a code snippet that does not compile
2 participants