InternalsVisibleTo
InternalsVisibleTo
Section titled “InternalsVisibleTo”The SDK automatically generates [assembly: InternalsVisibleTo("…")] attributes for every non-test
C# project. The friend assembly name is derived from the source project’s resolved $(AssemblyName),
so all naming modes are handled correctly:
- Explicit
<AssemblyName>— if a project sets<AssemblyName>Custom.Assembly</AssemblyName>, the generated attributes useCustom.Assembly.UnitTests,Custom.Assembly.IntegrationTests, etc. - Default —
AssemblyNameisRootNamespace-derived, so fully-qualified names are used (for exampleAcme.MyProject.UnitTests). EnableAssemblyNameGeneration=false— standard .NET behaviour:$(MSBuildProjectName)(for exampleMyProject.UnitTests).
What is generated
Section titled “What is generated”Two categories of friend assemblies are generated:
- TestType variants — for each defined
TestType(Unit,Integration,Architecture,Contract,Functional, …) the SDK emits the$(AssemblyName).{TestType}Testsalias plus the$(TargetProjectName).{TestType}Testsand$(MSBuildProjectName).{TestType}Testsequivalents, so the attribute resolves regardless of whether naming comes from an explicitAssemblyName, the SDK default, or the raw project name. - SharedTesting projects — one per known shared testing project name (
SharedTestingFramework,SharedTestingInfrastructure, etc.). By default (EnableAssemblyNameGeneration=true) with aNamespacePrefixset, these are prefixed (for exampleAcme.SharedTestingFramework); withEnableAssemblyNameGeneration=falsethe raw name is used.
InternalsVisibleTo is also generated for DynamicProxyGenAssembly2 so Moq/NSubstitute dynamic
proxies can access internals.
Disabling automatic InternalsVisibleTo
Section titled “Disabling automatic InternalsVisibleTo”To disable automatic InternalsVisibleTo generation, set DisableAutoInternalsVisibleTo=true in your
project or Directory.Build.props:
<PropertyGroup> <DisableAutoInternalsVisibleTo>true</DisableAutoInternalsVisibleTo></PropertyGroup>