Skip to content

Instantly share code, notes, and snippets.

@kazuk
Created April 17, 2013 08:22
Show Gist options
  • Save kazuk/5402657 to your computer and use it in GitHub Desktop.
Save kazuk/5402657 to your computer and use it in GitHub Desktop.
InternalsVisibleTo 属性を吐くT4 Template
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
using System.Runtime.CompilerServices;
<#
RenderInternalsVisibleTo(
"DocOfCode.Tests",
LoadSignKey( Path.Combine( Path.GetDirectoryName( Host.TemplateFile ), @"..\SignKeys\key.snk" ) ));
#>
<#+
public byte[] LoadSignKey( string pathName )
{
using( var file = File.Open( pathName, FileMode.Open ) )
{
var keyPair = new StrongNameKeyPair( file );
return keyPair.PublicKey;
}
}
public void RenderInternalsVisibleTo( string assemblyName, byte[] publicKey )
{
#>
[assembly: InternalsVisibleTo("<#=assemblyName#>, publicKey=<#=string.Join("",publicKey.Select(b=>b.ToString("x2")))#>")]
<#+
}
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment