Referring EDMX file in Separate VS Project from T4 Template
Posted
by Paul Petrov
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Paul Petrov
Published on Sun, 02 Jan 2011 19:00:33 GMT
Indexed on
2011/01/02
19:54 UTC
Read the original article
Hit count: 290
Filed under:
In my project I needed to separate template generated entities, context in separate projects from the EDMX file. I’ve stumbled across this problem how to make template generator to find edmx file without hardcoding absolute path into the template. Using relative path directly (inputFile=@”..\ProjectFolder\DataModel.edmx”) generated error:
Error 2 Running transformation: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\ProjectFolder\DataModel.edmx'
The code that worked well for me when placed in the beginning of the .tt file:
…
string rootPath = Host.ResolvePath(String.Empty);
string relativePath = @"..\\ProjectDir\\DataModel.edmx";
string inputFile = Path.Combine(rootPath, relativePath);
EdmItemCollection ItemCollection = loader.CreateEdmItemCollection(inputFile);
…
© Geeks with Blogs or respective owner