1

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]

skaffman
  • 398,947
  • 96
  • 818
  • 769
R.D
  • 4,781
  • 11
  • 41
  • 58

3 Answers3

1

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
  • 3,225
  • 1
  • 26
  • 33
1

You can do this but there are issues with this 'recursive' style of working that require care.

In VS2010, you can use VS Macro variables, $(SolutionDir), $(ProjectDir) and friends in your <#@ assembly #> directive, e.g.

<#@ assembly name="$(ProjectDir)$(OutDir)ClassLibrary.dll" #>

If you then have a developer do a clean get from source control, they'll have to do a build before they can do a working transform.

If they transform first, the transform will fail, then their build will fail and they'll be stuck and have to revert files. It's no big deal, but it can trip folsk up.

GarethJ
  • 6,496
  • 32
  • 42
0

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

Esther Fan - MSFT
  • 8,276
  • 4
  • 27
  • 25