Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 28, 2025

Analyzing and fixing the issue where aspire config set writes appHostPath to global settings file instead of local project settings.

Analysis

The issue occurs in the ConfigurationService.FindNearestSettingsFile() method. When aspire run tries to create local settings with the appHostPath, the method walks up the directory tree looking for existing settings files. If the user's project is under their home directory, this search can find the global ~/.aspire/settings.json file and treat it as a "local" settings file, causing the appHostPath to be written globally instead of locally.

Plan

  • Analyze the issue and identify root cause in ConfigurationService.FindNearestSettingsFile()
  • Create focused test to reproduce the issue
  • Implement fix to prevent global settings file from being considered as local
  • Test the fix works correctly
  • Run existing tests to ensure no regressions

Fixes #10699.


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

@mitchdenny
Copy link
Member

@copilot we are changing the strategy for solving this but. To remove ambiguity we are going to rename the global settings file from $HOME/.aspire/settings.json to $HOME/.aspire/globalsettings.json. Update the code to this effect.

Copy link
Contributor Author

Copilot AI commented Jul 28, 2025

@copilot we are changing the strategy for solving this but. To remove ambiguity we are going to rename the global settings file from $HOME/.aspire/settings.json to `$HOME/.aspire/globalsettings.json...

Updated the code to rename the global settings file from $HOME/.aspire/settings.json to $HOME/.aspire/globalsettings.json as requested. This removes the ambiguity since FindNearestSettingsFile() only looks for files named settings.json, so it will never find the global globalsettings.json file when walking up the directory tree.

The change is in commit 67cd7af.

@Copilot Copilot AI requested a review from mitchdenny July 28, 2025 14:11
Copilot finished work on behalf of mitchdenny July 28, 2025 14:11
@mitchdenny mitchdenny marked this pull request as ready for review July 28, 2025 15:12
@Copilot Copilot AI review requested due to automatic review settings July 28, 2025 15:12
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 addresses an issue where aspire config set incorrectly writes the appHostPath to the global settings file instead of local project settings. The problem occurs when the configuration service searches for existing settings files and mistakenly treats the global ~/.aspire/settings.json file as a local settings file when the project is located under the user's home directory.

  • Changes the global settings file name from settings.json to globalsettings.json to avoid conflicts
  • Prevents the configuration service from treating global settings as local settings during path resolution

Comment on lines 43 to +44
var homeDirectory = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
var globalSettingsPath = ConfigurationHelper.BuildPathToSettingsJsonFile(homeDirectory);
var globalSettingsPath = Path.Combine(homeDirectory, ".aspire", "globalsettings.json");
Copy link
Preview

Copilot AI Jul 28, 2025

Choose a reason for hiding this comment

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

Hardcoding the filename 'globalsettings.json' here creates a discrepancy with the ConfigurationHelper.BuildPathToSettingsJsonFile() method that was previously used. Consider creating a constant or method to ensure consistency across the codebase for the global settings filename.

Copilot uses AI. Check for mistakes.

@mitchdenny mitchdenny added this to the 9.4 milestone Jul 28, 2025
@mitchdenny
Copy link
Member

/backport to release/9.4

Copy link
Contributor

Started backporting to release/9.4: https://github.com/dotnet/aspire/actions/runs/16572869923

@mitchdenny mitchdenny changed the title [WIP] aspire config set writes appHostPath to ~/.aspire/settings.json globally, causing incorrect path resolution aspire config set writes appHostPath to ~/.aspire/settings.json globally, causing incorrect path resolution Jul 28, 2025
@mitchdenny mitchdenny merged commit 8f0e385 into main Jul 28, 2025
276 checks passed
@mitchdenny mitchdenny deleted the copilot/fix-10699 branch July 28, 2025 15:38
@davidfowl davidfowl modified the milestones: 9.4, 9.5 Jul 28, 2025
@github-actions github-actions bot locked and limited conversation to collaborators Aug 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aspire config set writes appHostPath to ~/.aspire/settings.json globally, causing incorrect path resolution
4 participants