有没有一种简单的方法可以使用InternalsVisibleToAttribute? [英] Is there an easy way to use InternalsVisibleToAttribute?

查看:41
本文介绍了有没有一种简单的方法可以使用InternalsVisibleToAttribute?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个C#项目和一个带有主项目单元测试的测试项目.我想拥有可测试的 internal 方法,并且要在没有Visual Studio测试项目可以拥有的不可思议的Accessor对象的情况下进行测试.我想使用 InternalsVisibleToAttribute ,但是每次完成操作后,我都不得不返回并查找操作方法,我记得其中涉及创建密钥文件对程序集进行签名,然后使用 sn.exe 获取公共密钥,依此类推.

I have a C# project and a test project with unit tests for the main project. I want to have testable internal methods and I want to test them without a magical Accessor object that you can have with Visual Studio test projects. I want to use InternalsVisibleToAttribute but every time I've done it I've had to go back and look up how to do it, which I remember involves creating key files for signing the assemblies and then using sn.exe to get the public key and so on.

  • 是否有一个实用程序可以自动执行以下过程:创建SNK文件,设置项目以对程序集进行签名,提取公钥以及应用 InternalsVisibleTo 属性?

  • Is there a utility that automates the process of creating a SNK file, setting projects to sign the assemblies, extracting the public key, and applying the InternalsVisibleTo attribute?

是否可以使用没有 签名程序集的属性?

Is there a way to use the attribute without signed assemblies?

推荐答案

您不必使用签名程序集即可使用 InternalsVisibleTo .如果不使用签名的程序集,则只需输入程序集的全名即可.

You don't have to use signed assemblies to use InternalsVisibleTo. If you don't use signed assemblies, you can just enter the full name of the assembly.

因此,如果要访问测试程序集( MyAssembly.Test )中的 MyAssembly ,则需要在 AssemblyInfo.cs 中进行所有操作 MyAssembly 是测试程序集的名称,如下所示:

So if you want to have access to MyAssembly in you test assembly (MyAssembly.Test) all you need in AssemblyInfo.cs for MyAssembly is the name of the test assembly like this:

[assembly: InternalsVisibleTo("CompanyName.Project.MyAssembly.Test")]

这篇关于有没有一种简单的方法可以使用InternalsVisibleToAttribute?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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