How do I pull DotNetOpenAuth assembly references into unit test project for ASP.NET MVC4 solution?

旧街凉风 提交于 2019-12-02 03:55:20

I think you should be able to install these as NuGet packages into your unit test project and have them work if you include these binding redirects to your test project's app.config file:

  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>
  <dependentAssembly>
    <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.1.0.0" newVersion="4.1.0.0" />
  </dependentAssembly>

If you have a fresh MVC project and run NuGet's Update-Package command on it, these are automatically created. If you hadn't run that, and installed the NuGet packages fresh into your unit test project, then your unit test project would have references to newer assemblies than your web project did. That would cause the load failure you saw, I think. You just have to make sure that either all your assemblies have common versions across your solution, or that the required binding redirects are in place. And in fact I think the binding redirects are required anyway, since the DotNetOpenAuth assemblies have been updated more recently than the Microsoft.AspNet.WebPages.OAuth package has.

Got some good help from a PM on the ASP.NET team at Msft, who recommended that I copy/reuse the collection of DLLs that are included in the MVC4 project template, which I have done and it's currently working for me.

I copied the DLLs directly to a "non-managed" folder outside of NuGet's purview so that they don't inadvertently get updated unless I really want them to be.

Also worth noting, I had to clean out some references and assy forwarding in web.config to 4.1.0.0, since the MVC4 project template includes 4.0.* of all of the DotNetOpenAuth stuff.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!