0

In one of my projects I use AutoFixture.AutoMoq package which depends on Moq package

<!-- project1.csproj -->
<PackageReference Include="AutoFixture.AutoMoq">
      <Version>4.11.0</Version>
</PackageReference>

enter image description here

and in another project I use Moq package directly, i.e.

<!-- project2.csproj -->
<PackageReference Include="Moq">
  <Version>4.13.1</Version>
</PackageReference>

The problem is that Visual Studio / MSBuild / Nuget during package version resolution always selects minimal dependency i.e. Moq 4.1.1308.2120 but I would like to use latest version of Moq 4.13.1.

How to tell Visual Studio / nuget to explicitly use requested version ?

UPDATE:

When I try to set Dependency behavior to Highest in Nuget UI I got a message that it doesn't apply to projects using PackageReference approach: enter image description here

tommyk
  • 3,187
  • 7
  • 39
  • 61
  • Hi Tommyk, any update for this issue? This seems an issue on `PackageReference` and l have already report it to the related staff. You can check it and add any useful info under that link. To use the latest dependency Moq so far, you should install the latest `Moq` and then `AutoFixture.AutoMoq`. – LoLance Mar 31 '20 at 09:13
  • 1
    The DC Forum has prioritize your request and I think you can get what you want from [the link](https://developercommunity.visualstudio.com/content/problem/966849/why-dependencyversion-highest-option-cannot-be-use.html). You can check it. – LoLance Apr 02 '20 at 10:02

2 Answers2

1

How to tell Visual Studio / nuget to explicitly use requested version ?

It actually can be done. You should change Dependency behavior to Highest under NuGet Package Manager UI which means it will install all the latest version of the dependencies within the required version range.

Note that all of these are implemented within the scope of the dependencies specified by the package. Moq (>= 4.1.1308.2120 && < 5.0.0)

enter image description here

Solution

Right-click on your project-->Manage Nuget packages-->change Dependency behavior to Highest under Options in the area shown in the image above.

Update 1

Sorry for that this function(the same as use DependencyVersion highest) applies to packages.config format rather than PackageReference. And this option only supports packages.config format. See this link. When you use PackageReference foramt, it will ignore this option.

Besides, there is also a similar issue which have been discussing it for a long time and still occurs in the latest VS version.

Due to it, I have reported this issue in our DC Forum and you can vote for it or add any comments in this link if l miss some other detailed info. Anyone who is interested in this will vote it so that it will get Microsoft's attention as soon as possible.

So it cannot be achieved in one step.

As a suggestion, you should use two steps to release it. First, clean nuget caches first.

  • Install the latest version Moq 4.13.1, and then install the nuget package AutoFixture.AutoMoq 4.11.0.
Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • When I tried this I got a message _These options are not applicable to projects managing their dependencies through project.json or PackageReference_ , see my screenshot above. – tommyk Mar 27 '20 at 10:29
1

Currently NuGet doesn't offer any way to control the versions used for transitive dependencies. There is a proposal in progress which will address the scenario.

By adding the PackageReference to Moq directly (even though it's already implied), you'll be able to pin the version as it's now a primary dependency.

Jimmy
  • 27,142
  • 5
  • 87
  • 100