Elton Stoneman

  Home  |   Contact  |   Syndication    |   Login
  120 Posts | 0 Stories | 3601 Comments | 0 Trackbacks

News

Archives

Post Categories

[Source: http://geekswithblogs.net/EltonStoneman]

As Cory pointed out, my original task to execute T4 templates under MSBuild (replacing property markers in the T4 script with evaluated values from the build, see: An MSBuild task to execute T4 templates), fails under MSBuild 3.5. This is down to a change in the object model in the framework. All the useful classes are internal and all the useful properties are private, so they have to be reflected over - which makes my code brittle.

I've updated the task as part of a set here: Sixeyed MSBuild tasks, and it now works with either MSBuild 2.0 or 3.5.

Another update will be coming soon, to allow you to use named item group values, as well as property values and whole item groups in the script. A script can be marked with %(Collection.Identity) and when the task is called iteratively over a collection, the script will be populated with the current collection value each time. I'm also planning to change it to use the T4 engine directly rather than invoking the TextTransform console app, to hopefully speed up the execution time.

I'm using this task increasingly in builds now. It's a lot neater than having multiple XML or Regex file updates, and the template can be used to isolate logic so the builds stay clean. Currently it's used to dynamically generate Wix scripts, generate BizTalk bindings file for a set of environments, generate documentation projects for Sandcastle Help File Builder and produce config files for running DevPartner code coverage. Some of those templates may be generically useful, so I'll add them to MSDN when I get to the next update.

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati
posted on Saturday, October 04, 2008 9:14 AM

Feedback

# re: ExecuteT4Template MSBuild task: Updated 10/15/2008 8:27 AM Woj
Great! Your sample is very useful and instructive, but I've found one weak point...

I've been playing with ExecuteT4Template and the sample project builds "successfuly" even in case of TextTransform.exe errors.

At the minimum you can make
ProcessHelper.Run return int:
-> return process.ExitCode
and then
ExecuteT4Template.Execute
-> if (0 == ProcessHelper.Run...
success = true;

Then build report 'FAILED' in case of transformation errors.
It would be useful to get those by intercepting OutStream messages and return them to build engine to show up ;-)

Best regards

# re: ExecuteT4Template MSBuild task: Updated 10/15/2008 1:02 PM Elton
Hi Woj, glad you've found it useful.

You're right though - when the template engine fails and you get a text file that just says "ErrorGeneratingOutput", the task does not return the failure to MSBuild.

Thanks for your suggestion - I'm looking at removing the use of TextTemplate.exe altogether though, and running the engine direct. That should be quicker and will let me log errors and warnings to the build, and return the correct status.

When I do the next update I'll let you know - I'm also planning to move it to the MSDN Code Gallery and post some proper sample templates.

Elton.

# re: ExecuteT4Template MSBuild task: Updated 3/25/2009 6:01 PM tricky
Firstly thx for the code just waht I was looking for.

I have found a weird error, I build and run the examples from Sixeyed MSBuild tasks link above, but when I try and incorporate the task in my own project I run into null object references trying to resolve the parent project.

I ran the code in debug and discovered the reason is that the contexts dictionary line ProjectFactory line 35 returns a single entry

[1, xxxxxx] not [0,xxxxx]

I have changed my code to obtain the one value in the dict and all seems well so far ...

You can probably shed some more light on this.


# re: ExecuteT4Template MSBuild task: Updated 4/1/2009 10:41 AM Giulio Vian
The path "C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.1" inside the task is valid only for x86. On an x64 the correct path is "C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\1.1".
Moreover "1.1" is for VS08 RTM; VS08 SP1 has "1.2".
HTH

# re: ExecuteT4Template MSBuild task: Updated 4/1/2009 10:57 AM Elton
Thanks Giulio - the task defaults the path as you say, but you can override it in your MSBuild script by specifying the ToolPath property.

# re: ExecuteT4Template MSBuild task: Updated 8/3/2009 11:23 AM Tommaso
I've found the same problem that tricky had. In my case instead of having 0 or 1 I had 38.
I've a target that is something like:
<Target ...>
<ExecuteT4Template...>
<...>
</Target>

if I change it to
<Target ...>
<ExecuteT4Template...>
<...>
</Target>

the key number becomes 39.

The other issue I found is that assemblies referred in the template cannot be found (such as System.Core.dll). I added few lines to add the -P parameters to the command line:

string incldirs="";
foreach (string refpath in helper.GetItemGroupValue("ReferencePath").Split(new char[] { ';' }))
{
incldirs += "-P \"" + Path.GetDirectoryName(refpath)+ "\" ";
}

# re: ExecuteT4Template MSBuild task: Updated 8/18/2009 5:08 AM Tommaso
Regarding the ProjectFactory wrong index problem. I realized that in some case there can be more than one value in the accessed data structure (contexts). In my case a Solution and a Project.
As workaround in Project Factory I check for the project that has among the usingTasks a task with the same name of the type of the executingTask passed as argument. But I am quite sure that there could be some case where two project could be listed and possibly both having conflicting UsingTasks (both uses ExecuteT4Template, for instance).
Here is the code for my workaround:

project = null;
string currentTaskType = executingTask.GetType().Name;
foreach (var cnt in contexts.Values) {
object parentProject = ReflectionHelper.GetPropertyValue(cnt, ReflectedMember.ParentProject);
ms.UsingTaskCollection utc = ReflectionHelper.GetPropertyValue(parentProject, ReflectedMember.UsingTasks) as ms.UsingTaskCollection;
foreach (ms.UsingTask ut in utc) {
if (ut.TaskName == currentTaskType) {
project = new ReflectedProject(parentProject);
break;
}
}
if (project != null)
break;
}

# re: ExecuteT4Template MSBuild task: Updated 1/10/2010 7:27 PM Nick Zdunic
For the following where there is more than one template item the code is also failing.

<Target Name="ExecuteT4Template">
<ExecuteT4Template ... />
<ExecuteT4Template />
</Target>

When it gets to the second template the line in ProjectFactory which gets the contexts (Hastable contexts = ReflectionHelper.GetFieldValue(engineCallback, ReflectedMember.ExecutionContexts) as Hashtable;) has a problem. It returns one context as item zero in the Hashtable, but it's value is null)

Any ideas on why this would be occuring?


# re: ExecuteT4Template MSBuild task: Updated 3/5/2010 5:04 AM Hotel isola d'Elba
Useful info, have sent the link to this blog to my friends. I think people will get a lot better results following this post. I am hopefully going to be one of them. Thanks for putting this information up. This is EXACTLY what I've been looking for.


# re: ExecuteT4Template MSBuild task: Updated 3/5/2010 5:17 AM vacanze isola d'Elba
Admiring the time and effort you put into your blog and detailed information you offer! I didn't know that!


# re: ExecuteT4Template MSBuild task: Updated 4/10/2010 8:11 AM imergent_69
Your blog provided us with valuable information to work with.Each & every tips of your post are awesome.Thanks a lot for sharing.Keep blogging.

# re: ExecuteT4Template MSBuild task: Updated 4/26/2010 6:39 AM content filter-57
First You got a great blog .I will be interested in more similar topics. i see you got really very useful topics , i will be always checking your blog thanks.

# re: ExecuteT4Template MSBuild task: Updated 4/28/2010 9:02 AM neways87
It is very interesting article. I enjoyed your distinguished way of writing this post. You have made it easy for me to understand.Thanks a lot for sharing.Keep blogging.

# re: ExecuteT4Template MSBuild task: Updated 5/30/2010 5:13 AM alberghi toscana mare
Totally informative post.I appreciate the tips and the recommendation.Thanks for the encouraging words.I have bookmarked it already.Keep blogging.

# re: ExecuteT4Template MSBuild task: Updated 6/12/2010 1:41 AM home security systems11
Its really one of the fabulous post which i like a lot.Each & every tips of your post are awesome.Keep up the good works.

# re: ExecuteT4Template MSBuild task: Updated 7/29/2010 8:13 AM Hotel Südtirol
Really a superb entry, definitely useful stuff. Never ever considered I'd find the facts I need right here.Thanks.Keep up the good works.

# re: ExecuteT4Template MSBuild task: Updated 8/5/2010 12:02 PM civitavecchia private taxi
It’s really good and important information’s am really thankful to u as well as I would like to tell you this is really a good article. Looking forward to reading more about this.


# re: ExecuteT4Template MSBuild task: Updated 8/5/2010 12:07 PM Uffizi tickets
Hello there, I’m quite impressed by your blogging ability. I’m a blogger myself.


# re: ExecuteT4Template MSBuild task: Updated 8/5/2010 12:23 PM Cauzione
It's so refreshing to find articles like the ones you post on your site. This is an enlightening blog post that has opened my eyes to new avenues that need to be explored.


# re: ExecuteT4Template MSBuild task: Updated 10/6/2010 3:21 PM Online bargain Lancome UK
Hey there, like what you do here..


# re: ExecuteT4Template MSBuild task: Updated 10/11/2010 7:36 AM tamara lowe
I am really enjoying reading your well written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles.


# re: ExecuteT4Template MSBuild task: Updated 11/27/2010 9:46 AM phlebotomy certification
I really love how it is easy on my eyes and the details are well written. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your rss feed which should do the trick! Have a nice day!

# re: ExecuteT4Template MSBuild task: Updated 12/9/2010 8:23 AM Office 2010 Product Key
Strouds shows are super entertaining and often shows a wonderful unspoiled landscape. His new show, "Off the Grid" has this stingy Al Gore nay-sayer seriously considering building a place for my own family. Thanks Les! Please do more episodes from your Off The Grid Estate!! I'm hooked!
Office 2010 Product Key


# re: ExecuteT4Template MSBuild task: Updated 12/10/2010 8:47 AM Parenting
It's so refreshing to find articles like the ones you post on your site. This is an enlightening blog post that has opened my eyes to new avenues that need to be explored.

# re: ExecuteT4Template MSBuild task: Updated 12/14/2010 3:04 PM Become Radiology Technician
Any way I'll be subscribing to your feed and I hope you post again soon

# re: ExecuteT4Template MSBuild task: Updated 1/4/2011 8:55 AM IGCSE schools in Bangalore
good stuff with marvelous information.

# re: ExecuteT4Template MSBuild task: Updated 1/8/2011 9:14 AM disk backup solutions
T4 means Text Templating Transformation Toolkit which is available in Visual Studio 2005. MSBuild extensions are the part of the Visualization and Modeling SDK. The main benefits of design-time code generation are its simplicity and automatic addition of the generated files in Visual Studio.

# re: ExecuteT4Template MSBuild task: Updated 1/29/2011 8:45 AM persönliche assistenz
Very rarely do I come across a blog thats both informative and entertaining, and let me tell you, youve hit the nail on the head. Your blog is important; the issue is something that not enough people are talking intelligently about.

# re: ExecuteT4Template MSBuild task: Updated 3/9/2011 9:32 AM flowers to australia
You are best i really like your post keep it up

# re: ExecuteT4Template MSBuild task: Updated 3/29/2011 12:31 PM evitamins
I will read time to time that!!!

# re: ExecuteT4Template MSBuild task: Updated 4/18/2011 1:41 PM Planet Shoes Coupons
Thank you for a very clear and helpful post. I am definitely enjoyed to read this post.

# re: ExecuteT4Template MSBuild task: Updated 4/19/2011 7:57 AM Rocawear
I feel very glad for this quality content, you did such a fabulous work in this blog.


# re: ExecuteT4Template MSBuild task: Updated 4/30/2011 11:08 AM Telecom Technologys
Thanks for sharing this wonderful nice thought to us. this is full of adventures and very interesting.

# re: ExecuteT4Template MSBuild task: Updated 5/13/2011 7:02 AM online ged programs
What the result you have when you use T4 engine directly?

# Cheap Christian Louboutins Platforms 5/30/2011 6:38 AM Cheap Christian Louboutins
Christian Louboutin Outlet,Christian Louboutins Cheap,Christian Louboutin Boots Sale,Christian Louboutins For Cheap

# re: ExecuteT4Template MSBuild task: Updated 6/4/2011 11:59 PM London Escorts
We are a group of independents opening a new scheme in our community, you have done a good job here giving us a whole new way of looking at certain issues, great topic ;-)
Indian escorts London

# re: ExecuteT4Template MSBuild task: Updated 6/24/2011 12:00 PM picaboo coupons
Great post!! I love your content and Thankyou very much, I have found this info extremely good!

picaboo coupons


# re: ExecuteT4Template MSBuild task: Updated 6/24/2011 2:30 PM Love Shayari
I Like your posting keepo it up!!!

Love Shayari

# re: ExecuteT4Template MSBuild task: Updated 6/25/2011 7:36 AM janitorial cleaning supplies
this is really what i need thanks for this info.

# re: ExecuteT4Template MSBuild task: Updated 7/14/2011 6:24 AM A2B Lancaster Locksmiths
I can’t imagine the community without your sharings. this is the best place for sharing the topics over here.

# re: ExecuteT4Template MSBuild task: Updated 8/2/2011 10:52 AM Mectaler
Hello there, I’m quite impressed by your blogging ability info Impressive I like it very much

# re: ExecuteT4Template MSBuild task: Updated 8/20/2011 11:51 AM forex currency trading system
thanks for share this great thread.

# re: ExecuteT4Template MSBuild task: Updated 9/24/2011 5:06 PM way2sms login
I'm a regular visitor of this site. Keep it up. Thanks for sharing information that is actually helpful. Good day!


# re: ExecuteT4Template MSBuild task: Updated 10/10/2011 7:43 AM nokia mobiles
I highly appreciate your effort and the points you just raised were worth mentioning. I will recommend you in my blog as well.

nokia mobiles

# re: ExecuteT4Template MSBuild task: Updated 11/20/2011 2:18 PM Keyword Research Tool
I can't wait for the next update to come soon. I'll probably try to implement T4 templates later. Thanks for this update! Have a good day!

# re: ExecuteT4Template MSBuild task: Updated 1/4/2012 5:00 AM web design rajasthan
"I ever welcome to pen in my position something equal that but I work you'r faster

# re: ExecuteT4Template MSBuild task: Updated 1/30/2012 12:45 PM bowling tips
interesting, thanks for all the info.

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: