how can i access internals in asp.net 5

2019-04-19 09:43发布

Before asp.net 5 I would add "internalsVisibleTo(some.namespace.name)" to AssemblyInfo.cs - But I no longer have assemblyInfo.cs in my WebApi project.

How do I expose internals in a WebAPI project to my unitTest project?

2条回答
ら.Afraid
2楼-- · 2019-04-19 10:05

You can add your own AssemblyInfo.cs file. Just add a class file, name it AssemblyInfo.cs (or any name for that matter), and replace all of its code with the following line:

[assembly: System.Runtime.CompilerServices.InternalsVisibleTo("some.assembly.name")]
查看更多
老娘就宠你
3楼-- · 2019-04-19 10:25

You can see an example of the above answer in action in the asp open sourced MVC project available on github:

https://github.com/aspnet/Mvc/blob/e2fd41e416ce1d84e13734ebfb56e64094607d01/src/Microsoft.AspNetCore.Mvc.Abstractions/Properties/AssemblyInfo.cs

One of the best ways of figuring this stuff out is to get in there and have a dig about.

Good luck.

查看更多
登录 后发表回答