5

I am using MSBuild to generate some files using T4 and I was wondering if it would be possible to reference and use MSBuild properties within the T4 template?

I want to do something like this snippet:

Revision: <#=$(Revision)#>

This throws an error:

error CS1056: Compiling transformation: Unexpected character '$'

I'd prefer not to have to wrap the properties in a custom DLL and reference a C# class as a T4 property.

Any help would be much appreciated.

T4Dude
  • 51
  • 2

2 Answers2

0

You may use ResolveAssemblyReference, for example :

Revision: <#=Host.ResolveAssemblyReference("$(Revision)")#>
McX
  • 1,166
  • 1
  • 11
  • 15
0

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

Add something like this into your template:

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

And into MsBuild script:

    TextTransform -a !!RevisionParameter!$(Revision)
Ludwo
  • 5,783
  • 4
  • 29
  • 48