Just a quick post today. More for my own personal reference (as I forget the syntax every time I try to do this), but it may be useful for others to read.
Back in the day, we used to declare the InternalsVisibleTo attribute in the
AssemblyInfo.cs file. However, this file no longer exists in the new SDK-style projects. You can, of course, still make your own file and add the standard
[assembly: InternalsVisibleTo("YourAssemblyName")] declaration to it.
But, there is also the option of putting this in the csproj itself, via the new
<ItemGroup> <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute"> <_Parameter1>YourAssemblyName</_Parameter1> </AssemblyAttribute> </ItemGroup>
As an aside, you can also use this method to add other custom attributes to your assembly.
As of .NET 5.0, this gets even easier. You can just use the
InternalsVisibleTo item directly!
<ItemGroup> <InternalsVisibleTo Include="YourAssemblyName" /> </ItemGroup>