devlooped / moq

The most popular and friendly mocking framework for .NET
Other
5.92k stars 801 forks source link

Use latest version of 'System.Threading.Tasks.Extensions' #690

Closed godrose closed 5 years ago

godrose commented 6 years ago

The version 4.9.0 depends on specific version 4.3.0 of System.Threading.Tasks.Extensions package. This introduces conflicts with other external packages that use later versions of this package (like System.Reactive)

stakx commented 6 years ago

Hi @godrose. Moq is currently intentionally specifying an older version of the STTE NuGet package because of the awful binding redirect problems the latest version of the day caused; see https://github.com/moq/moq4/issues/566#issuecomment-356064411.

But Moq doesn't pin that exact version. You should still be able to install a later version of STTE in your project. This might take some fiddling with NuGet settings.

While Moq is targeting net45 and netstandard13, I am not going to change that particular dependency. (Later edit: Let's not be irrational about it and see if things have improved by now.) Sorry if this seems irrational, I've been burnt rather badly #566 and don't want to run any risk of putting everyone back in that situation.

That being said, NuGet tooling has likely improved in the meantime. Once we update the targeted platform(s) for Moq (see e.g. #630), I'll reevaluate & update all System package dependencies. That's likely going to happen for Moq 4.11.0.

godrose commented 6 years ago

@stakx Thanks for the reply. I was able to install the latest version. That's how I got the conflict. Redirect didn't help. I guess I'll wait until 4.11.0 then.

stakx commented 6 years ago

@godrose - If you are using a recent version of Visual Studio and MSBuild, there should in theory be no need to manually configure binding redirects, unless perhaps you created your project file with previous tooling versions. Find a few things below that you can try.

Using a recent VS version, things should be as simple as this: Create a new console app project (I've tried with both .NET 4.6.1 and .NET Core 2.0). Then install Moq 4.10.0. Then install STTE 4.5.1. The NuGet package manager will tell you that that it's going to upgrade STTE from version 4.3.0 to 4.5.1. Code & run.

Make sure that the project which references Moq, or the executable project "above" it, references the desires version of the STTE package to enforce that package version.

If you are targeting .NET Core, you shouldn't have to do anything esle since .NET Core isn't as strict when it comes to assembly versioning as the .NET Framework.

If you are targeting the .NET Framework however, and you're using the new SDK-style .csproj format, any required binding redirects should be automatically generated for you in the bin\ output folder's .config file (not in the one in your project root!).

If you are not using the new SDK-style .csproj format, you might want to check that there is a <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> entry in your .csproj. This should enable the automatic redirect generation even for the old project file format.

For Moq 4.10.0 and STTE 4.5.1 (both the most recent versions at this time of writing), the generated binding redirect in bin\$(Configuration)\$(ProjectName).exe.config should probably look as follows:

<configuration>
   ...
  <runtime>
    ...
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.0.0" />
      </dependentAssembly>
    </assemblyBinding>
    ...
  </runtime>
  ...
</configuration>
stakx commented 5 years ago

@godrose - Moq 4.10.1 which now uses System.Threading.Tasks.Extensions 4.5.1 should become available on NuGet.org in a short moment.

godrose commented 5 years ago

Perfect timing!

On Mon, 3 Dec 2018 at 21:21 stakx notifications@github.com wrote:

@godrose https://github.com/godrose - Moq 4.10.1 which now uses System.Threading.Tasks.Extensions 4.5.1 should become available on NuGet.org in a short moment.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/moq/moq4/issues/690#issuecomment-443835639, or mute the thread https://github.com/notifications/unsubscribe-auth/AHbkI8AVHA-BrrmuQn9nn98pY5VX0nxeks5u1XmvgaJpZM4WfWdD .

-- Best Regards, Gena