question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PackageValidation task cannot find nuget package due to version normalization

See original GitHub issue

I tried the new SDK feature following the example at https://devblogs.microsoft.com/dotnet/package-validation/#validation-against-baseline-package-version.

I am getting an error from the task complaining the nuget package has not been found: Error MSB4018 The "Microsoft.DotNet.PackageValidation.ValidatePackage" task failed unexpectedly. System.IO.InvalidDataException: The file is not a valid nupkg. File path: bin\Debug\*******.2.0.0.0.nupkg ---> System.IO.FileNotFoundException: Could not find file 'bin\Debug\********.2.0.0.0.nupkg'.

If I look into the bin\Debug folder I see the nuget package file, but it has a normalized version of 2.0.0 although I explicitly set <PackageVersion>2.0.0.0</PackageVersion>.

If change the PackageVersion to either 2.0.0 or 2.0.0.1 it works as expected.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ViktorHofercommented, Aug 15, 2022

Thanks for reporting @smkanadl. I just submitted a PR that will fix this by using a similar approach as what @cdonnellytx shared.

0reactions
cdonnellytxcommented, Jul 17, 2021

A similar discrepancy in NuGet package filename also occurs if you are using “full” semantic versioning (e.g. PackageVersion=1.2.3-alpha.1+2). The package file generated (at least in Windows, by MSBuild) appears to be bin\Debug\1.2.3-alpha.1.nupkg, not including the +.

I dug into the SDK targets for dotnet (5.0.301, win-x64) and it looks like the first entry in @(NuGetPackOutput) is what is desired, with target _GetOutputItemsFromPack being responsible for what is altering the expected filename.

(I discovered this by using the GitVersion.MsBuild task; the trick is to have unstaged changes out where the currently committed HEAD is not on a tag.)

Update: I found a way to extract it, assuming the output order from GetOutputItemsFromPack is stable and is always xxx.nupkg;xxx.nuspec:

  <Target Name="GetPackageTargetPath" BeforeTargets="RunPackageValidation">
    <ItemGroup>
      <Reversed Include="@(NuGetPackOutput->Reverse())" />
    </ItemGroup>
    <PropertyGroup>
      <PackageTargetPath>%(Reversed.Identity)</PackageTargetPath>
    </PropertyGroup>
<!-- debug dumping out the names for comparison. -->
    <Warning Text="    PackageTargetPath='$(PackageTargetPath)'" />
    <Warning Text="    DEFAULT_PackageTargetPath='$(PackageOutputPath)$(PackageId).$(PackageVersion).nupkg'" />
  </Target>

Reference

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to resolve "Unable to find package" nuget error
I installed VS2017 professional on my system and opened an existing project and found that multiple packages were missing. I tried everything I ......
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
Change the folder permissions and try restoring packages again. You may be using an old version of NuGet. Check nuget.org/downloads for the ...
Read more >
Unable to resolve dependencies of NuGet packages
Solution · Clear the NuGet cache files. You do this in the following way: In the toolbar of Visual Studio, navigate to Tools...
Read more >
NuGet package name, version, and asset ...
To find the normalized name of a package, use the aws codeartifact list-packages command. For more information, see List package names. To find...
Read more >
Cannot install/restore NuGet packages via "Manage ...
The error message produced by any attempt to install or update a NuGet package: Value cannot be null or an empty string. Parameter...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found