locked
T4 - Property "TransformOnBuild" creates different namespaces than using "Transform All" button of IDE RRS feed

  • Question

  • Hi,

    I ran into a problem with the T4 engine of Visual Studio 2010:

    I use "preprocessed" templates to generate code. If I press the "Transform All" button in the Visual Studio IDE, generated CSharp classes are in a namespace corresponding to the directory structure of the project. Example:

    File "...\ProjectDir\Templates\MyTemplate.tt" creates a class "MyTemplate" in the namespace "ProjectNamespace.Templates".

    This is great, because it allows to have templates with the same name in different directories - and even more important: one can use reflection to find or unambiguously identify templates in code.

    The problem:

    I'd like to automatically transform all templates on a build. The TransformOnBuild property seems to be the way to go, but all preprocessed templates transformed that way are "placed" in the same namespace "ProjectNamespace" irrespectively in which folder the .tt file is located.

    Is there any workaround for this issue? Or is it possible to automate template transformation another way?

    Cheers,

    Till

    Thursday, December 20, 2012 10:32 AM

All replies

  • I think you can use fileManager to create the name of file in the .tt file like:

    fileManager.StartNewFile("ProjectNamespace.Templates");

    Please view the article as following below:

    http://msdn.microsoft.com/en-us/data/gg558520

    Hope it is helpful to you.


    崖山之後無中國,明亡之後無華夏

    Monday, December 24, 2012 2:41 AM
  • Thanks for directing me to that article... I've not been aware of the coupling between T4 and the EntityFramework. Great thing!

    But unfortunately your suggestion using fileManager (or any other mechanism that comes along with the EntityFramwork as described in the article) won't work for me, since my current solution does without the EntityFramework and this must remain so, since it is required that the solution can be opened and transformed/compiled/run using Visual C# Express which doesn't contain all assemblies that would be required.

    But I'm going to have a closer look how the namespaces for the generated file is set up in case of the EntityFramework. Perhaps it is possible to adopt something...

    Additional hints / other approaches still welcome :)

    Tuesday, December 25, 2012 4:32 PM