how can i access internals in asp.net 5
Asked Answered
M

3

14

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?

Merthiolate answered 12/1, 2016 at 11:27 Comment(1)
I would've assumed the project.json file, but I can't find it in the schema.Motheaten
C
21

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")]
Caputo answered 12/1, 2016 at 13:12 Comment(0)
C
2

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.

Credendum answered 25/1, 2016 at 17:5 Comment(3)
File doesn't exist. Maybe you should link to a certain commit.Pennebaker
changed to an example commit where the code exists.Credendum
@Credendum Can't seem to get this working. Even after creating the AssemblyInfo.cs file. Is this still the way to do it?Peptone
P
2

While creating an AssemblyInfo.cs file is an option, I prefer to configure this in my project file.

Add this to your .csproj file:

<ItemGroup>
  <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
    <_Parameter1>$(AssemblyName).Tests</_Parameter1>
  </AssemblyAttribute>
</ItemGroup>
Platino answered 10/6, 2021 at 7:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.