Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run TextTransform.exe from VS 2015 on PC without Visual Studio installed?

I copied TextTransform.exe from PC with VS 2015 Update 3 installed from location C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\14.0\TextTransform.exe to PC without VS 2015 installed.

TextTransform.exe is called as a part of build scripts.

When I run it I get following error:
Error: Exception has been thrown by the target of an invocation.

I read the article Code Generation in a Build Process.
I tried to copy all dll-s described in section "Configure your machines".
But I didn't found the folder $(ProgramFiles)\MSBuild\Microsoft\VisualStudio\v*.0\TextTemplating on my PC with VS 2015 installed.
I copied files in other two folders described in the article to the folder which contains TextTransform.exe on my PC without VS 2015 installed.

After running TextTransform.exe the error still occurs.

How this error should be fixed? How can I get TextTransform.exe run?

UPDATE

I call TextTransform.exe from MSBuild script. So if there are any approaches which can be implemented in MSBuild which performs text transformation functionality it would be acceptable for me, although requires to update build scripts.
I suppose such solution may exists because there are examples when MSBuild performs transformation without direct call of TextTransform.exe, e.g. article mentioned above.

like image 389
sergtk Avatar asked Jan 10 '17 00:01

sergtk


1 Answers

Took a while to unravel, but I have a working TextTransform.exe! Here are the steps I found necessary (note: only tested with VS2015 and .NET 4.6.1):

First, on the build machine, copy all of the following files into C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0 (or wherever you want the tool to end up):

C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.14.0\v4.0_14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.14.0.dll
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VSSDK\VisualStudioIntegration\Common\Assemblies\v4.0\Microsoft.VisualStudio.TextTemplating.Interfaces.14.0.dll
C:\Program Files (x86)\MsBuild\14.0\Bin\Microsoft.CodeAnalysis.dll
C:\Program Files (x86)\MsBuild\14.0\Bin\Microsoft.CodeAnalysis.CSharp.dll
C:\Program Files (x86)\MsBuild\14.0\Bin\Microsoft.CodeAnalysis.VisualBasic.dll
C:\Program Files (x86)\MsBuild\14.0\Bin\System.Reflection.Metadata.dll

If your T4 templates contain C#/VB code, the Microsoft.VisualStudio.TextTemplating.Interfaces.10.0 and Microsoft.VisualStudio.TextTemplating.Interfaces.11.0 assemblies will be resolved from a dynamically-created app-domain, and will not be found next to TextTransform.exe. They must be registered in the GAC instead. From an Administrator command prompt, execute:

gacutil -i Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll
gacutil -i Microsoft.VisualStudio.TextTemplating.Interfaces.11.0.dll

Note: gacutil is typically found in C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools.

Create a TextTransform.exe.config file next to TextTransform.exe with binding redirects (may or may not be necessary depending on your .NET version):

<?xml version ="1.0"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Collections.Immutable" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
        <bindingRedirect oldVersion="1.1.37.0" newVersion="1.1.36.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

When TextTransform.exe first starts, it checks for a folder at %VS140COMNTOOLS%\..\IDE\PrivateAssemblies and throws an exception if it does not exist. So, either create a %VS140COMNTOOLS% environment variable that points to a path accordingly, or create an empty ..\IDE\PrivateAssemblies relative to the working directory where TextTransform.exe will be called from.

like image 51
Cameron Avatar answered Nov 17 '22 13:11

Cameron