views:

30

answers:

2

I have a lot of assemblies that have set the InternalsVisibleToAttribute pointing one specifc assembly within the same solution. Unfortunately the assembly that is being pointed to has a stong name, so I always have to put the same public key token over and over again into the AssemblyInfo.cs files. Since there is no precompiler in c#, how would I ideally eliminate this redundancy.

A: 

maybe you could use t4

rename AssemblyInfo.cs to AssemblyInfo.tt

and add something like this

<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension="cs" #>

[assembly: InternalsVisibleTo("<# Write(System.Reflection.Assembly.GetExecutingAssembly().FullName); #>")]
Kikaimaru
+1  A: 

You have a couple of easy-ish options:

  1. Use a constant instead of a literal in your AssemblyInfo.cs files.
  2. Add this attribute to a shared file (e.g.: CommonFriendAssemblies.cs) that is linked rather than copied into your individual projects.

#1 is somewhat simpler to manage, but it has the unfortunate side-effect of removing IntelliSense support for the referenced internals in the referencing project.

#2 is somewhat more complex to manage, but it doesn't interfere with IntelliSense support.

Nicole Calinoiu