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

查看:25
本文介绍了如何将程序集绑定重定向添加到 .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>

否则,如 Joao 所说,将它们添加到解决方案根目录中的 app.config 也可以.确保将其 Copy to Output Directory 设置设置为 Copy alwaysCopy if Newer.

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天全站免登陆