Use MSBuild Properties in T4 Templates
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 开发者_StackOverflow中文版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.
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)
You may use ResolveAssemblyReference
, for example :
Revision: <#=Host.ResolveAssemblyReference("$(Revision)")#>
精彩评论