{"record":{"id":"196912c8d4270dc9","repo":"microsoft/aspire","slug":"project-metadata-was-not-found-for-resource-project-name","errorCode":null,"errorMessage":"Project metadata was not found for resource '{project.Name}'.","messagePattern":"Project metadata was not found for resource '(.+?)'\\.","errorType":"exception","errorClass":"DistributedApplicationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs","lineNumber":179,"sourceCode":"    {\n        Writer.WriteString(\"error\", \"This resource does not support generation in the manifest.\");\n        return Task.CompletedTask;\n    }\n\n    private Task WriteConnectionStringAsync(IResourceWithConnectionString resource)\n    {\n        // Write connection strings as value.v0\n        Writer.WriteString(\"type\", \"value.v0\");\n        WriteConnectionString(resource);\n\n        return Task.CompletedTask;\n    }\n\n    private async Task WriteProjectAsync(ProjectResource project)\n    {\n        if (!project.TryGetProjectMetadata(out var metadata))\n        {\n            throw new DistributedApplicationException($\"Project metadata was not found for resource '{project.Name}'.\");\n        }\n\n        var relativePathToProjectFile = GetManifestRelativePath(metadata.ProjectPath);\n\n        var deploymentTarget = project.GetDeploymentTargetAnnotation();\n        if (deploymentTarget is not null)\n        {\n            Writer.WriteString(\"type\", \"project.v1\");\n        }\n        else\n        {\n            Writer.WriteString(\"type\", \"project.v0\");\n        }\n\n        Writer.WriteString(\"path\", relativePathToProjectFile);\n\n        if (deploymentTarget is not null)\n        {","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Hosting/Publishing/ManifestPublishingContext.cs#L161-L197","documentation":"During manifest publishing, ManifestPublishingContext.WriteProjectAsync serializes a ProjectResource, but every project resource must carry IProjectMetadata (its project file path). If the resource is a ProjectResource without that metadata annotation, Aspire cannot emit a valid manifest entry, so it throws DistributedApplicationException. This is an internal model invariant: only AddProject creates valid project resources.","triggerScenarios":"Calling AddResource (or building a custom resource derived from ProjectResource) with a ProjectResource constructed manually that never received IProjectMetadata, instead of using builder.AddProject; or removing/replacing the metadata annotation before publish runs.","commonSituations":"Custom resource-building helpers that new up ProjectResource directly; tests or tools that manipulate the distributed application model and strip annotations; upgrading custom code after the ProjectResource/metadata API changed.","solutions":["Use IDistributedApplicationBuilder.AddProject<TProject>(name) instead of manually constructing ProjectResource so IProjectMetadata is attached automatically.","If building a custom resource, ensure TryGetProjectMetadata succeeds by annotating the resource with IProjectMetadata (project path resolved via PhysicalFile path of the .csproj).","Check custom model transforms/annotations that may remove project metadata before publishing."],"exampleFix":"// before\nvar project = new ProjectResource(\"api\");\nbuilder.AddResource(project);\n// after\nbuilder.AddProject<Projects.Api>(\"api\");","handlingStrategy":"validation","validationCode":"if (!project.TryGetProjectMetadata(out var metadata))\n{\n    throw new InvalidOperationException($\"Resource '{project.Name}' is a ProjectResource without project metadata; use AddProject<T>.\");\n}","typeGuard":"static bool HasProjectMetadata(ProjectResource p) => p.TryGetProjectMetadata(out _);","tryCatchPattern":null,"preventionTips":["Always create project resources via AddProject<TProject>.","Never construct ProjectResource manually in production code.","Review custom model transforms for annotation removal."],"tags":["manifest","publishing","project-resource"],"backgroundTag":"resource-not-found","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-22T11:17:16.035Z"}