SlideShare ist ein Scribd-Unternehmen logo
1 von 46
Using Microsoft’s
T4 Across the Life
of an Application
Gary Pedretti
Gary.Pedretti@Centare.com

             Logo, Design, and Company Information:© 2011 Centare Group, Ltd.
          Slide Show and Notes Content: Creative Commons License, Gary Pedretti
      Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
About Centare
 Consulting Services Organization
   Primary focus on Agile, Mobile and Cloud
 Individual and team based development
   .NET & Java technology stacks
 Microsoft Gold Partner in ALM
 Training, coaching, mentoring & team
 building
   Full Scrum.org course offering
   Best practices training
   Technical and business leadership strategies
Gary Pedretti

Solutions Manager, Agile Practice

Over 12 years in the software industry – Database
Administrator, Developer, Business
Analyst, Application Architect

Scrum: Team member, Scrum
Master, Coach, Certified Scrum Trainer for
Scrum.org

MCPD 4.0 Web, MCTS 4.0 WCF/Web/Data Access, MCDBA MSSQL
2000, PSM, PSD .NET, PSD Java, CSM, MCPD 3.5 ASP.NET, MCTS 3.5
WCF/ASP.NET/ADO.NET, MCTS SharePoint 2003 Infrastructure, MCPD 2.0
Enterprise, MCTS 2.0 Distributed/Web/Windows, MCSD 1.1, MCAD
1.1, MOUS
Professional Scrum at Scrum.org
  Professional       Professional     Professional
     Scrum          Scrum Master         Scrum
 Product Owner                         Developer
                                       .NET or Java

                                         Architects
                                      Business Analysts
   Product Owners                      DB Specialists
                     Scrum Masters
      Executives                         Designers
                                        Developers
                                           Testers




     Professional Scrum Foundations      Everyone
What is T4?
 T4 Basics and T4 Tooling
 Using T4 Across the Life of an Application
What is T4?
 Text Template Transformation Toolkit
 A way to
   Template desired output
   Provide input to the template
   Process the template together with the input to
   produce text output
Text Transformation
 XSLT – XML input, ? output (often
 XHTML)
 Razor (and any number of MVC
 view engines like NVelocity, etc.)
 – ? input (often a Model
 object), (X)HTML output
 T4 – ? input, ? output
   Anything goes
   Designed for generic cases
Why?
 Automate repetitive, boilerplate code
   Data Access code
   Front-end scaffolding
 Produce templated text output to be used by
 applications
   Form letters
 Transformations between different text
 formats
   XML to C#
T4 Pre-History

 CodeSmith was/is the primary mover
 in the .NET space
   Around for a long time, very mature
   Provides an excellent set of ready-to-use
   templates
   Better template editing and debugging
   experience
   Very code-centric (not geared around general
   text or transformations)
   $$ licensing, not free
T4 Pre-History

 Many competitors still exist, free and
 paid
   XY Studio (web-based)
   Atom Weaver (MDD-based)
   Code Generator 360 (ASP.NET DAL-centric)
   Iron Speed Designer (RAD front-to-back)
T4 History

 Increasing importance and support as
 we’ve moved from Visual Studio 2005
 to Visual Studio 2010
   Including out-of-band frameworks
T4 History

 A second-class citizen in Visual Studio
 2005
   Available through the DSL tools download or
   through the Guidance Automation Toolkit
   (GAT – primarily used for software factories)
T4 History

 More of a first-class citizen in VS 2008
   Built-in, but not available through File -> New
   No highlighting or Intellisense
   A lot of “dogfooding” started, especially with
   SP 1 – EF, MVC
T4 History

 Almost a first-class citizen in VS 2010
   Still no highlighting or Intellisense
   Dogfooding all over the place – EF (all
   code generation items), MVC
   2, Architecture Tools)
Microsoft Dogfooding
 ASP.NET MVC
 ADO.NET Entity Framework
 ASP.NET Dynamic Data
 Lightswitch (cannot currently get at the
 templates used, though)
 VS 2010 Architecture Tool Modeling Feature
 Pack (forward-engineering)
Microsoft Dogfooding – ASP.NET MVC

 Add Controller and Add View
 Templates found at [Visual Studio Install
 Directory]Common7IDEItemTemplates[CSharp |
 VisualBasic]WebMVC 2CodeTemplates
Microsoft Dogfooding – ASP.NET MVC
Microsoft Dogfooding – Entity Framework
 Default, EF-aware Entities
   Add the EntityObject Generator as a code
   generation item to see what the default
   template does behind the scenes
 POCO and Self-Tracking Entities
   Implemented through templates
   Add code generation item to see the templates
   in your project
Microsoft Dogfooding – Entity Framework
Microsoft Dogfooding – Architecture Tools

 Modeling Feature Pack (built in to VS 2010
 Feature Pack 2) allows for forward-
 generation of code from diagrams
 Templates found at [Visual Studio Install
 Directory]Common7IDEExtensionsMicrosoftVis
 ualization and Modeling Feature
 Pack2.0TemplatesText
Microsoft Dogfooding – Architecture Tools
Microsoft Dogfooding – Demo
What is T4?

T4 Basics and T4 Tooling
 Using T4 Across the Life of an Application
T4 Text Transformation
Standard Templates
 Design-time templates
 Meant to be run within the context of Visual
 Studio
Precompiled Templates
 Runtime templates
 For text to be used by an application
   Form letters
 For CodeDOM-like activities – dynamic
 compilation of code
   Note T4 would be language-specific where raw
   CodeDOM would not
 Also makes for easily composable and
 reusable blocks
 Just call the TransformText method, it
 returns a string
T4 Syntax - Directives
 Template <#@ template #>
   Language
   Debug
   Inherits
   Hostspecific
 Output <#@ output #>
   Extension
 Import <#@ import #>
   Namespace
   Resolves to “using” in C# generation
T4 Syntax - Directives
 Assembly <#@ assembly #>
   Name
   Equivalent of Add Reference…
   Careful if you need to rebuild – locks the
   assembly because of the way the T4 engine
   handles AppDomains
     T4 Toolbox has a VolatileAssembly custom directive
     Fixed in VS 2010 SP1 via shadowing
   You can use MSBuild-style references
     $(SolutionDir)
     $(OutDir)
T4 Syntax - Directives
 Include <#@ include #>
   File
   As if file contents were dropped directly into the
   template
 Parameter <#@ parameter #>
   Name
   Type
T4 Syntax – Text Blocks

 Standard block of text with no delimiters – will be
 placed in the output file wholesale
T4 Syntax – Control Blocks

 Statement or Standard Block
   <# #>
   For standard code not contained in a class
T4 Syntax – Control Blocks

 Expression Block
   <#= #>
   For any expression, evaluates and converts to
   string
T4 Syntax – Control Blocks
 Class Block
   <#+ #>
   For placing helper classes (or any other code
   not included in the main transform) inline in
   the template
   Must be the last block in a template
     Unless you’re including a file with a Class Block
     using the Include Directive
     This is noted because it should be common…
T4 Syntax – Utility Methods
 Write and WriteLine
   Essentially the same as an Expression block
   Allows for text output inside Standard blocks
   May be preferable over Expression blocks for
   readability, if a Standard block is long or
   contains nesting
   Formatting overloads that take string params
   at the end
T4 Syntax – Utility Methods
 Indent Methods and Properties
   CurrentIndent property returns the current
   indent level
   PushIndent indents
   PopIndent moves back one indention
   ClearIndent clears all indents


 Error and Warning Methods
   To write to the VS Error list
   Error(“some expression”)
T4 Syntax – Utility Methods
 Host Property
   If hostspecific is set to “true” in the template
   directive
   Provides some helpful methods
      ResolvePath
   Hooks into the VS API, if VS is the host
      Cast this.Host as an IServiceProvider
      Then GetService of the DTE type
T4 Syntax – Utility Methods
  Host Property Example to access VS API:
<#@ template hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#
IServiceProvider serviceProvider =
(IServiceProvider)this.Host;
DTE dte = serviceProvider.GetService(typeof(DTE))
as DTE;
#>

Number of projects in this solution:
<#= dte.Solution.Projects.Count #>
T4 Syntax – Escape Sequences
 Use the  for escaping any special
 characters

      <# ... #>
T4 Tooling
Use an editor!
 Good “freemium” editors out there in the Visual
 Studio Gallery
 Tangible T4 Editor
    No need to install the Tangible architecture tools
    Latest version has a fix for use with ReSharper
  DevArt T4 Editor
  Clarius Visual T4
T4 Tooling
 Tangible T4 Editor Extras – Template Gallery
   Many excellent examples
   Many snippets that would typically be used for
   Includes
      Multi-file output
      VS automation
   Many out-of-the-box solutions
      HTML image gallery
T4 Tooling


 Still no editor support – syntax
 highlighting/Intellisense – in VS 11
 Will this change? No indications…
What is T4?
 T4 Basics and T4 Tooling

Using T4 Across the Life of an Application
Code Generation Issues are Universal
  UI Designers in VS
  You’ve seen this a lot:
//---------------
// <auto-generated>
//     This code was generated by a tool.
//     Changes to this file will be lost
if the code is regenerated.
// </auto-generated>
//---------------
Code Generation Issues are Universal
 Extending the code
   Inheritance
   Partial classes!!!
   Composition
Resources
 Oleg Sych’s Blog: http://www.olegsych.com/
 T4 Team/Gareth Jones
   Old: http://blogs.msdn.com/b/garethj/
   New: http://blogs.msdn.com/b/t4/
 Kathleen Dollard:
 http://msmvps.com/blogs/kathleen/
 MSDN: http://msdn.microsoft.com/en-
 us/library/bb126445.aspx
Resources
 Tangible’s tutorials: http://t4-editor.tangible-
 engineering.com/How-Do-I-With-T4-Editor-Text-
 Templates.htm
 Wikipedia code generation tool comparison:
 http://en.wikipedia.org/wiki/Comparison_of_code
 _generation_tools

Más contenido relacionado

Was ist angesagt?

BCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IBCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IVaibhavj1234
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPeter Hendriks
 
Top Ten Reasons to Upgrade from Delphi 7
Top Ten Reasons to Upgrade from Delphi 7Top Ten Reasons to Upgrade from Delphi 7
Top Ten Reasons to Upgrade from Delphi 7Michael Findling
 
Entity Framework NYC Firestarter
Entity Framework NYC FirestarterEntity Framework NYC Firestarter
Entity Framework NYC FirestarterJulie Lerman
 
Migrating To Visual Studio 2008 & .Net Framework 3.5
Migrating To Visual Studio 2008 & .Net Framework 3.5Migrating To Visual Studio 2008 & .Net Framework 3.5
Migrating To Visual Studio 2008 & .Net Framework 3.5Jeff Blankenburg
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into JavaTom Johnson
 
Net serialization
Net serializationNet serialization
Net serializationGreg Sohl
 
UML Case Tools
UML Case ToolsUML Case Tools
UML Case ToolsAshesh R
 
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,..."Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...Yandex
 
Eclipse EDT - EGL Inner Workings - June 2011
Eclipse EDT - EGL Inner Workings - June 2011Eclipse EDT - EGL Inner Workings - June 2011
Eclipse EDT - EGL Inner Workings - June 2011Will Smythe
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lineslokeshG38
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialRemedy IT
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming CodeIntro C# Book
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet IntroductionWei Sun
 

Was ist angesagt? (20)

BCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-IBCA IPU VB.NET UNIT-I
BCA IPU VB.NET UNIT-I
 
Zend Framework Workshop
Zend Framework WorkshopZend Framework Workshop
Zend Framework Workshop
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Top Ten Reasons to Upgrade from Delphi 7
Top Ten Reasons to Upgrade from Delphi 7Top Ten Reasons to Upgrade from Delphi 7
Top Ten Reasons to Upgrade from Delphi 7
 
Entity Framework NYC Firestarter
Entity Framework NYC FirestarterEntity Framework NYC Firestarter
Entity Framework NYC Firestarter
 
Migrating To Visual Studio 2008 & .Net Framework 3.5
Migrating To Visual Studio 2008 & .Net Framework 3.5Migrating To Visual Studio 2008 & .Net Framework 3.5
Migrating To Visual Studio 2008 & .Net Framework 3.5
 
API workshop: Deep dive into Java
API workshop: Deep dive into JavaAPI workshop: Deep dive into Java
API workshop: Deep dive into Java
 
Net serialization
Net serializationNet serialization
Net serialization
 
UML Case Tools
UML Case ToolsUML Case Tools
UML Case Tools
 
Dotnet basics
Dotnet basicsDotnet basics
Dotnet basics
 
C#.NET
C#.NETC#.NET
C#.NET
 
Java vs .Net
Java vs .NetJava vs .Net
Java vs .Net
 
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,..."Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...
"Architecting and testing large iOS apps: lessons from Facebook". Adam Ernst,...
 
Eclipse EDT - EGL Inner Workings - June 2011
Eclipse EDT - EGL Inner Workings - June 2011Eclipse EDT - EGL Inner Workings - June 2011
Eclipse EDT - EGL Inner Workings - June 2011
 
Android coding guide lines
Android coding guide linesAndroid coding guide lines
Android coding guide lines
 
CORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorialCORBA Programming with TAOX11/C++11 tutorial
CORBA Programming with TAOX11/C++11 tutorial
 
21. Java High Quality Programming Code
21. Java High Quality Programming Code21. Java High Quality Programming Code
21. Java High Quality Programming Code
 
VB.net
VB.netVB.net
VB.net
 
DotNet Introduction
DotNet IntroductionDotNet Introduction
DotNet Introduction
 
Tutorial c#
Tutorial c#Tutorial c#
Tutorial c#
 

Ähnlich wie T4 presentation

What's New in Visual Studio 2010
What's New in Visual Studio 2010What's New in Visual Studio 2010
What's New in Visual Studio 2010Adil Mughal
 
Code Generation using T4
Code Generation using T4Code Generation using T4
Code Generation using T4Joubin Najmaie
 
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0Antonio Chagoury
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arpGary Pedretti
 
Chicago Code Camp 2014 TFS Care and Feeding
Chicago Code Camp 2014   TFS Care and FeedingChicago Code Camp 2014   TFS Care and Feeding
Chicago Code Camp 2014 TFS Care and FeedingAngela Dugan
 
A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010Abram John Limpin
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersDave Bost
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010Satish Verma
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep JoshiSpiffy
 
Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Lars Vogel
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Steve Lange
 
MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020Ieva Navickaite
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overviewbwullems
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelukdpe
 
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...ITCamp
 
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTCode Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTdschaefer
 
Domain Specific Development using T4
Domain Specific Development using T4Domain Specific Development using T4
Domain Specific Development using T4Joubin Najmaie
 

Ähnlich wie T4 presentation (20)

What's New in Visual Studio 2010
What's New in Visual Studio 2010What's New in Visual Studio 2010
What's New in Visual Studio 2010
 
VS 2010 codename Rosario
VS 2010 codename RosarioVS 2010 codename Rosario
VS 2010 codename Rosario
 
Code Generation using T4
Code Generation using T4Code Generation using T4
Code Generation using T4
 
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
A Sneak Peek At Visual Studio 2010 And .Net Framework 4.0
 
T4 / Code Generation
T4 / Code GenerationT4 / Code Generation
T4 / Code Generation
 
Onion Architecture with S#arp
Onion Architecture with S#arpOnion Architecture with S#arp
Onion Architecture with S#arp
 
Chicago Code Camp 2014 TFS Care and Feeding
Chicago Code Camp 2014   TFS Care and FeedingChicago Code Camp 2014   TFS Care and Feeding
Chicago Code Camp 2014 TFS Care and Feeding
 
A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010A Lap Around Visual Studio 2010
A Lap Around Visual Studio 2010
 
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee ApplicatiesFinal Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
Final Jspring2009 Mda Slimmer Ontwikkelen Van Java Ee Applicaties
 
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for DevelopersMSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
MSDN Presents: Visual Studio 2010, .NET 4, SharePoint 2010 for Developers
 
Visual Studio .NET2010
Visual Studio .NET2010Visual Studio .NET2010
Visual Studio .NET2010
 
.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi.NET 4 Demystified - Sandeep Joshi
.NET 4 Demystified - Sandeep Joshi
 
Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010Eclipse 40 - Eclipse Summit Europe 2010
Eclipse 40 - Eclipse Summit Europe 2010
 
Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)Whats New In 2010 (Msdn & Visual Studio)
Whats New In 2010 (Msdn & Visual Studio)
 
MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020MuleSoft Manchester Meetup #3 slides 31st March 2020
MuleSoft Manchester Meetup #3 slides 31st March 2020
 
Visual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 OverviewVisual Studio 2010 and .NET 4.0 Overview
Visual Studio 2010 and .NET 4.0 Overview
 
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnelEntity Framework 4 In Microsoft Visual Studio 2010 - ericnel
Entity Framework 4 In Microsoft Visual Studio 2010 - ericnel
 
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...
The Roslyn Compiler: Look at Your Code from a Different Perspective (Raffaele...
 
Code Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDTCode Analysis and Refactoring with CDT
Code Analysis and Refactoring with CDT
 
Domain Specific Development using T4
Domain Specific Development using T4Domain Specific Development using T4
Domain Specific Development using T4
 

Mehr von Gary Pedretti

Territories, Not Hierarchies
Territories, Not HierarchiesTerritories, Not Hierarchies
Territories, Not HierarchiesGary Pedretti
 
Agile Architecture: Ideals, History, and a New Hope
Agile Architecture: Ideals, History, and a New HopeAgile Architecture: Ideals, History, and a New Hope
Agile Architecture: Ideals, History, and a New HopeGary Pedretti
 
King Tut Architecture
King Tut ArchitectureKing Tut Architecture
King Tut ArchitectureGary Pedretti
 
Agile Architecture and Modeling - Where are we Today
Agile Architecture and Modeling - Where are we TodayAgile Architecture and Modeling - Where are we Today
Agile Architecture and Modeling - Where are we TodayGary Pedretti
 
This IS Agile Development
This IS Agile DevelopmentThis IS Agile Development
This IS Agile DevelopmentGary Pedretti
 
Holistic Product Development
Holistic Product DevelopmentHolistic Product Development
Holistic Product DevelopmentGary Pedretti
 
TFS 2012 + VS 2012 = Agile Goodness???
TFS 2012 + VS 2012 = Agile Goodness???TFS 2012 + VS 2012 = Agile Goodness???
TFS 2012 + VS 2012 = Agile Goodness???Gary Pedretti
 
Agile Modeling using the Architecture Tools in VS 2010
Agile Modeling  using the Architecture Tools in VS 2010Agile Modeling  using the Architecture Tools in VS 2010
Agile Modeling using the Architecture Tools in VS 2010Gary Pedretti
 

Mehr von Gary Pedretti (8)

Territories, Not Hierarchies
Territories, Not HierarchiesTerritories, Not Hierarchies
Territories, Not Hierarchies
 
Agile Architecture: Ideals, History, and a New Hope
Agile Architecture: Ideals, History, and a New HopeAgile Architecture: Ideals, History, and a New Hope
Agile Architecture: Ideals, History, and a New Hope
 
King Tut Architecture
King Tut ArchitectureKing Tut Architecture
King Tut Architecture
 
Agile Architecture and Modeling - Where are we Today
Agile Architecture and Modeling - Where are we TodayAgile Architecture and Modeling - Where are we Today
Agile Architecture and Modeling - Where are we Today
 
This IS Agile Development
This IS Agile DevelopmentThis IS Agile Development
This IS Agile Development
 
Holistic Product Development
Holistic Product DevelopmentHolistic Product Development
Holistic Product Development
 
TFS 2012 + VS 2012 = Agile Goodness???
TFS 2012 + VS 2012 = Agile Goodness???TFS 2012 + VS 2012 = Agile Goodness???
TFS 2012 + VS 2012 = Agile Goodness???
 
Agile Modeling using the Architecture Tools in VS 2010
Agile Modeling  using the Architecture Tools in VS 2010Agile Modeling  using the Architecture Tools in VS 2010
Agile Modeling using the Architecture Tools in VS 2010
 

Último

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightSafe Software
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applicationsnooralam814309
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Libraryshyamraj55
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.IPLOOK Networks
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsDianaGray10
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfInfopole1
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosErol GIRAUDY
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptxHansamali Gamage
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updateadam112203
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud DataEric D. Schabell
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1DianaGray10
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInThousandEyes
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4DianaGray10
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0DanBrown980551
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveIES VE
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTxtailishbaloch
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch TuesdayIvanti
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIVijayananda Mohire
 

Último (20)

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie WorldTrustArc Webinar - How to Live in a Post Third-Party Cookie World
TrustArc Webinar - How to Live in a Post Third-Party Cookie World
 
Graphene Quantum Dots-Based Composites for Biomedical Applications
Graphene Quantum Dots-Based Composites for  Biomedical ApplicationsGraphene Quantum Dots-Based Composites for  Biomedical Applications
Graphene Quantum Dots-Based Composites for Biomedical Applications
 
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through TokenizationStobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
Stobox 4: Revolutionizing Investment in Real-World Assets Through Tokenization
 
How to release an Open Source Dataweave Library
How to release an Open Source Dataweave LibraryHow to release an Open Source Dataweave Library
How to release an Open Source Dataweave Library
 
Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.Introduction - IPLOOK NETWORKS CO., LTD.
Introduction - IPLOOK NETWORKS CO., LTD.
 
Automation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projectsAutomation Ops Series: Session 2 - Governance for UiPath projects
Automation Ops Series: Session 2 - Governance for UiPath projects
 
Extra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdfExtra-120324-Visite-Entreprise-icare.pdf
Extra-120324-Visite-Entreprise-icare.pdf
 
Scenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenariosScenario Library et REX Discover industry- and role- based scenarios
Scenario Library et REX Discover industry- and role- based scenarios
 
.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx.NET 8 ChatBot with Azure OpenAI Services.pptx
.NET 8 ChatBot with Azure OpenAI Services.pptx
 
Patch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 updatePatch notes explaining DISARM Version 1.4 update
Patch notes explaining DISARM Version 1.4 update
 
3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data3 Pitfalls Everyone Should Avoid with Cloud Data
3 Pitfalls Everyone Should Avoid with Cloud Data
 
UiPath Studio Web workshop series - Day 1
UiPath Studio Web workshop series  - Day 1UiPath Studio Web workshop series  - Day 1
UiPath Studio Web workshop series - Day 1
 
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedInOutage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
Outage Analysis: March 5th/6th 2024 Meta, Comcast, and LinkedIn
 
UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4UiPath Studio Web workshop series - Day 4
UiPath Studio Web workshop series - Day 4
 
LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0LF Energy Webinar - Unveiling OpenEEMeter 4.0
LF Energy Webinar - Unveiling OpenEEMeter 4.0
 
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES LiveKeep Your Finger on the Pulse of Your Building's Performance with IES Live
Keep Your Finger on the Pulse of Your Building's Performance with IES Live
 
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENTSIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
SIM INFORMATION SYSTEM: REVOLUTIONIZING DATA MANAGEMENT
 
March Patch Tuesday
March Patch TuesdayMarch Patch Tuesday
March Patch Tuesday
 
My key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAIMy key hands-on projects in Quantum, and QAI
My key hands-on projects in Quantum, and QAI
 

T4 presentation

  • 1. Using Microsoft’s T4 Across the Life of an Application Gary Pedretti Gary.Pedretti@Centare.com Logo, Design, and Company Information:© 2011 Centare Group, Ltd. Slide Show and Notes Content: Creative Commons License, Gary Pedretti Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. About Centare Consulting Services Organization Primary focus on Agile, Mobile and Cloud Individual and team based development .NET & Java technology stacks Microsoft Gold Partner in ALM Training, coaching, mentoring & team building Full Scrum.org course offering Best practices training Technical and business leadership strategies
  • 3. Gary Pedretti Solutions Manager, Agile Practice Over 12 years in the software industry – Database Administrator, Developer, Business Analyst, Application Architect Scrum: Team member, Scrum Master, Coach, Certified Scrum Trainer for Scrum.org MCPD 4.0 Web, MCTS 4.0 WCF/Web/Data Access, MCDBA MSSQL 2000, PSM, PSD .NET, PSD Java, CSM, MCPD 3.5 ASP.NET, MCTS 3.5 WCF/ASP.NET/ADO.NET, MCTS SharePoint 2003 Infrastructure, MCPD 2.0 Enterprise, MCTS 2.0 Distributed/Web/Windows, MCSD 1.1, MCAD 1.1, MOUS
  • 4. Professional Scrum at Scrum.org Professional Professional Professional Scrum Scrum Master Scrum Product Owner Developer .NET or Java Architects Business Analysts Product Owners DB Specialists Scrum Masters Executives Designers Developers Testers Professional Scrum Foundations Everyone
  • 5. What is T4? T4 Basics and T4 Tooling Using T4 Across the Life of an Application
  • 6. What is T4? Text Template Transformation Toolkit A way to Template desired output Provide input to the template Process the template together with the input to produce text output
  • 7. Text Transformation XSLT – XML input, ? output (often XHTML) Razor (and any number of MVC view engines like NVelocity, etc.) – ? input (often a Model object), (X)HTML output T4 – ? input, ? output Anything goes Designed for generic cases
  • 8. Why? Automate repetitive, boilerplate code Data Access code Front-end scaffolding Produce templated text output to be used by applications Form letters Transformations between different text formats XML to C#
  • 9. T4 Pre-History CodeSmith was/is the primary mover in the .NET space Around for a long time, very mature Provides an excellent set of ready-to-use templates Better template editing and debugging experience Very code-centric (not geared around general text or transformations) $$ licensing, not free
  • 10. T4 Pre-History Many competitors still exist, free and paid XY Studio (web-based) Atom Weaver (MDD-based) Code Generator 360 (ASP.NET DAL-centric) Iron Speed Designer (RAD front-to-back)
  • 11. T4 History Increasing importance and support as we’ve moved from Visual Studio 2005 to Visual Studio 2010 Including out-of-band frameworks
  • 12. T4 History A second-class citizen in Visual Studio 2005 Available through the DSL tools download or through the Guidance Automation Toolkit (GAT – primarily used for software factories)
  • 13. T4 History More of a first-class citizen in VS 2008 Built-in, but not available through File -> New No highlighting or Intellisense A lot of “dogfooding” started, especially with SP 1 – EF, MVC
  • 14. T4 History Almost a first-class citizen in VS 2010 Still no highlighting or Intellisense Dogfooding all over the place – EF (all code generation items), MVC 2, Architecture Tools)
  • 15. Microsoft Dogfooding ASP.NET MVC ADO.NET Entity Framework ASP.NET Dynamic Data Lightswitch (cannot currently get at the templates used, though) VS 2010 Architecture Tool Modeling Feature Pack (forward-engineering)
  • 16. Microsoft Dogfooding – ASP.NET MVC Add Controller and Add View Templates found at [Visual Studio Install Directory]Common7IDEItemTemplates[CSharp | VisualBasic]WebMVC 2CodeTemplates
  • 18. Microsoft Dogfooding – Entity Framework Default, EF-aware Entities Add the EntityObject Generator as a code generation item to see what the default template does behind the scenes POCO and Self-Tracking Entities Implemented through templates Add code generation item to see the templates in your project
  • 19. Microsoft Dogfooding – Entity Framework
  • 20. Microsoft Dogfooding – Architecture Tools Modeling Feature Pack (built in to VS 2010 Feature Pack 2) allows for forward- generation of code from diagrams Templates found at [Visual Studio Install Directory]Common7IDEExtensionsMicrosoftVis ualization and Modeling Feature Pack2.0TemplatesText
  • 21. Microsoft Dogfooding – Architecture Tools
  • 23. What is T4? T4 Basics and T4 Tooling Using T4 Across the Life of an Application
  • 25. Standard Templates Design-time templates Meant to be run within the context of Visual Studio
  • 26. Precompiled Templates Runtime templates For text to be used by an application Form letters For CodeDOM-like activities – dynamic compilation of code Note T4 would be language-specific where raw CodeDOM would not Also makes for easily composable and reusable blocks Just call the TransformText method, it returns a string
  • 27. T4 Syntax - Directives Template <#@ template #> Language Debug Inherits Hostspecific Output <#@ output #> Extension Import <#@ import #> Namespace Resolves to “using” in C# generation
  • 28. T4 Syntax - Directives Assembly <#@ assembly #> Name Equivalent of Add Reference… Careful if you need to rebuild – locks the assembly because of the way the T4 engine handles AppDomains T4 Toolbox has a VolatileAssembly custom directive Fixed in VS 2010 SP1 via shadowing You can use MSBuild-style references $(SolutionDir) $(OutDir)
  • 29. T4 Syntax - Directives Include <#@ include #> File As if file contents were dropped directly into the template Parameter <#@ parameter #> Name Type
  • 30. T4 Syntax – Text Blocks Standard block of text with no delimiters – will be placed in the output file wholesale
  • 31. T4 Syntax – Control Blocks Statement or Standard Block <# #> For standard code not contained in a class
  • 32. T4 Syntax – Control Blocks Expression Block <#= #> For any expression, evaluates and converts to string
  • 33. T4 Syntax – Control Blocks Class Block <#+ #> For placing helper classes (or any other code not included in the main transform) inline in the template Must be the last block in a template Unless you’re including a file with a Class Block using the Include Directive This is noted because it should be common…
  • 34. T4 Syntax – Utility Methods Write and WriteLine Essentially the same as an Expression block Allows for text output inside Standard blocks May be preferable over Expression blocks for readability, if a Standard block is long or contains nesting Formatting overloads that take string params at the end
  • 35. T4 Syntax – Utility Methods Indent Methods and Properties CurrentIndent property returns the current indent level PushIndent indents PopIndent moves back one indention ClearIndent clears all indents Error and Warning Methods To write to the VS Error list Error(“some expression”)
  • 36. T4 Syntax – Utility Methods Host Property If hostspecific is set to “true” in the template directive Provides some helpful methods ResolvePath Hooks into the VS API, if VS is the host Cast this.Host as an IServiceProvider Then GetService of the DTE type
  • 37. T4 Syntax – Utility Methods Host Property Example to access VS API: <#@ template hostspecific="true" language="C#" #> <#@ output extension=".txt" #> <#@ assembly name="EnvDTE" #> <#@ import namespace="EnvDTE" #> <# IServiceProvider serviceProvider = (IServiceProvider)this.Host; DTE dte = serviceProvider.GetService(typeof(DTE)) as DTE; #> Number of projects in this solution: <#= dte.Solution.Projects.Count #>
  • 38. T4 Syntax – Escape Sequences Use the for escaping any special characters <# ... #>
  • 39. T4 Tooling Use an editor! Good “freemium” editors out there in the Visual Studio Gallery Tangible T4 Editor No need to install the Tangible architecture tools Latest version has a fix for use with ReSharper DevArt T4 Editor Clarius Visual T4
  • 40. T4 Tooling Tangible T4 Editor Extras – Template Gallery Many excellent examples Many snippets that would typically be used for Includes Multi-file output VS automation Many out-of-the-box solutions HTML image gallery
  • 41. T4 Tooling Still no editor support – syntax highlighting/Intellisense – in VS 11 Will this change? No indications…
  • 42. What is T4? T4 Basics and T4 Tooling Using T4 Across the Life of an Application
  • 43. Code Generation Issues are Universal UI Designers in VS You’ve seen this a lot: //--------------- // <auto-generated> // This code was generated by a tool. // Changes to this file will be lost if the code is regenerated. // </auto-generated> //---------------
  • 44. Code Generation Issues are Universal Extending the code Inheritance Partial classes!!! Composition
  • 45. Resources Oleg Sych’s Blog: http://www.olegsych.com/ T4 Team/Gareth Jones Old: http://blogs.msdn.com/b/garethj/ New: http://blogs.msdn.com/b/t4/ Kathleen Dollard: http://msmvps.com/blogs/kathleen/ MSDN: http://msdn.microsoft.com/en- us/library/bb126445.aspx
  • 46. Resources Tangible’s tutorials: http://t4-editor.tangible- engineering.com/How-Do-I-With-T4-Editor-Text- Templates.htm Wikipedia code generation tool comparison: http://en.wikipedia.org/wiki/Comparison_of_code _generation_tools

Hinweis der Redaktion

  1. Also, C:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Common7\\IDE\\Extensions\\Microsoft\\Entity Framework Tools
  2. &lt;#@ template language=&quot;C#&quot; #&gt; &lt;#@ parameter name=&quot;MyParameter&quot; type=&quot;System.String&quot; #&gt; Parameter in expression block: &lt;#= MyParameter #&gt; Parameter in statement block: &lt;# Write(MyParameter) #&gt;Call Context Template:&lt;#@ template language=&quot;C#&quot; hostspecific=&quot;true&quot; #&gt; &lt;#@ output extension=&quot;.txt&quot; #&gt; &lt;#@ import namespace=&quot;System.IO&quot; #&gt; &lt;#@ import namespace=&quot;System.Runtime.Remoting.Messaging&quot; #&gt; &lt;#@ import namespace=&quot;Microsoft.VisualStudio.TextTemplating&quot; #&gt; &lt;# string templateFile = this.Host.ResolvePath(&quot;MyTemplate.tt&quot;); string templateContent = File.ReadAllText(templateFile); CallContext.LogicalSetData(&quot;MyParameter&quot;, &quot;CallContextValue&quot;); Engine engine = new Engine(); string generatedContent = engine.ProcessTemplate(templateContent, this.Host); CallContext.FreeNamedDataSlot(&quot;MyParameter&quot;); this.Write(generatedContent); #&gt;Session Template:&lt;#@ template debug=&quot;true&quot; hostspecific=&quot;true&quot; language=&quot;C#&quot; #&gt; &lt;#@ output extension=&quot;.txt&quot; #&gt; &lt;#@ import namespace=&quot;System.IO&quot; #&gt; &lt;#@ import namespace=&quot;Microsoft.VisualStudio.TextTemplating&quot; #&gt; &lt;# string templateFile = this.Host.ResolvePath(&quot;MyTemplate.tt&quot;); string templateContent = File.ReadAllText(templateFile); TextTemplatingSession session = new TextTemplatingSession(); session[&quot;MyParameter&quot;] = &quot;SessionValue&quot;; varsessionHost = (ITextTemplatingSessionHost) this.Host; sessionHost.Session = session; Engine engine = new Engine(); string generatedContent = engine.ProcessTemplate(templateContent, this.Host); this.Write(generatedContent); #&gt;
  3. Finally, we&apos;ll develop a data-driven application that takes advantage of T4 generation, showing how to handle and extend generated code in a changing codebase and how to establish a workflow to use T4 over the lifecycle of an application.