microsoft/aspire · error · InvalidOperationException

Package reference ' ' is missing a version.

Error message

Package reference '{p.Name}' is missing a version.

What it means

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.

Solutions

  1. Add an explicit Version to the package entry in the closure/config that lists it.
  2. Regenerate the manifest/closure with the tooling that emits versions so every PackageReference carries one.
  3. Check whether central package management removed the per-reference version and supply the version the bundle restore expects.

Example fix

// before
<PackageReference Include="Aspire.Hosting.Redis" />
// after
<PackageReference Include="Aspire.Hosting.Redis" Version="9.4.0" />
Defensive patterns

Strategy: validation

Validate before calling

var bad = packageRefs.Where(p => p.Version is null).ToList();
if (bad.Count > 0) throw new InvalidOperationException("Missing versions: " + string.Join(",", bad.Select(p => p.Name)));

Type guard

static bool HasVersion(PackageRef p) => p.Version is not null;

Try / catch

try { GenerateRestoreProject(packageRefs); }
catch (InvalidOperationException ex) when (ex.Message.Contains("is missing a version"))
{ logger.LogError(ex, "Package descriptor missing Version: {Msg}", ex.Message); }

Prevention

When it happens

Trigger: A package descriptor in the prebuilt AppHost configuration has Name set but Version null while building the generated project's ItemGroup for PackageReference items.

Common situations: 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.

Understand the failure class

Background: "is required", "must be set", "missing required field": configuration validation errors across open-source libraries — this error's family across 36 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Cli/Projects/PrebuiltAppHostServer.cs:916

            if (sourceList.Length > 0)
            {
                propertyGroup.Add(new XElement("RestoreAdditionalProjectSources", sourceList));
            }
        }

        var doc = new XDocument(
            new XElement("Project",
                new XAttribute("Sdk", "Microsoft.NET.Sdk"),
                propertyGroup));

        if (packageRefs.Count > 0)
        {
            doc.Root!.Add(new XElement("ItemGroup",
                packageRefs.Select(p =>
                {
                    if (p.Version is null)
                    {
                        throw new InvalidOperationException($"Package reference '{p.Name}' is missing a version.");
                    }
                    return new XElement("PackageReference",
                        new XAttribute("Include", p.Name),
                        new XAttribute("Version", GetRestoreVersion(p.Name, p.Version, useExactPackageVersions)));
                })));
        }

        if (projectRefs.Count > 0)
        {
            doc.Root!.Add(new XElement("ItemGroup",
                projectRefs.Select(p => new XElement("ProjectReference",
                    new XAttribute("Include", p.ProjectPath!)))));
        }

        doc.Root!.Add(
            new XElement("Target",
                new XAttribute("Name", "_WriteAspireProjectRefAssemblyNames"),
                new XAttribute("AfterTargets", "Build"),

View on GitHub (pinned to 25830f84bd)