Relative path

Jun 20, 2011 at 11:41 PM

My apologies for the lack of sophistication of this request for help...

I've tried to recreate your sample, and am having problem with the Generator.includett file and its declaration of the edmx file location.  Specifically I have tried building a project on my desktop and in "my documents" where it normally resides, but it seems that the relative path isn't picking up the location.

I've tried

EdmxFilePath = @"ScheduleView.Web\Models\ScheduleViewModel.edmx";
EdmxFilePath = @"ScheduleView\ScheduleView.Web\Models\ScheduleViewModel.edmx";

My project looks like "ScheduleView\ScheduleView.Web\Models\ScheduleViewModel.edmx".

with its current absolute location: "C:\Users\Mark\Documents\Visual Studio 2010\Projects\ScheduleView\ScheduleView.Web\Models\ScheduleViewModel.edmx"

The failure indicates it is looking for the edmx ...

[error trimmed for brevity]

Error 33 Running transformation: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ScheduleView\ScheduleView.Web\Models\ScheduleViewModel.edmx'.

Is there a step I'm missing to enable the relative path?  A nudge in the correct direction would be greatly appreciated.

Thanks and regards,

Mark

Coordinator
Jun 21, 2011 at 8:22 AM

Hi Mark,

Thanks for tryign out m2m4ria.

The issue with relative paths is soemthing that I don't fully understand. It seems like relative paths are resolved differently when you open a solution by double clicking on it in an explorer window, or when you open it within Visual Studio. You might try that out if you like. This seems to be an issue of T4, not of m2m4ria. However, I would very much welcome an alternative approach that works better.

The simplest way to solve it in your case is to replace the relative paths by absolute paths. So, replace EdmxFilePath = @"ScheduleView.Web\Models\ScheduleViewModel.edmx" by EdmxFilePath = @"C:\Users\Mark\Documents\Visual Studio 2010\Projects\ScheduleView\ScheduleView.Web\Models\ScheduleViewModel.edmx";

Please let me know if this stil doesn't work.

Good luck and best regards,

Merijn

Jun 21, 2011 at 11:53 AM
Edited Jun 21, 2011 at 11:53 AM

Thanks Merijn for taking the time to answer...I never would have come to that conclusion.  It certainly does make a world of difference.  I guess it caches the current directory when you open the *.sln file directly.  I'm still having a couple issues but I'll try and resolve them before I trouble you further.

Kind regards,

Mark

Jul 14, 2011 at 4:48 PM

Hello,

absolute paths are no option for us in our company because every developer has his own local directory branch under which the source code is stored. That's why I had to find another solution and I'm glad that I found one:

  1. Modify the M2MGenerator.ttinclude file as follows:
    EdmxFilePath = @"..\DataModel\SomeDataModel.edmx";
    EdmxFilePath = Host.ResolvePath( EdmxFilePath );
    
    
  2. In order for the Host.ResolvePath() call to work, the attribute hostspecific of the template directive has to be set to true. Do this for all of the files
  • M2M4RiaEntities.tt
  • M2M4RiaLinqToEntitiesDomainService.tt
  • M2M4RiaDomainContext.tt
as follows:
<#@ template language="C#" hostspecific="True" #>


This solution works for relative and absolute paths. Note that the path is relative always to the path in which the corresponding .tt file is located. Because the .tt files are usually distributed over multiple projects, the projects all have to be on the same directory level (so that "..\" leads to the same path for all projects).

Best regards,
Toby

Jul 14, 2011 at 4:49 PM

Thanks very much !!

From: Toby_ [email removed]
Sent: Thursday, July 14, 2011 12:49 PM
To: Mark Tompkins
Subject: Re: Relative path [m2m4ria:262080]

From: Toby_

Hello,

absolute paths are no option for us in our company because every developer has his own local directory branch under which the source code is stored. That's why I had to find another solution and I'm glad that I found one:

1. Modify the M2MGenerator.ttinclude file as follows:

2.  EdmxFilePath = @"..\DataModel\SomeDataModel.edmx";
3.  EdmxFilePath = Host.ResolvePath( EdmxFilePath );
4.   

5. In order for the Host.ResolvePath() call to work, the attribute hostspecific of the template directive has to be set to true. Do this for all of the files

  • M2M4RiaEntities.tt
  • M2M4RiaLinqToEntitiesDomainService.tt
  • M2M4RiaDomainContext.tt

as follows:

<#@ template language="C#" hostspecific="True" #>


This solution works for relative and absolute paths. Note that the path is relative always to the path in which the corresponding .tt file is located. Because the .tt files are usually distributed over multiple projects, the projects all have to be on the same directory level (so that "..\" leads to the same path for all projects).

Best regards,
Toby

Jul 14, 2011 at 4:50 PM

Did we miss a step 4?? Before I cause myself unexpected problems (laughing)

From: Toby_ [email removed]
Sent: Thursday, July 14, 2011 12:49 PM
To: Mark Tompkins
Subject: Re: Relative path [m2m4ria:262080]

From: Toby_

Hello,

absolute paths are no option for us in our company because every developer has his own local directory branch under which the source code is stored. That's why I had to find another solution and I'm glad that I found one:

1. Modify the M2MGenerator.ttinclude file as follows:

2.  EdmxFilePath = @"..\DataModel\SomeDataModel.edmx";
3.  EdmxFilePath = Host.ResolvePath( EdmxFilePath );
4.   

5. In order for the Host.ResolvePath() call to work, the attribute hostspecific of the template directive has to be set to true. Do this for all of the files

  • M2M4RiaEntities.tt
  • M2M4RiaLinqToEntitiesDomainService.tt
  • M2M4RiaDomainContext.tt

as follows:

<#@ template language="C#" hostspecific="True" #>


This solution works for relative and absolute paths. Note that the path is relative always to the path in which the corresponding .tt file is located. Because the .tt files are usually distributed over multiple projects, the projects all have to be on the same directory level (so that "..\" leads to the same path for all projects).

Best regards,
Toby

Jul 14, 2011 at 4:55 PM

No, there is no step 4. I think the quote mechanism in this forum has renumbered the steps and kind of corrupted the numbers. :-)

Coordinator
Aug 2, 2011 at 11:10 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.