cake-build / cake

:cake: Cake (C# Make) is a cross platform build automation system.
https://cakebuild.net
MIT License
3.91k stars 729 forks source link

XUnit console runner and binding redirects #1516

Closed nrjohnstone-coolblue closed 7 years ago

nrjohnstone-coolblue commented 7 years ago

I have a test assembly that is using Microsoft.Owin.Testing to spin up a WebAPI2 project in memory and execute some integration tests.

Microsoft.Owin.Testing has a dependency on NewtonSoft.Json 6.0.0.0 so if I upgrade the WebAPI project to NewtonSoft.Json 9.0.0.0 then it correctly applies the binding redirects to the test project as well.

Running the tests in NCrunch and Resharper means the tests pass correctly.

Running them from cake with the XUnit2 task has the tests failing with the following message

System.IO.FileNotFoundException : Could not load file or assembly 'Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified. Stack Trace: at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.JsonMediaTypeFormatter..ctor() at System.Net.Http.Formatting.MediaTypeFormatterCollection.CreateDefaultFormatters() at System.Web.Http.HttpConfiguration.DefaultFormatters(HttpConfiguration config) at System.Web.Http.HttpConfiguration..ctor(HttpRouteCollection routes)

Running the Xunit console directly from the commandline and passing the test assembly in, the tests pass fine....

And as a final test, if I go an add the binding redirects into the xunit.console.exe.config

<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">

  <dependentAssembly>
    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
  </dependentAssembly>
</assemblyBinding>

And THEN run the cake task, the tests pass.

What is Expected?

I would expect that running the Xunit console runner from a cake task would be the same as running it directly from the command line, but it appears that binding redirects are not being applied when running it from the XUnit2 cake task.

What version of Cake are you using?

Are you running on a 32 or 64 bit system?

64bit

What environment are you running on? Windows? Linux? Mac?

Windows 10

How Did You Get This To Happen? (Steps to Reproduce)

Create a simple WebAPI2 project, create a test assembly, spin up a TestServer from Microsoft.Owin.Testing.

Then upgrade newtonsoft to 9.0 and run the XUnit2 task from cake.

nrjohnstone-coolblue commented 7 years ago

Never mind... just discovered I was passing "NoAppDomain = true" in the XUnit settings.... DOH !