views:

118

answers:

2

I have a library that defines a class

namespace ClassLibrary1
{
    public class Class1
    {
        public static readonly int Rate = 5;
    }
}

In the same lib I add a tt file

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#@ import namespace="ClassLibrary1" #>
<#@ assembly name="ClassLibrary.dll" #>

enum  MilkRate{ Walmart=<#= Class1.Rate #>}

I get error "Compiling transformation: Metadata file 'ClassLibrary.dll' could not be found d:\documents\visual studio 10\Projects\ConsoleApplication2\ClassLibrary1\TextTemplate1.tt"

how to solve this?

[Occurs on VS 2010, VS2008]

+1  A: 

I'm not sure if that is possible.

I think the problem I might have with that is: your template is generating code that will change the dll that it is referencing!

One thing you can do is have one template reference another template using:

<#@ include file="Helper.tt" #>

In that way you could define Rate = 5 in one central template and have everything else reference that. You could even build a template to generate your Class1 class so everything is held in one central place.

I know that doesn't directly answer your question but I hope it's useful any way.

Wilfred Knievel
+1  A: 

Have you tried posting to the VS Extensibility forum at http://social.msdn.microsoft.com/Forums/en-US/vsx/threads?

Esther Fan - MSFT