从生成服务器预处理T4模板时发生FileNotFoundException
我试图按照Microsoft生成过程中的代码生成文档中的说明在我们的构建服务器上重建T4模板。 当我构建时,模板生成失败并出现错误(完整的MSBuild输出在此问题后面):
错误MSB4018:“TransformTemplates”任务意外失败。
错误MSB4018:System.IO.FileNotFoundException:无法加载文件或程序集'Microsoft.VisualStudio.TextTemplating.14.0,版本= 14.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a'或其某个依赖项。 该系统找不到指定的文件。
我创建了一个复制问题的最小项目。 脚本build.cmd只是执行MSBuild。 当我从我的工作站运行build.cmd时,构建成功。 它只在构建服务器上失败。
我试过的东西:
按照代码生成文档的规定,将MSBuild和Visual Studio程序集复制到构建服务器。
将Visual Studio程序集添加到GAC。
将VSSDK140Install
环境变量设置为“C: Program Files(x86) Microsoft Visual Studio 14.0 VSSDK ”(因为这是它在我的工作站上的设置)。
将HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudio14.0!InstallDir
为C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDE
我试图避免安装Visual Studio 2015,因为这是一个非常大的依赖项,需要添加到我们的构建服务器,并且Microsoft文档明确指出这应该是可能的。
将程序集复制到C: Program Files(x86)
我已将以下文件复制到构建服务器,如代码生成文档中所述(这些都位于Program Files(x86)文件夹中,因为它们位于我的计算机上):
已添加到GAC
我看到它没有试图加载Microsoft.VisualStudio.TextTemplating.14.0.dll
,并且由于该程序集位于工作站上的GAC中,所以我猜测可能这是必需的,因此我尝试使用GAC管理器添加Microsoft.VisualStudio.TextTemplating.14.0.dll
给GAC,但错误是一样的。
完整的MSBuild输出
当我运行build.cmd
,我得到以下输出:
D:TTTest>"C:Program Files (x86)MSBuild14.0BinMSBuild.exe" ClassLibrary1.sln /t:Rebuild
Microsoft (R) Build Engine version 14.0.25420.1
Copyright (C) Microsoft Corporation. All rights reserved.
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 10/20/2017 11:05:16 AM.
Project "D:TTTestClassLibrary1.sln" on node 1 (Rebuild target(s)).
ValidateSolutionConfiguration:
Building solution configuration "Debug|Any CPU".
Project "D:TTTestClassLibrary1.sln" (1) is building "D:TTTestClassLibrary1ClassLibrary1.csproj" (2) on node 1 (Rebuild target(s)).
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: The "TransformTemplates" task failed unexpectedly. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.TextTemplating.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: File name: 'Microsoft.VisualStudio.TextTemplating.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Sdk.Host.GenericTextTemplatingHost..ctor(IServiceProvider serviceProvider) [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.GetConfiguredTextTemplatingHost() [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: at Microsoft.VisualStudio.TextTemplating.Build.Tasks.TransformTemplatesBase.Execute() [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: === Pre-bind state information === [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: DisplayName = Microsoft.VisualStudio.TextTemplating.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: (Fully-specified) [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Appbase = file:///C:/Program Files (x86)/MSBuild/14.0/Bin/ [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Initial PrivatePath = NULL [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: Calling assembly : Microsoft.VisualStudio.TextTemplating.Sdk.Host.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: === [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: This bind starts in LoadFrom load context. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load(). [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Using application configuration file: C:Program Files (x86)MSBuild14.0BinMSBuild.exe.Config [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Using host configuration file: [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Using machine configuration file from C:WindowsMicrosoft.NETFrameworkv4.0.30319configmachine.config. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Post-policy reference: Microsoft.VisualStudio.TextTemplating.14.0, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/14.0/Bin/Microsoft.VisualStudio.TextTemplating.14.0.DLL. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/14.0/Bin/Microsoft.VisualStudio.TextTemplating.14.0/Microsoft.VisualStudio.TextTemplating.14.0.DLL. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/14.0/Bin/Microsoft.VisualStudio.TextTemplating.14.0.EXE. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/14.0/Bin/Microsoft.VisualStudio.TextTemplating.14.0/Microsoft.VisualStudio.TextTemplating.14.0.EXE. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/Microsoft/VisualStudio/v14.0/TextTemplating/Microsoft.VisualStudio.TextTemplating.14.0.DLL. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/Microsoft/VisualStudio/v14.0/TextTemplating/Microsoft.VisualStudio.TextTemplating.14.0/Microsoft.VisualStudio.TextTemplating.14.0.DLL. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/Microsoft/VisualStudio/v14.0/TextTemplating/Microsoft.VisualStudio.TextTemplating.14.0.EXE. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: LOG: Attempting download of new URL file:///C:/Program Files (x86)/MSBuild/Microsoft/VisualStudio/v14.0/TextTemplating/Microsoft.VisualStudio.TextTemplating.14.0/Microsoft.VisualStudio.TextTemplating.14.0.EXE. [D:TTTestClassLibrary1ClassLibrary1.csproj]
C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0TextTemplatingMicrosoft.TextTemplating.targets(396,5): error MSB4018: [D:TTTestClassLibrary1ClassLibrary1.csproj]
Done Building Project "D:TTTestClassLibrary1ClassLibrary1.csproj" (Rebuild target(s)) -- FAILED.
Done Building Project "D:TTTestClassLibrary1.sln" (Rebuild target(s)) -- FAILED.
Build FAILED.
当我查看文件Microsoft.TextTemplating.targets
,发现它使用注册表项来查找包含dlls
文件夹:
<PropertyGroup Condition=" $(IncludeDslT4Settings)=='true' ">
<!-- Path to VSCommon7IDE -->
<!-- Check the 32bit location first ; if that is empty, use the 64bit location. -->
<VsIdePath>$(Registry:HKEY_LOCAL_MACHINESoftwareMicrosoftVisualStudio14.0@InstallDir)</VsIdePath>
<VsIdePath Condition=" $(VsIdePath) == ''" >$(Registry:HKEY_LOCAL_MACHINESoftwareWow6432NodeMicrosoftVisualStudio14.0@InstallDir)</VsIdePath>
<!-- Set the default location for the Dsl Designer install. -->
<DslDesignerInstallPath Condition=" $(DslDesignerInstallPath)=='' ">$(VsIdePath)ExtensionsMicrosoftDSL SDKDsl Designer$(VisualStudioVersion)</DslDesignerInstallPath>
<!-- Add the standard DSL templates folder -->
<IncludeFolders>$(IncludeFolders);$(DslDesignerInstallPath)TextTemplates</IncludeFolders>
所以我必须在构建服务器上的Microsoft Visual Studio 2015 SDK和Microsoft Visual Studio 2015可视化和建模SDK到注册表DLL中安装。
但是, 从Visual Studio 2015开始 ,不要从下载中心安装Visual Studio SDK。 它作为Visual Studio安装中的可选功能包含在内 。 所以我们无法安装Visual Studio SDK而无需安装Visual Studio。 有关详细信息,请参阅Visual Studio SDK。
此外,Daniel's有一篇关于如何在不安装Visual Studio SDK的情况下转换T4模板的博客,您可以检查它是否有帮助。
问题似乎是.NET无法找到程序集Microsoft.VisualStudio.TextTemplating.14.0.dll
。
因此,不是在Visual Studio安装它们时将所有内容保存在单独的文件夹中,而是将以下文件:
并将它们全部复制到MSBuild任务目录中:
这样做后,.NET能够找到它需要的程序集并转换模板。
链接地址: http://www.djcxy.com/p/92431.html上一篇: FileNotFoundException when preprocessing T4 templates from build server