Skip to content

Fix Dev Container / Codespaces support for non-default usernames #9538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented May 27, 2025

This PR fixes an issue where Aspire would only work with the default vscode username in Dev Containers and GitHub Codespaces environments. When using a different username in .devcontainer/devcontainer.json configuration (e.g., "remoteUser": "root"), the application would fail with a System.IO.DirectoryNotFoundException because it was looking for configuration files in a hardcoded /home/vscode/ path.

Changes

  • Replace hardcoded /home/vscode/ paths with path segments relative to the user's home directory
  • Add a method to dynamically get the user's home directory using Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
  • Update path construction in GetSettingsPaths() to use the actual user's home directory
  • Add detailed comments explaining the approach

Before

private const string CodespaceSettingsPath = "/home/vscode/.vscode-remote/data/Machine/settings.json";
private const string VSCodeServerPath = "/home/vscode/.vscode-server";
private const string VSCodeInsidersServerPath = "/home/vscode/.vscode-server-insiders";

After

private const string VscodeRemotePathSegment = ".vscode-remote/data/Machine/settings.json";
private const string VscodeServerPathSegment = ".vscode-server";
private const string VscodeInsidersServerPathSegment = ".vscode-server-insiders";

private static string GetUserHomeDirectory() => 
    Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);

This ensures Aspire will work properly regardless of the username specified in the Dev Container or Codespace configuration.

Fixes #9533.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 0t3vsblobprodcus362.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • 7devsblobprodcus323.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • 7k6vsblobprodcus337.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • dlbvsblobprodcus316.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • h6tvsblobprodcus346.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • i1qvsblobprodcus353.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • imzvsblobprodcus368.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • jd4vsblobprodcus366.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • kh4vsblobprodcus325.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • l49vsblobprodcus358.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • ofvvsblobprodcus315.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • p2ovsblobprodcus312.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • pe4vsblobprodcus351.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)
  • x3yvsblobprodcus370.vsblob.vsassets.io
    • Triggering command: /home/REDACTED/work/aspire/aspire/.dotnet/dotnet test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


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

Copilot AI and others added 2 commits May 27, 2025 23:06
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
Co-authored-by: mitchdenny <513398+mitchdenny@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] Dev Container / Codespaces Support does only work with vscode user Fix Dev Container / Codespaces support for non-default usernames May 27, 2025
@Copilot Copilot AI requested a review from mitchdenny May 27, 2025 23:10
Copilot finished work on behalf of mitchdenny May 27, 2025 23:10
@mitchdenny
Copy link
Member

I've verified that this appears to be working within a codespace for the existing vscode user (so existing functionality hasn't broken). Now looking to verify with a devcontainer locally with non-vscode user.

@mitchdenny mitchdenny marked this pull request as ready for review June 16, 2025 03:56
@Copilot Copilot AI review requested due to automatic review settings June 16, 2025 03:56
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 fixes an issue where Aspire used hardcoded paths for configuration files in Dev Containers and GitHub Codespaces, causing failures when a non-default username is used.

  • Replace constant hardcoded paths with relative path segments
  • Introduce a helper method to dynamically retrieve the current user's home directory
  • Update path construction and directory existence checks in GetSettingsPaths() accordingly

@mitchdenny
Copy link
Member

@davidfowl verified this in a local devcontainer, works fine.

@mitchdenny mitchdenny requested a review from davidfowl June 16, 2025 03:57
@mitchdenny mitchdenny merged commit 0ebbd84 into main Jun 16, 2025
508 of 515 checks passed
@mitchdenny mitchdenny deleted the copilot/fix-9533 branch June 16, 2025 06:18
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

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

Dev Container / Codespaces Support does only work with vscode user
3 participants