microsoft/aspire · error · ProjectUpdaterException

Could not find PackageVersion element for

Error message

Could not find PackageVersion element for '{0}' in {1}

What it means

When updating Aspire package versions under Central Package Management, the updater looks up <PackageVersion Include="{packageId}"> in Directory.Packages.props via case-insensitive XPath and requires a Version attribute. If the element is missing or has no Version attribute, it throws ProjectUpdaterException naming the package and file.

Solutions

  1. Add <PackageVersion Include="{packageId}" Version="x.y.z" /> to Directory.Packages.props for the named package, then re-run `aspire update`.
  2. Fix the package id spelling in Directory.Packages.props so it matches the ProjectReference/PackageReference id exactly.
  3. Give the existing <PackageVersion> element a Version attribute if it is missing.

Example fix

// before (Directory.Packages.props)
<PackageVersion Include="Aspire.Hosting.AppHost" />
// after
<PackageVersion Include="Aspire.Hosting.AppHost" Version="9.4.0" />
Defensive patterns

Strategy: validation

Validate before calling

var doc = new XmlDocument(); doc.Load("Directory.Packages.props");
var node = doc.SelectSingleNode($"//PackageVersion[translate(@Include,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='{packageId.ToLowerInvariant()']");
if (node?.Attributes["Version"] is null)
    throw new InvalidOperationException($"Directory.Packages.props is missing a Version for '{packageId}'.");

Try / catch

try { await updater.UpdateAsync(...); }
catch (ProjectUpdaterException ex) when (ex.Message.StartsWith("Could not find PackageVersion element"))
{
    // add <PackageVersion Include="{id}" Version="..."/> to Directory.Packages.props, then retry
}

Prevention

When it happens

Trigger: Updating a package whose id has no <PackageVersion Include="..."> entry in Directory.Packages.props, or whose entry lacks a Version attribute — i.e. the package is referenced by the project but centrally managed metadata is absent/incomplete.

Common situations: Package referenced directly in the csproj with an inline Version while Directory.Packages.props was never given an entry; a typo'd package id in the props file; a hand-edited props file missing the Version attribute; CPM enabled (ManagePackageVersionsCentrally) but props file out of sync.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


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

Appendix: source

Thrown at src/Aspire.Cli/Projects/ProjectUpdater.cs:1219

            logger.LogWarning(ex, "Exception while resolving MSBuild property '{PropertyName}' for project '{ProjectFile}'", propertyName, projectFile.FullName);
            return null;
        }
    }

    private static bool IsValidSemanticVersion(string version)
    {
        return SemVersion.TryParse(version, SemVersionStyles.Strict, out _);
    }

    private static async Task UpdatePackageVersionInDirectoryPackagesProps(string packageId, string newVersion, FileInfo directoryPackagesPropsFile)
    {
        var doc = new XmlDocument { PreserveWhitespace = true };
        doc.Load(directoryPackagesPropsFile.FullName);

        var packageVersionNode = doc.SelectSingleNode(CaseInsensitiveIncludeXPath("/Project/ItemGroup/PackageVersion", packageId));
        if (packageVersionNode?.Attributes?["Version"] is null)
        {
            throw new ProjectUpdaterException(string.Format(CultureInfo.InvariantCulture, UpdateCommandStrings.CouldNotFindPackageVersionInDirectoryPackagesProps, packageId, directoryPackagesPropsFile.FullName));
        }

        packageVersionNode.Attributes["Version"]!.Value = newVersion;
        doc.Save(directoryPackagesPropsFile.FullName);

        await Task.CompletedTask;
    }

    private async Task UpdatePackageReferenceInProject(FileInfo projectFile, NuGetPackageCli package, CancellationToken cancellationToken)
    {
        // Pass --no-restore here so each per-package edit only mutates the project / file-based AppHost.
        // A single restore is performed once *all* update steps have completed (see UpdateProjectAsync).
        // Restoring per-package would run NuGet against a half-updated reference graph, which is fatal
        // when the channel's nuget.config (already merged earlier in UpdateProjectAsync for Explicit
        // channels) contains a packageSourceMapping pinning Aspire* to a feed that does not carry the
        // not-yet-bumped versions. See https://github.com/dotnet/aspire/issues/15891.
        var exitCode = await runner.AddPackageAsync(
            projectFilePath: projectFile,

View on GitHub (pinned to 25830f84bd)