Search code examples
c#.net-standardcsproj.net-standard-2.0internals

How to make internals visible to multiple other assemblies in .NET Standard


I have multiple assemblies which include unit tests for a single .NET Standard 2.0 project. To thoroughly test my project I want the internal classes to be visible to both assemblies.

Here is the part of my .csproj file which makes the internals visible to one assembly:

<ItemGroup>
    <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
        <_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
    </AssemblyAttribute>
  </ItemGroup>

How can I add additional assemblies to this configuration?

Right now it works with either one of the 2 values that I need but I haven't figured out how to make it work for both at the same time. This should be possible, as I have found solutions for this in .NET and .NET Framework, but not .NET Standard.

Any Suggestions?


Solution

  • Just add a second AssemblyAttribute block, like:

    <ItemGroup>
        <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
            <_Parameter1>$(MSBuildProjectName).Tests</_Parameter1>
        </AssemblyAttribute>
        <AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
            <_Parameter1>Other.Assembly.Name</_Parameter1>
        </AssemblyAttribute>
    </ItemGroup>
    

    In the sample above, Other.Assembly.Name stands for the name of the other assembly (omitting directory path and extension).