The Nico solution requires the creation of your solution.
There is another way, without having to compile your solution by reading the resx source file.
var fileName = "CustomResource.resx";
var filePath = Path.Combine(Path.GetDirectoryName(this.Host.ResolvePath("")), "WindowsFormsApplication1", fileName);
var reader = new ResXResourceReader(filePath);
var values = reader.Cast<DictionaryEntry>().ToDictionary(x => x.Key, y => y.Value);
var value = values["entry"];
You should be aware that this method does not check development time if the resource does not exist and you are not getting localized values because you are just reading the file. Both often not necessary with T4 templates.
The following is a working snippet that creates an enumeration from a resource file.
, fileName filePath
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Windows.Forms" #>
<#@ import namespace="System.Resources" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.ComponentModel.Design" #>
<#
var nameSpace = "WindowsFormsApplication1";
var enumName = "CustomEnum";
var fileName = "CustomResource.resx";
var filePath = Path.Combine(Path.GetDirectoryName(this.Host.ResolvePath("")), "WindowsFormsApplication10", fileName);
using (var reader = new ResXResourceReader(filePath))
{
reader.UseResXDataNodes = true;
#>
namespace <#=nameSpace#>
{
public enum <#=enumName#>
{
Undefined,
<# foreach(DictionaryEntry entry in reader) {
var name = entry.Key;
var node = (ResXDataNode)entry.Value;
var value = node.GetValue((ITypeResolutionService) null);
var comment = node.Comment;
var summary = value;
if (!String.IsNullOrEmpty(comment)) summary += " - " + comment;
#>
<#= name #>,
<# } #>
}
}
<#
}
#>