Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

markm
#1 Posted : Monday, October 7, 2013 1:23:30 AM(UTC)
markm
Rank: Newbie

Groups: Member
Joined: 10/5/2013(UTC)
Posts: 2
United States

As in your example "How to generate multiple output files from a single T4 Template", when files are created in a specific folder, either in the current project or a different project, an extra empty file with a txt4 extension is created. Looking at this in Visual Studio, it looks like all the real files are created as children of the empty txt4 file. Is there anyway around creating this extra file? It works, but is kind of annoying. I think the txt4 file is used for syncing the project up with the newly created files and files that may have previously existed but need to be dropped. If I wanted to generate files into a folder, for example, that only included generated files then would that help? Or maybe keep a log file on disk, etc. that can be used for the sync?
tangible | Nico
#2 Posted : Monday, October 7, 2013 11:38:32 AM(UTC)
tangible | Nico
Rank: Administration

Groups: Administration
Joined: 10/8/2012(UTC)
Posts: 29
Germany
Location: Stuttgart

Was thanked: 1 time(s) in 1 post(s)
Hey Mark,

creating a default output file under the T4 template is the standard behavior of the TextTemplatingFileGenerator engine in Visual Studio that does the actual transformation. By design one should not be able to change this behavior.

Nevertheless you can change the output extension of your T4 Template to something resulting in an invalid file name like <#@ output extension="/" #>. This causes the engine to fail the cration of the default output file but creating different output files using the TemplateFileManager still works.

The output generated by the TemplateFileManager is a simple log output and is not needed for any sync purposes. Have a look at lines 327-340 in the TemplateFileManagerV2.1.ttinclude where the output is created using "this._textTransformation.WriteLine...". Just remove or comment those lines and the default output file will remain empty.

Hope this helps,
Nico
markm
#3 Posted : Monday, October 7, 2013 7:59:34 PM(UTC)
markm
Rank: Newbie

Groups: Member
Joined: 10/5/2013(UTC)
Posts: 2
United States

Thanks for the reply. It isn't the log file that I am talking about. If you look at the tutorial at http://t4-editor.tangibl...-single-t4-template.html and scroll down to Part 2: Multiple output files in different projects. The screen shot shows what I am talking about. In this example, the SubFolder has a "child" of MultipleFileOutputToOtherProjects.txt4 and then all the files that were actually created are children of that txt4 file. The tree looks something like this: SubFolder\MultipleFileOutputToOtherProjects.txt4\OutputFile3.txt. I am hoping to be able to not create the txt4 file and instead just put the created files as "children" to SubFolder, something like this: SubFolder\OutputFile3.txt.

Again, it more or less works. I just don't like seeing the extra file with the actual files as children. I have looked at the include template and I don't understand what the purpose of the txt4 file is.

tangible | Nico
#4 Posted : Wednesday, October 9, 2013 1:09:30 PM(UTC)
tangible | Nico
Rank: Administration

Groups: Administration
Joined: 10/8/2012(UTC)
Posts: 29
Germany
Location: Stuttgart

Was thanked: 1 time(s) in 1 post(s)
Okay, now I see your issue. Unfortunately I cannot provide you with a overall clean solution at the moment, but I'll add this to my ToDo-List and maybe create a V2.2 as soon as possible.

Meanwhile have a look at Line 457 in the ProjectSync method of TemplateFileManagerV2.1.ttinclude:
There I replaced the line getting the project item for the output file and provided the Folder instead of the .txt4 Project Item...

Code:

// Remove this line
EnvDTE.ProjectItem pi = VSHelper.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem);

// Replace by these two lines:
EnvDTE.Project prj = VSHelper.GetProject(dte, item.ProjectName);
EnvDTE.ProjectItem pi = VSHelper.GetAllProjectItemsRecursive(prj.ProjectItems).Where(i=>i.Name == item.FolderName).First();

Now the output file is generated directly in the specified folder.
But you lose ability to track visually if those files are automatically generated or manually created...

Kind regards,
Nico

Edited by user Wednesday, October 9, 2013 1:10:03 PM(UTC)  | Reason: Not specified

LandOfToz
#5 Posted : Thursday, June 30, 2016 12:55:52 AM(UTC)
LandOfToz
Rank: Newbie

Groups: Member
Joined: 6/16/2016(UTC)
Posts: 5
United States
Location: Florida

Nico,

There is still a problem with this proposed solution. If you are dropping a file into a project with no folder, then it throws an exception on...

.Where( i=>i.Name == item.FolderName).First()

In my particular case, I have a solution with nested solution folders which contain several projects, some of which contain actual folders. When I try to produce output into one of those project with no folders, the exception is thrown. I also posted another related issue where it is not accounting for nested solution folders and throws a different exception, although I was able to get around that but writing a recursive function and modifying GetAllProjects to call it.
Greg Bell
#6 Posted : Friday, June 8, 2018 5:29:11 AM(UTC)
Greg Bell
Rank: Newbie

Groups: Member
Joined: 6/7/2018(UTC)
Posts: 3
Australia
Location: Peth

Originally Posted by: tangible | Nico Go to Quoted Post
Okay, now I see your issue. Unfortunately I cannot provide you with a overall clean solution at the moment, but I'll add this to my ToDo-List and maybe create a V2.2 as soon as possible.

Meanwhile have a look at Line 457 in the ProjectSync method of TemplateFileManagerV2.1.ttinclude:
There I replaced the line getting the project item for the output file and provided the Folder instead of the .txt4 Project Item...

Code:

// Remove this line
EnvDTE.ProjectItem pi = VSHelper.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem);

// Replace by these two lines:
EnvDTE.Project prj = VSHelper.GetProject(dte, item.ProjectName);
EnvDTE.ProjectItem pi = VSHelper.GetAllProjectItemsRecursive(prj.ProjectItems).Where(i=>i.Name == item.FolderName).First();

Now the output file is generated directly in the specified folder.
But you lose ability to track visually if those files are automatically generated or manually created...

Kind regards,
Nico


With regards to the result of the change above, how do you stop TFM from deleting the existing content in the folder? I'm happy with the result, i.e. all the files are present, and I prefix my files to indicate generation, but when TFM writes to the folder, it removes the existing content. How can I stop it from doing this.

Thanks
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF | YAF © 2003-2020, Yet Another Forum.NET
This page was generated in 0.255 seconds.

Authorization on the site

For an authorized user opens up new possibilities

Login

Password