如何将程序集绑定重定向添加到.net核心单元测试项目? [英] How can I add an assembly binding redirect to a .net core unit test project?

查看:72
本文介绍了如何将程序集绑定重定向添加到.net核心单元测试项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试针对框架4.6.1创建一个.net核心单元测试项目,该框架测试依赖于Microsoft.SqlServer.Types(10.0.0.0)的项目。在.net core之前,我将添加具有绑定重定向的app.config文件。我已经尝试过了,但是当我从Visual Studio运行时,绑定重定向似乎没有被接受。我该怎么做才能解决绑定重定向?

I'm trying to create a .net core unit test project against framework 4.6.1 which tests an project dependent on Microsoft.SqlServer.Types (10.0.0.0). Prior to .net core I'd add an app.config file with the binding redirect. I've tried this but the binding redirect does not seem to be picked up when I run from visual studio. What can I do to fix the binding redirect?

推荐答案

如果您引用Microsoft.NET.Test.Sdk> = 15.3.0在您的项目中,它将自动打开所需的MSBuild属性,如下面的Fabian所述。请参阅此处

If you reference Microsoft.NET.Test.Sdk >= 15.3.0 in your project it automatically turns on the required MSBuild properties, as Fabian says below. See here.

您可以将以下设置添加到 .csproj 文件:

You can add the following settings to your .csproj file:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

否则将它们添加到 app.config 如Joao所说,解决方案的根源也是有效的。确保将其复制到输出目录设置为始终复制如果较新则复制

Otherwise adding them to an app.config in the root of the solution, as Joao says, works too. Make sure you set its Copy to Output Directory setting to Copy always or Copy if Newer.

这篇关于如何将程序集绑定重定向添加到.net核心单元测试项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆