Skip to content

Instantly share code, notes, and snippets.

@kazuk
Created June 22, 2013 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazuk/5835964 to your computer and use it in GitHub Desktop.
Save kazuk/5835964 to your computer and use it in GitHub Desktop.
プロジェクトのマニフェストリソース名を T4MVC っぽく
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="$(TargetPath)" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#
var hostServiceProvider = Host as IServiceProvider;
var dte = (DTE) hostServiceProvider.GetService(typeof(DTE));
var solution = dte.Solution;
var projItem = solution.FindProjectItem( Host.TemplateFile );
var project = projItem.ContainingProject;
string namespaceName = (string) project.Properties.Item("RootNamespace").Value;
string assemblyName = (string) project.Properties.Item("AssemblyName").Value;
var sourceAssembly = AppDomain.CurrentDomain.GetAssemblies()
.Single( a=>a.GetName().Name==assemblyName );
#>
namespace <#=namespaceName#>
{
// ReSharper disable InconsistentNaming
public static class ManifestResourceNames
{
<#
foreach( var item in sourceAssembly.GetManifestResourceNames() )
{
#>
public const string <#=item.Replace(".","_")#>="<#=item#>";
<#
}
#>
}
// ReSharper enable InconsistentNaming
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment