Skip to content
This repository has been archived by the owner on Jul 12, 2022. It is now read-only.

Support PackageReference without version #311

Closed
hangy opened this issue Jul 6, 2018 · 14 comments
Closed

Support PackageReference without version #311

hangy opened this issue Jul 6, 2018 · 14 comments
Labels

Comments

@hangy
Copy link

hangy commented Jul 6, 2018

With ASP.NET Core 2.1, the main package reference for the core projects is changed from

<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />

to

<PackageReference Include="Microsoft.AspNetCore.App" />

I think the actual version is determined by the SDK. Running NuKeeper on a csproj that contains this PackageReference displays an ArgumentNullException. This package could be skipped, so that the error is not shown.

Could not read package from <PackageReference Include="Microsoft.AspNetCore.App" /> in file C:\Users\me\Source\Repos\Foo\Bar\Bar.csproj ArgumentException : Value cannot be null or an empty string.
Parameter name: value

Probably caused by the NuGetVersion constructor at

this(new PackageIdentity(id, new NuGetVersion(version)), path)

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

That's... odd :-) this is still a package listed normally on NuGet https://www.nuget.org/packages/Microsoft.AspNetCore.App/ and I definitely missed that "no version" option when upgrading my projects.

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

Simple repro: dotnet new webapi; nukeeper log=Verbose

call stack:

Could not read package from <PackageReference Include="Microsoft.AspNetCore.App" /> in file c:\carnect\test\test.csproj ArgumentException : Value cannot be null or an empty string.
Parameter name: value
   at NuGet.Versioning.NuGetVersion.Parse(String value)
   at NuGet.Versioning.NuGetVersion..ctor(String version)
   at NuKeeper.Inspection.RepositoryInspection.PackageInProject..ctor(String id, String version, PackagePath path) in C:\Code\NuKeeper\NuKeeper.Inspection\RepositoryInspection\PackageInProject.cs:line 15
   at NuKeeper.Inspection.RepositoryInspection.ProjectFileReader.XmlToPackage(XElement el, PackagePath path) in C:\Code\NuKeeper\NuKeeper.Inspection\RepositoryInspection\ProjectFileReader.cs:line 70```

@AnthonySteele
Copy link
Member

Ack! yes, we should just skip this one ref and not crash.
"don't crash" is a good rule for almost any scenario.

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

Played a bit with other packages without a version - NuGet will just install the lowest version published. Ack. But it's valid, just not very useful. Agreed - best behaviour here is to skip.

@AnthonySteele
Copy link
Member

I am not surprised that nuget picks the minimum version; within other constraints like platform support and other packages that could depend on it, with version ranges. I am seeing similar at work where we get an old version of a transitive dependency. Which is sometimes not ideal.

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

Oh, no, for normal packages, it ignores the target platform constraints completely in this case. Just the oldest version published, end of story :-D

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

Grabbing ideas from the Big League: dotnet-outdated filters out "auto-references" based on how NuGet parsing reports them ( https://github.com/jerriep/dotnet-outdated/blob/master/src/DotNetOutdated/Services/ProjectAnalysisService.cs#L69 ) but reports references with missing constraints with the lowest-possible version, as this is also coming from NuGet own parsing ( https://github.com/jerriep/dotnet-outdated/blob/master/src/DotNetOutdated/Program.cs#L183 ). It would be nice to get this behaviour (including version range handling and multiple target framework handling), but it's a big piece of work. For now, skipping those dependencies where we can't read the version seems an acceptable workaround.

@skolima
Copy link
Collaborator

skolima commented Jul 6, 2018

Ah, we do skip those packages and continue with the rest of analysis. See https://github.com/NuKeeperDotNet/NuKeeper/blob/master/NuKeeper.Inspection/RepositoryInspection/ProjectFileReader.cs#L63 (and the implementations for other 2 formats). @AnthonySteele perhaps the solution here is to not log this as _logger.Error but _logger.Verbose ?

@hangy
Copy link
Author

hangy commented Jul 6, 2018

Yup, it does not cause the process to crash, but this being reported as an Error is weird. It might be better to detect the empty version before passing it to the NuGet version, so that it can be skipped correctly (and other Exceptions would still cause an Error).

@AnthonySteele
Copy link
Member

AnthonySteele commented Jul 7, 2018

The PR above should stop this being reported as an error.

In another codebase, I now have imported versions with a range, e.g. <PackageReference Include="AWSSDK.Core" Version="3.3.*" />

It would be good to detect and work with these.

Looking at outdated again, I see types like NuGet.LibraryModel.LibraryDependency which might be useful?

@skolima
Copy link
Collaborator

skolima commented Jul 7, 2018

outdated uses NuGet version range handling. Which is great, but it's going to be a bigger piece of work to move towards it.

@AnthonySteele AnthonySteele added feature and removed bug labels Jul 8, 2018
@AnthonySteele
Copy link
Member

The bug is fixed, what remains is a missing feature.

@skolima
Copy link
Collaborator

skolima commented Aug 29, 2018

Those references might be actually going away; issue to track is dotnet/aspnetcore#3307

@skolima
Copy link
Collaborator

skolima commented Sep 28, 2018

With #443 in place this issue is most likely ready to be closed?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants