Geeks With Blogs
Paul's Petrov Whiteboard [BizTalk, Enterprise Application Integration, Business Process Automation, SOA, .NET]
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);

 
 

 

Posted on Sunday, January 2, 2011 1:00 PM .Net | Back to top


Comments on this post: Referring EDMX file in Separate VS Project from T4 Template

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Paul Petrov | Powered by: GeeksWithBlogs.net