OferP
OferP

Reputation: 393

dotnet build - PackageReference to 2 different versions

We are using PackageReference and we are using some 3rd party packages. We encounter some unique case where we need to download 2 different versions from a 3rd party and use them in our build process. This is not an assembly, but rather a folder containing many files so a workaround that handle it in the code isn't relevant.

So far the best answer I could found was - No

How can I achieve it?

Thanks in advance!

Upvotes: 1

Views: 939

Answers (1)

rbennett485
rbennett485

Reputation: 2163

dotnet restore takes each PackageReference in your dependency tree and works out a single version to use for each.

So you are correct that there isn't a way to pull in 2 versions of the same package using a standard PackageReference.

If the assemblies are both being loaded in the same process in your build then it's just not going to work at all.

If the packages are pulling in executables that get forked or something then there will be less nice workarounds.

One option is to add an msbuild task which manually downloads and uses the package you need (pretty nasty).

Another option is to add your own NuGet package source and repackage one of the versions under your own package name, then use the normal PackageReferencesetup with the two different names.

Upvotes: 1

Related Questions