Tuesday Coding Tip 07 — Exposing internal bits of .NET projects

●5 ●34 ●98
calendar_today • schedule1 min read
— Originally published at medium.com

Tuesday coding tips are super short posts about various tidbits mainly from C++, but also from other programming languages I use. You can also follow the #TuesdayCodingTips hashtag on Mastodon and Linkedin.


C# has a number of visibility keywords and their combinations. A peculiar one is ‘internal’ which restricts the visibility of the symbols to the current assembly. However, that can be tweaked.

You can manually specify the names of assemblies to which the ‘internal’ bits will be visible. Why is this useful? Because you can expose otherwise private parts of your code to assemblies like unit tests and test code with ease. No more ‘friend’ shenanigans like in C++ unit tests!

Ways how to configure this evolved over the years and the most up-to-date approach seems to be in configuring the project file directly (with the latest MSVC and .NET 5+).

<Project>
    <!-- ... --->

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

</Project>

Want more #csharp & #tuesday-coding-tips deep dives?

Join 6,093+ developers sharing real benchmarks, code breakdowns, and projects. Free forever.

Part 7 of 32 in Tuesday Coding Tips

More Posts

Tuesday Coding Tip 06 - Explicit template instantiation

Jakub Neruda - Apr 7

Tuesday Coding Tip 02 - Template with type-specific API

Jakub Neruda - Mar 10

Dozens of email accounts: learning AI coding tools as a student

rahuldk1105 - Oct 27

The Zero-Net-Loss Fleet & The Mercenary Squad: A Live AI Economy

DEVPlank - Aug 4

Tuesday Coding Tip 31 — Deducing this

Jakub Neruda - Nov 17
chevron_left
2.1k Points • 137 Badges
Brno, Czech Republic • linkedin.com/in/jakub-neruda
43Posts
38Comments
25Connections
Experienced C++ developer, team lead and hobby gamedev. I enjoy writing stuff about C++, clean code, clean architecture, and game development.

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!