Closed Barsonax closed 5 years ago
Great writeup and analysis 👍
I'm flagging this as up for grabs, since you already proposed a fix that looks self-contained enough for a collaborative PR, maybe with a few iterations extra due to the importance of package management.
Unfortunately for some reason the Update method is not virtual and also needs the targetframework. Thus the final solution will contain some less desirable code such as hiding methods with new
.
Ugh it could have been so clean...
Made a PR: #710
Fixed by @Barsonax in #710. Release in progress. Closing this.
Summary
When installing a plugin which has multiple targetframeworks in the
package/metadata/dependencies
node duality can pick the wrong framework and then complain about not being able to resolve dependencies. This can happen when it picks the.NETStandard1.1
framework for instance. A example of anuspec
with multiple targetframeworks can be found below:If you try to install such a package you will get a similar error to the following:
The problem seems to be that the packagemanager doesn't know what framework it should be looking for so instead of picking the
.NETFramework4.5.2
it picks the.NETStandard1.1
. I confirmed this by decompiling theInstallPackage
method inNuget.Core
:Luckily this method is virtual and as such we can override it:
Then replace the nuget packagemanager with our own derived class here
With the above modification duality succeeds in installing the package. So I think the solution is to derive from
NuGet.PackageManager
and override the methods in order to pass in the correct targetframework.Note there is a overload of
InstallPackage
which does accept a targetframework but itsprotected
:How to reproduce
nupkg
files to it. Make sure the test package has multiple targetframeworks defined (I used.NETFramework4.5.2
and.NETStandard1.1
). If one of the test packages has dependencies you need to include them all:Build\Output
and open upPackageConfig.xml
to make sure theRepositoryUrl
points to the folder we created in step 1.Workaround