It is 2022 and with the introduction of SDK-style projects, another option to put the InternalsVisibleTo
attribute is the project file. Add the following lines to your *.csproj
file:
<ItemGroup>
<InternalsVisibleTo Include="ProjectName.Tests" />
</ItemGroup>
Another case that can be useful is to use parametric project names like that:
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
Not sure but I assume you can use this feature for .NET 5+.
Lastly, I agree with @Tim Lloyd. Putting InternalsVisibleTo
attribute in a central location (either in AssemblyInfo.cs
or project file) in the assembly improves discoverability and eventually this is an assembly-level attribute.