Skip to content

Commit c2748c5

Browse files
authored
Merge pull request #1799 from Christopher-St/T4Edits
T4 Code Snippets Exception Fix
2 parents 6bd1f09 + 5857bd7 commit c2748c5

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

docs/modeling/design-time-code-generation-by-using-t4-text-templates.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Design-time T4 text templates let you generate program code and other files in y
147147

148148
```csharp
149149

150-
<#@ template debug="false" hostspecific="false" language="C#" #>
150+
<#@ template debug="false" hostspecific="false" language="C#" #>
151151
<#@ output extension=".cs" #>
152152
<# var properties = new string [] {"P1", "P2", "P3"}; #>
153153
// This is generated code:
@@ -219,7 +219,7 @@ Design-time T4 text templates let you generate program code and other files in y
219219

220220
```csharp
221221

222-
<# var properties = File.ReadLines("C:\\propertyList.txt");#>
222+
<# var properties = File.ReadLines("C:\\propertyList.txt");#>
223223
...
224224
<# foreach (string propertyName in properties) { #>
225225
...
@@ -264,12 +264,13 @@ Design-time T4 text templates let you generate program code and other files in y
264264
The type of `this.Host` (in VB, `Me.Host`) is `Microsoft.VisualStudio.TextTemplating.ITextTemplatingEngineHost`.
265265

266266
### Getting data from Visual Studio
267-
To use services provided in Visual Studio, set the `hostSpecific` attribute and load the `EnvDTE` assembly. You can then use IServiceProvider.GetCOMService() to access DTE and other services. For example:
267+
To use services provided in Visual Studio, set the `hostSpecific` attribute and load the `EnvDTE` assembly. Import `Microsoft.VisualStudio.TextTemplating`, which contains the `GetCOMService()` extension method. You can then use IServiceProvider.GetCOMService() to access DTE and other services. For example:
268268

269-
```scr
269+
```src
270270
<#@ template hostspecific="true" language="C#" #>
271271
<#@ output extension=".txt" #>
272272
<#@ assembly name="EnvDTE" #>
273+
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
273274
<#
274275
IServiceProvider serviceProvider = (IServiceProvider)this.Host;
275276
EnvDTE.DTE dte = (EnvDTE.DTE) serviceProvider.GetCOMService(typeof(EnvDTE.DTE));

docs/modeling/t4-template-directive.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ hostspecific="true"
8282
<#@ assembly name="EnvDTE" #>
8383
<#@ import namespace="EnvDTE" #>
8484
<#@ import namespace="System.IO" #>
85+
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
8586
<# // Get the Visual Studio API as a service:
8687
DTE dte = ((IServiceProvider)this.Host).GetCOMService(typeof(DTE)) as DTE;
8788
#>

0 commit comments

Comments
 (0)