{"record":{"id":"e719a294cefa738f","repo":"microsoft/aspire","slug":"path-to-c-project-could-not-be-determined-the-directory-e719a2","errorCode":null,"errorMessage":"Path to C# project could not be determined. The directory '{projectPath}' must contain a single .csproj file.","messagePattern":"Path to C# project could not be determined\\. The directory '(.+?)' must contain a single \\.csproj file\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs","lineNumber":434,"sourceCode":"        path = PathNormalizer.NormalizePathForCurrentPlatform(Path.Combine(builder.AppHostDirectory, path));\n        var projectMetadata = new ProjectMetadata(path);\n\n        var resource = builder.AddResource(app)\n                              .WithAnnotation(projectMetadata)\n                              .WithProjectDefaults(options);\n\n        resource.OnBeforeResourceStarted((r, e, ct) =>\n        {\n            var projectPath = projectMetadata.ProjectPath;\n\n            // Validate project path\n            if (!projectPath.EndsWith(\".csproj\", StringComparison.OrdinalIgnoreCase) && !projectPath.EndsWith(\".cs\", StringComparison.OrdinalIgnoreCase))\n            {\n                // Project path did not resolve to a .csproj or .cs file\n                var message = Directory.Exists(projectPath)\n                    ? $\"Path to C# project could not be determined. The directory '{projectPath}' must contain a single .csproj file.\"\n                    : $\"The C# app path '{projectPath}' is invalid. The path must be to a .cs file, .csproj file, or directory containing a single .csproj file.\";\n                throw new DistributedApplicationException(message);\n            }\n\n            return Task.CompletedTask;\n        });\n\n        return resource;\n    }\n\n    private static void ApplyProjectResourceOptions(ProjectResourceOptions target, ProjectResourceOptions source)\n    {\n        ArgumentNullException.ThrowIfNull(target);\n        ArgumentNullException.ThrowIfNull(source);\n\n        target.LaunchProfileName = source.LaunchProfileName;\n        target.ExcludeLaunchProfile = source.ExcludeLaunchProfile;\n        target.ExcludeKestrelEndpoints = source.ExcludeKestrelEndpoints;\n    }\n","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/ProjectResourceBuilderExtensions.cs#L416-L452","documentation":"AddCSharpApp throws DistributedApplicationException when the supplied project path is not a .csproj or .cs file and, if it is a directory, that directory does not contain exactly one .csproj file. The message distinguishes two cases: the path exists as a directory without a single .csproj, or the path is otherwise invalid (not a .cs/.csproj file or usable directory). Aspire cannot determine which project to run, so it fails during resource callback validation.","triggerScenarios":"Calling builder.AddCSharpApp(\"name\", path) with a directory containing zero or multiple .csproj files; or with a path not ending in .csproj/.cs that is not a directory; or a mistyped path.","commonSituations":"Pointing at a solution folder or multi-project directory, typos in the path, passing a directory that holds several projects, or using a relative path that resolves differently from the AppHost working directory.","solutions":["Pass the full path to the specific .csproj (or the .cs entry file) directly.","If passing a directory, ensure it contains exactly one .csproj file; move or exclude extra project files.","Fix path typos and verify the path exists relative to the AppHost's working directory.","Move shared class libraries out of the target directory or reference them explicitly instead."],"exampleFix":"// before\nbuilder.AddCSharpApp(\"frontend\", \"../frontend\"); // directory has 2 .csproj files\n\n// after\nbuilder.AddCSharpApp(\"frontend\", \"../frontend/Frontend.csproj\");","handlingStrategy":"validation","validationCode":"var resolved = Path.GetFullPath(projectPath);\nif (!resolved.EndsWith(\".csproj\", StringComparison.OrdinalIgnoreCase) &&\n    !resolved.EndsWith(\".cs\", StringComparison.OrdinalIgnoreCase) &&\n    Directory.EnumerateFiles(resolved, \"*.csproj\").Take(2).Count() != 1)\n{\n    throw new DistributedApplicationException($\"'{projectPath}' must be a .csproj, a .cs file, or a directory with exactly one .csproj.\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    builder.AddCSharpApp(name, projectPath);\n}\ncatch (DistributedApplicationException ex) when (ex.Message.Contains(\"Path to C# project could not be determined\"))\n{\n    logger.LogError(ex, \"Project path '{Path}' does not resolve to a single .csproj.\", projectPath);\n}","preventionTips":["Always point AddCSharpApp at the .csproj file itself.","Ensure target directories contain exactly one .csproj.","Use paths relative to the AppHost project and verify them in a smoke test."],"tags":["projects","path","apphost","validation"],"backgroundTag":"file-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}