Use MSBuild Properties in T4 Templates

I use MSBuild to create some files using T4, and I was wondering if it is possible to reference and use the MSBuild properties in the T4 template?

I want to do something like this snippet:

Revision: <#=$(Revision)#>

This causes an error:

error CS1056: Compiling transformation: Unexpected character '$'

I would prefer not to transfer the properties to the user DLL and refer to the C # class as a T4 property.

Any help would be greatly appreciated.

+4
source share
1 answer

It should be possible to pass the value of $ (Revision) using the command line TextTransform -a option .

Add the following to your template:

  [<#= this.Host.ResolveParameterValue("", "", "RevisionParameter") #>] 

And in the MsBuild script:

  TextTransform -a !!RevisionParameter!$(Revision) 
0
source

All Articles