{"record":{"id":"a0c436650f019199","repo":"microsoft/aspire","slug":"package-reference-p-name-is-missing-a-version","errorCode":null,"errorMessage":"Package reference '{p.Name}' is missing a version.","messagePattern":"Package reference '(.+?)' is missing a version\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Cli/Projects/PrebuiltAppHostServer.cs","lineNumber":916,"sourceCode":"            if (sourceList.Length > 0)\n            {\n                propertyGroup.Add(new XElement(\"RestoreAdditionalProjectSources\", sourceList));\n            }\n        }\n\n        var doc = new XDocument(\n            new XElement(\"Project\",\n                new XAttribute(\"Sdk\", \"Microsoft.NET.Sdk\"),\n                propertyGroup));\n\n        if (packageRefs.Count > 0)\n        {\n            doc.Root!.Add(new XElement(\"ItemGroup\",\n                packageRefs.Select(p =>\n                {\n                    if (p.Version is null)\n                    {\n                        throw new InvalidOperationException($\"Package reference '{p.Name}' is missing a version.\");\n                    }\n                    return new XElement(\"PackageReference\",\n                        new XAttribute(\"Include\", p.Name),\n                        new XAttribute(\"Version\", GetRestoreVersion(p.Name, p.Version, useExactPackageVersions)));\n                })));\n        }\n\n        if (projectRefs.Count > 0)\n        {\n            doc.Root!.Add(new XElement(\"ItemGroup\",\n                projectRefs.Select(p => new XElement(\"ProjectReference\",\n                    new XAttribute(\"Include\", p.ProjectPath!)))));\n        }\n\n        doc.Root!.Add(\n            new XElement(\"Target\",\n                new XAttribute(\"Name\", \"_WriteAspireProjectRefAssemblyNames\"),\n                new XAttribute(\"AfterTargets\", \"Build\"),","sourceCodeStart":898,"sourceCodeEnd":934,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Cli/Projects/PrebuiltAppHostServer.cs#L898-L934","documentation":"When generating the bundled restore project, PrebuiltAppHostServer writes a PackageReference element per package. A package reference without a version cannot be restored, so before writing the element it throws InvalidOperationException naming the package. This guards against generating an MSBuild file that would fail later with a more confusing NuGet error.","triggerScenarios":"A package descriptor in the prebuilt AppHost configuration has Name set but Version null while building the generated project's ItemGroup for PackageReference items.","commonSituations":"A hand-edited or truncated closure/config file listing packages without versions; a generator bug or older manifest format that omitted Version; Central Package Management assumptions where versions are expected to come from Directory.Packages.props but the generated project has no such import.","solutions":["Add an explicit Version to the package entry in the closure/config that lists it.","Regenerate the manifest/closure with the tooling that emits versions so every PackageReference carries one.","Check whether central package management removed the per-reference version and supply the version the bundle restore expects."],"exampleFix":"// before\n<PackageReference Include=\"Aspire.Hosting.Redis\" />\n// after\n<PackageReference Include=\"Aspire.Hosting.Redis\" Version=\"9.4.0\" />","handlingStrategy":"validation","validationCode":"var bad = packageRefs.Where(p => p.Version is null).ToList();\nif (bad.Count > 0) throw new InvalidOperationException(\"Missing versions: \" + string.Join(\",\", bad.Select(p => p.Name)));","typeGuard":"static bool HasVersion(PackageRef p) => p.Version is not null;","tryCatchPattern":"try { GenerateRestoreProject(packageRefs); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"is missing a version\"))\n{ logger.LogError(ex, \"Package descriptor missing Version: {Msg}\", ex.Message); }","preventionTips":["Always populate Version when defining package descriptors for bundles.","Validate package descriptor files on load (reject entries without Version).","Don't rely on Directory.Packages.props for generated restore projects — set explicit versions.","Regenerate descriptors with current tooling after format changes."],"tags":["cli","nuget","packagereference","version"],"backgroundTag":"missing-required-config-field","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}