microsoft/aspire · error · DistributedApplicationException

string.Format(LaunchProfileStrings.ProjectFileNotFoundExcept…

Error message

string.Format(LaunchProfileStrings.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath)

What it means

When reading launch settings, GetLaunchSettings(IProjectMetadata) checks that projectMetadata.ProjectPath exists on disk. If the project file is missing it throws DistributedApplicationException with ProjectFileNotFoundExceptionMessage formatted with the path. The project path is recorded when the resource was added and must still be valid when launch settings are read.

Solutions

  1. Verify the path in the error message exists; restore or recreate the missing .csproj file.
  2. Re-add the project in the AppHost (AddProject<T>) so ProjectPath reflects the current location.
  3. If projects were moved, fix the solution references and rebuild the AppHost so fresh metadata is captured.
  4. Ensure any project-generation step (e.g. tests that scaffold projects) runs before launch settings are read.

Example fix

// before: projects/api/Api.csproj was deleted
builder.AddProject<Projects.Api>("api"); // ProjectPath stale

// after: restore projects/api/Api.csproj (or move it back) and rebuild,
// so IProjectMetadata.ProjectPath points at an existing file.
Defensive patterns

Strategy: validation

Validate before calling

var projectPath = metadata.ProjectPath;
if (!File.Exists(projectPath))
    throw new FileNotFoundException($"Project file for resource was moved or deleted: {projectPath}", projectPath);

Try / catch

try { var settings = resource.GetLaunchSettings(); }
catch (DistributedApplicationException ex)
{ logger.LogError(ex, "Project file missing at {Path}; rebuild the AppHost model", projectPath); throw; }

Prevention

When it happens

Trigger: Reading launch settings for a project resource whose IProjectMetadata.ProjectPath points to a .csproj that no longer exists — e.g. after the project file was moved, renamed, deleted, or the AppHost model was built on a different machine.

Common situations: Renaming/moving a project folder without updating the AppHost reference; cloning a repo without restoring all project files; generated projects removed by a clean step; path differences between Windows and Linux checkouts.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/aa3b23a910f6c992. Report an issue: GitHub.

Appendix: source

Thrown at src/Shared/LaunchProfiles/LaunchProfileExtensions.cs:79

            var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.LaunchSettingsFileDoesNotContainProfileExceptionMessage, launchProfileName);
            throw new DistributedApplicationException(message);
        }

        return launchProfile;
    }

    private static LaunchSettings? GetLaunchSettings(this IProjectMetadata projectMetadata, string resourceName)
    {
        // For testing
        if (projectMetadata.LaunchSettings is { } launchSettings)
        {
            return launchSettings;
        }

        if (!File.Exists(projectMetadata.ProjectPath))
        {
            var message = string.Format(CultureInfo.InvariantCulture, LaunchProfileStrings.ProjectFileNotFoundExceptionMessage, projectMetadata.ProjectPath);
            throw new DistributedApplicationException(message);
        }

        var projectFileInfo = new FileInfo(projectMetadata.ProjectPath);
        var launchSettingsFilePath = projectFileInfo.DirectoryName switch
        {
            null => Path.Combine("Properties", "launchSettings.json"),
            _ => Path.Combine(projectFileInfo.DirectoryName, "Properties", "launchSettings.json")
        };

        // It isn't mandatory that the launchSettings.json file exists!
        if (!File.Exists(launchSettingsFilePath))
        {
            if (!projectMetadata.IsFileBasedApp)
            {
                return null;
            }
            else
            {

View on GitHub (pinned to 25830f84bd)