InternalsVisibleTo.MSBuild
InternalsVisibleTo.MSBuild copied to clipboard
Enables declaring 'InternalsVisibleTo' items in a .NET project file, rather than declaring them to an AssemblyInfo.cs file.
InternalsVisibleTo.MSBuild
Enables declaring InternalsVisibleTo items in a .NET project file, rather than declaring them in an AssemblyInfo.cs file.
IMPORTANT: starting with .NET 5.0, the SDK already provides support for this. You don't need this package if you're using the .NET 5.0 SDK or later.
How to use
-
Install the
InternalsVisibleTo.MSBuildNuGet package. -
Edit your csproj file and add
<InternalsVisibleTo>items in your project for each assembly that should have access to the internals of the current project:<ItemGroup> <InternalsVisibleTo Include="$(AssemblyName).UnitTests" /> <InternalsVisibleTo Include="SomeOtherAssembly" /> <InternalsVisibleTo Include="StronglyNamedAssembly, PublicKey=0123....." /> </ItemGroup>This will generate the appropriate
InternalsVisibleToattributes for your assembly.Alternatively, you can also use
<InternalsVisibleToSuffix>to specify that assemblies named$(AssemblyName).<suffix>will have access to the internals of the current project:<ItemGroup> <!-- $(AssemblyName).UnitTests will have access to the internals of this project --> <InternalsVisibleToSuffix Include=".UnitTests" /> </ItemGroup>
Note
In fact, it's already possible to declare InternalsVisibleTo attributes in the project file without this package, but the syntax is ugly and hard to remember:
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>SomeOtherAssembly</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
This package just makes things easier by transforming <InternalsVisibleTo> elements into appropriate <AssemblyAttribute> elements.