Using InternalsVisibleTo Attribute with Strong Named Assemblies
The InternalsVisibleTo Attribute can be used to allow another assembly (such as your Unit Test assembly) to see the internal members of your assembly. I prefer this method to either putting unit tests in my primary assembly or to using the VSTS feature of autogenerating accessors to my private members. (Those are real fun when you go to refactor a project…)
Now most of the info you will find about this refers to the earlier beta usage. The attribute used to take in a PublicKeyToken but now takes in a PublicKey.
To use the InternalsVisibleTo Attribute:
1. Run sn.exe -p MyStrongNameKey.snk MyStrongNameKey.PublicKey
This will extract to public key to a file with the .PublicKey extension. (I hate using the .pub extension because it is seen as a Microsoft Publisher file…)
2. run sn.exe -tp MyStrongNameKey.PublicKey
This will display your public key for you. Copy this key.
3. Create an attribute as such:
[assembly: InternalsVisibleTo( "MyProject.UnitTests, PublicKey=PASTE-YOUR-PUBLIC-KEY-HERE" )]
4. Note that the public key that was displayed was 5 lines or so. Remove the line breaks from the public key and paste it into your attribute.
5. You are done! The assembly MyProject.UnitTests can now see the internal members of your assembly.
Recent Posts
- Understanding API First Strategy and Benefits
- Frankenstein APIs Explained! - API Cyber Security Series
- API Security 101 - Cyber Security Explained
- API Trends 2022 - API Security and Cybersecurity
- API Trends 2022 - Seamless Integration Solutions
- API Trends 2022 - Adaptive API Management
- API Trends 2022 - API Integration Automation
- API Trends 2022 - Industry Specific Breakouts
- API Trends 2022 - API Best Practices
- API Trends 2022 - Open API Standards
- API Trends 2022 - API Integration Experience
- API Trends 2022 - API-Led Modernization
- API Trends 2022 - API Economy Growth
- Brenton House - Give your App and APIs a Turbo Boost – Part 2
- Easily Enable Speech Recognition in Titanium iOS using Hyperloop
Tag Cloud
- .NET
- adaptive api management
- android
- api
- api automation
- api best practices
- api economy
- api experience
- api first
- api integration
- api integrations
- api management
- api security
- api standards
- api strategy
- api trends
- apis
- appcelerator
- automation
- boot
- Brenton House
- C#
- Cisco VPN
- Cloud
- Community News
- Continuous Integration
- crash
- cybersecurity
- Dropbox
- fhir apis
- Free Stuff
- General Software Development
- Google Drive
- graphql
- healthcare apis
- houserules
- hyperloop
- ios
- json schema
- Live Mesh
- Mac OS X
- Microsoft
- mobile
- mobile api
- native
- open banking
- openapi
- Other Stuff
- SkyDrive
- speech
- Stuff
- swagger
- Team Systems
- titanium native
- titanium turbo
- Unit Testing
- Vista
- Visual Studio
- Visual Studio 11
- voice
- win7
- Windows 7
- Windows 8
- windows update