如何在未安装Visual Studio的PC上从VS 2015运行TextTransform.exe? [英] How to run TextTransform.exe from VS 2015 on PC without Visual Studio installed?

查看:207
本文介绍了如何在未安装Visual Studio的PC上从VS 2015运行TextTransform.exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将TextTransform.exe从安装了VS 2015 Update 3的PC从位置C:\Program Files (x86)\Common Files\Microsoft Shared\TextTemplating\14.0\TextTransform.exe复制到了未安装VS 2015的PC.

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被称为构建脚本的一部分.

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

当我运行它时,出现以下错误:
Error: Exception has been thrown by the target of an invocation.

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

我阅读了文章构建过程中的代码生成. br> 我试图复制配置您的计算机"部分中描述的所有dll-s.
但是我在安装了VS 2015的PC上找不到文件夹$(ProgramFiles)\MSBuild\Microsoft\VisualStudio\v*.0\TextTemplating.
我将本文所述的其他两个文件夹中的文件复制到了未安装VS 2015的PC上包含TextTransform.exe的文件夹中.

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.

运行TextTransform.exe后,仍然会发生错误.

After running TextTransform.exe the error still occurs.

该错误应如何解决? 如何获得TextTransform.exe运行?

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

更新

我从MSBuild脚本调用TextTransform.exe.因此,如果有任何可以在MSBuild中实现的执行文本转换功能的方法,尽管需要更新构建脚本,但对我来说是可以接受的.
我想这样的解决方案可能存在,因为有一些示例在MSBuild执行转换而无需直接调用TextTransform.exe的情况下,例如上面提到的文章.

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.

推荐答案

花点时间进行解说,但是我有一个正在工作的TextTransform.exe!这是我发现必要的步骤(注意:仅在VS2015和.NET 4.6.1上进行过测试):

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):

首先,在构建计算机上,将以下所有文件复制到C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0(或您希望该工具结束的任何位置):

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

如果您的T4模板包含C#/VB代码,则Microsoft.VisualStudio.TextTemplating.Interfaces.10.0Microsoft.VisualStudio.TextTemplating.Interfaces.11.0 程序集将从动态创建的应用程序域中解析,并且不会在TextTransform.exe旁边找到.他们必须在GAC中注册. 在管理员命令提示符下,执行:

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

注意:gacutil通常在C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools中找到.

TextTransform.exe旁边创建具有绑定重定向的TextTransform.exe.config文件(根据您的.NET版本,可能是或不是必需的):

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>

TextTransform.exe首次启动时,它将在%VS140COMNTOOLS%\..\IDE\PrivateAssemblies处检查文件夹,如果不存在则抛出异常. 因此,要么创建一个%VS140COMNTOOLS%环境变量以相应地指向路径,要么相对于该变量创建一个空的..\IDE\PrivateAssemblies. 将在其中调用TextTransform.exe的工作目录.

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.

这篇关于如何在未安装Visual Studio的PC上从VS 2015运行TextTransform.exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆