pjmolina
pjmolina

Reputation: 316

T4 include Directive broken after installing VS2013 Update 3

After updating to Visual Studio 2013 Update 3, the following code in a T4 template breaks.

<#@ include file="../File1.tt" #>

It worked as expected in all previous versions of VS. With this Update, all the variants:

<#@ include file="../File1.tt" #>
<#@ include file="..\File1.tt" #>
<#@ include file="..\\File1.tt" #>

Fails with the following error:

There was an error loading the include file '..\\File1.tt'. The transformation will not    be run. The following Exception was thrown:
System.ArgumentException: The path is not of a legal form.
  at System.IO.Path.NormalizePath(String path, Boolean fullCheck, Int32 maxPathLength, Boolean expandShortPaths)
  at System.IO.Path.GetFullPathInternal(String path)
  at System.IO.Path.GetFullPath(String path)
  at Microsoft.VisualStudio.TextTemplating.Engine.VisitedFiles.Visit(String fileLocation)
  at Microsoft.VisualStudio.TextTemplating.Engine.ProcessIncludeDirective(Directive directive, ITextTemplatingEngineHost host, VisitedFiles includedFiles) in line: 234 in file: C:\...\mytemplate.tt

Any known workaround or fix for this issue?

Upvotes: 4

Views: 664

Answers (1)

pjmolina
pjmolina

Reputation: 316

Root cause found.

When implementing the interface ITextTemplatingEngineHost one of the method to implement is:

public bool LoadIncludeText(
              string requestFileName, out string content, out string location)

In all previous versions before VS2013 Update 3 returning a valid filename in the location parameter as output was not required. In fact, we send string.Empty.

Accordingly to the documentation the value can be empty if the template is not file-system based. See doc reference:

location Type: String
A String that contains the location of the acquired text. If the host searches the registry for the location of include files or if the host searches multiple locations by default, the host can return the final path of the include file in this parameter. The host can set the location to Empty if the file could not be found or if the host is not file-system based.

However with Update 3, something has changed and T4 engine checks and expects the location parameter to be a non-empty file path. String.Empty value result in the original commented exception.

As a temporal workaround: passing a valid file name to the location parameter on method LoadIncludeText when implementing ITextTemplateEngineHost avoids the exception.

Thanks to @rubenjmarrufo in the hunt for the bug.

Update: Confirmed bug by Microsoft. It will be fixed on Update 4. Commented workaround is valid.

Upvotes: 4

Related Questions