VSCT.exe 无法加载文件或程序集。

3

我正在尝试通过命令行构建 Visual Studio 扩展包,但遇到了问题。

该项目在 Visual Studio 环境中完美构建,包括发布和调试。我只是想让该项目也能通过命令行构建。其他项目(非 Visual Studio 扩展包项目)都可以正常构建。问题出现在 VSSDK 的引入上。

错误信息:

12:33:41.147     2>C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(107,5): error VSSDK1000: Failed to load 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' Assembly. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\VsProjects\MyProject\MyProject.csproj]
                   Done executing task "VSCTCompiler" -- FAILED. (TaskId:24)
12:33:41.147     2>Done building target "VSCTCompile" in project "MyProject.csproj" -- FAILED.: (TargetId:42)
12:33:41.147     2>Target "_CheckForCompileOutputs: (TargetId:43)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "_CleanGetCurrentAndPriorFileWrites" depends on it):

我看到了这些文章,其中第一个对我帮助最大,并让我克服了之前的错误,进入了这个错误:

使用VS2012 Package项目进行MS Build

MS Build命令行...VSSDK

在团队环境中构建VS包

我将VSSDKInstall路径设置为:

C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK

我的系统:Windows 8.1 Pro X64

构建:任何CPU

我意识到根据我所读的,该项目是在32位环境下构建的。

我已经实施了以下措施:

  1. 设置VSSDKInstall环境变量并重新启动
  2. 执行:call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat"
  3. 进行ms build调用

我运行了诊断构建,这里是一个较大的片段:

12:33:41.132     2>Done building target "PrepareRdlFiles" in project "MyProject.csproj".: (TargetId:39)
                   Target "RunRdlCompiler" skipped, due to false condition; ('@(RdlFile)'!='') was evaluated as (''!='').
12:33:41.133     2>Target "CompileRdlFiles: (TargetId:40)" in file "C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\ReportingServices\Microsoft.ReportingServices.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "PrepareResources" depends on it):
12:33:41.133     2>Done building target "CompileRdlFiles" in project "MyProject.csproj".: (TargetId:40)
12:33:41.133     2>Target "GenerateListOfCTO: (TargetId:41)" in file "C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "MergeCtoResource" depends on it):
                   Task "AssignCulture" (TaskId:23)
                     Task Parameter:
                         Files=
                             obj\Debug\MyProject.cto
                                     ResourceName=Menus.ctmenu (TaskId:23)
                     Culture of "" was assigned to file "obj\Debug\MyProject.cto". (TaskId:23)
                   Done executing task "AssignCulture". (TaskId:23)
12:33:41.133     2>Done building target "GenerateListOfCTO" in project "MyProject.csproj".: (TargetId:41)
                   Target "FindSDKInstallation" skipped, due to false condition; ('$(VsSDKInstall)'=='') was evaluated as ('C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK'=='').
12:33:41.133     2>Target "VSCTCompile: (TargetId:42)" in file "C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "MergeCtoResource" depends on it):
                       Using "VSCTCompiler" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Build.Tasks.dll".
                   Task "VSCTCompiler" (TaskId:24)
                     Task Parameter:IntermediateDirectory=obj\Debug\ (TaskId:24)
                     Task Parameter:
                         Definitions=
                             __CTC__
                             _CTC_GUIDS_ (TaskId:24)
                     Task Parameter:NoLogo=True (TaskId:24)
                     Task Parameter:OutputFile=MyProject.cto (TaskId:24)
                     Task Parameter:Source=MyProject.vsct (TaskId:24)
                     Task Parameter:Verbose=False (TaskId:24)
                     Task Parameter:SDKVersion=12.0 (TaskId:24)
12:33:41.147     2>C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(107,5): error VSSDK1000: Failed to load 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' Assembly. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\VsProjects\MyProject\MyProject.csproj]
                   Done executing task "VSCTCompiler" -- FAILED. (TaskId:24)
12:33:41.147     2>Done building target "VSCTCompile" in project "MyProject.csproj" -- FAILED.: (TargetId:42)
12:33:41.147     2>Target "_CheckForCompileOutputs: (TargetId:43)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "_CleanGetCurrentAndPriorFileWrites" depends on it):
12:33:41.148     2>Done building target "_CheckForCompileOutputs" in project "MyProject.csproj".: (TargetId:43)
                   Target "_SGenCheckForOutputs" skipped, due to false condition; ('$(_SGenGenerateSerializationAssembliesConfig)' == 'On' or ('@(WebReferenceUrl)'!='' and '$(_SGenGenerateSerializationAssembliesConfig)' == 'Auto')) was evaluated as ('Off' == 'On' or (''!='' and 'Off' == 'Auto')).
12:33:41.148     2>Target "_CleanGetCurrentAndPriorFileWrites: (TargetId:44)" in file "C:\Program Files (x86)\MSBuild\12.0\bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\VsProjects\MyProject\MyProject.csproj" (target "_CleanRecordFileWrites" depends on it):

这是正常的输出:

1/4/2015 1:10:05 PM: Building project step 11 - Build: Debug (Any CPU)...
Pre-processing...

Building configuration 'Debug|Any CPU'...
Microsoft (R) Build Engine version 12.0.31101.0
[Microsoft .NET Framework, version 4.0.30319.34014]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 1/4/2015 1:10:06 PM.
     1>Project "C:\VsProjects\MyProject.sln" on node 1 (default targets).
     1>ValidateSolutionConfiguration:
         Building solution configuration "Debug|Any CPU".
     1>Project "C:\VsProjects\MyProject.sln" (1) is building "C:\VsProjects\MyProject\MyProject.csproj" (2) on node 1 (default targets).
     2>MainResourcesGeneration:
       Skipping target "MainResourcesGeneration" because all output files are up-to-date with respect to the input files.
       CoreResGen:
         No resources are out of date with respect to their source files. Skipping resource generation.
     2>C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(107,5): error VSSDK1000: Failed to load 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' Assembly. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\VsProjects\MyProject\MyProject.csproj]
     2>Done Building Project "C:\VsProjects\MyProject\MyProject.csproj" (default targets) -- FAILED.
     1>Done Building Project "C:\VsProjects\MyProject.sln" (default targets) -- FAILED.

Build FAILED.

       "C:\VsProjects\MyProject.sln" (default target) (1) ->
       "C:\VsProjects\MyProject\MyProject.csproj" (default target) (2) ->
       (VSCTCompile target) -> 
         C:\Program Files (x86)\MSBuild\Microsoft VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(107,5): error VSSDK1000: Failed to load 'C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' Assembly. Could not load file or assembly 'file:///C:\Program Files (x86)\Microsoft Visual Studio 12.0\VSSDK\VisualStudioIntegration\Tools\bin\VSCT.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format. [C:\VsProjects\MyProject\MyProject.csproj]

更新:

  1. 问题可能出在我设置的VSSDKInstall环境变量上,因为我尝试在VS内部构建项目时失败了,无论是调试还是发布。我不得不删除环境变量并重新启动计算机。

更新:2015年1月29日

完整路径如下:

C:\Program Files (x86)\MSBuild\12.0\bin\amd64\msbuild.exe

我使用一个构建工具,它调用一个脚本。
以下是来自诊断msbuild的摘录。我删除了无关的部分。
Building configuration 'Debug|Any CPU'...
Microsoft (R) Build Engine version 12.0.31101.0
[Microsoft .NET Framework, version 4.0.30319.18444]
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files (x86)\MSBuild\12.0\bin\amd64\msbuild.exe /maxcpucount:1 /p:Platform=Any CPU /v:diagnostic <path to project>\myproject.sln
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
Build started 1/29/2015 8:04:26 AM.
Environment at start of build:
ALLUSERSPROFILE = C:\ProgramData
ANT_HOME = C:\SoftDev\Tools\Java\Ant\apache-ant-1.9.3
APPDATA = C:\Users\sarahmarci.JMR\AppData\Roaming
ArmServerInfo = 02272370
asl.log = Destination=file


Done building target "ResGen" in project "myproject.csproj".: (TargetId:37)
Target "CompileLicxFiles" skipped, due to false condition; ('@(_LicxFile)'!='') was evaluated as (''!='').
Target "PrepareRdlFiles: (TargetId:38)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\ReportingServices\Microsoft.ReportingServices.targets" from project "<path to project>\<my project>\myproject.csproj" (target "CompileRdlFiles" depends on it):
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.resx'=='.rdlc').
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.ico'=='.rdlc').
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.png'=='.rdlc').
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.rtf'=='.rdlc').
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.docx'=='.rdlc').
Task "CreateItem" skipped, due to false condition; ('%(Extension)'=='.rdlc') was evaluated as ('.txt'=='.rdlc').
Done building target "PrepareRdlFiles" in project "myproject.csproj".: (TargetId:38)
Target "RunRdlCompiler" skipped, due to false condition; ('@(RdlFile)'!='') was evaluated as (''!='').
Target "CompileRdlFiles: (TargetId:39)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\ReportingServices\Microsoft.ReportingServices.targets" from project "<path to project>\<my project>\myproject.csproj" (target "PrepareResources" depends on it):
Done building target "CompileRdlFiles" in project "myproject.csproj".: (TargetId:39)
Target "GenerateListOfCTO: (TargetId:40)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.targets" from project "<path to project>\<my project>\myproject.csproj" (target "MergeCtoResource" depends on it):
Task "AssignCulture" (TaskId:22)
  Task Parameter:
      Files=
          obj\Debug\myproject.cto
                  ResourceName=Menus.ctmenu (TaskId:22)
  Culture of "" was assigned to file "obj\Debug\myproject.cto". (TaskId:22)
Done executing task "AssignCulture". (TaskId:22)
Done building target "GenerateListOfCTO" in project "myproject.csproj".: (TargetId:40)
Target "FindSDKInstallation: (TargetId:41)" in file "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets" from project "<path to project>\<my project>\myproject.csproj" (target "VSCTCompile" depends on it):
Using "FindVsSDKInstallation" task from assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Build.Tasks.dll".
Task "FindVsSDKInstallation" (TaskId:23)
  Task Parameter:SDKVersion=12.0 (TaskId:23)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(74,5): error VSSDK1036: Can not find the installation for VS SDK. [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4018: The "FindVsSDKInstallation" task failed unexpectedly. [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4018: System.ArgumentNullException: Value cannot be null. [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4018: Parameter name: path1 [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4018:    at System.IO.Path.Combine(String path1, String path2) [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4028: The "FindVsSDKInstallation" task's outputs could not be retrieved from the "IncludesPath" parameter. Value cannot be null. [<path to project>\<my project>\myproject.csproj]
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\VSSDK\Microsoft.VsSDK.Common.targets(76,7): error MSB4028: Parameter name: path1 [<path to project>\<my project>\myproject.csproj]
Done executing task "FindVsSDKInstallation" -- FAILED. (TaskId:23)

您有什么想法?


我已经编辑了你的标题。请参考“问题的标题应该包含“标签”吗?”,在那里达成共识是“不应该”。 - John Saunders
@JohnSaunders - SDK不在标签中。也许它是由vspackage隐含的,但我仍然认为你应该把它留下来。 - H H
@JohnSaunders 我没有意识到标题中不允许使用标签,所以我会记住这一点。但是谢谢你,VSSDK曾经在标题中出现,但它不是我的标签之一。我在标题中添加了VSSDK,因为没有VSSDK的标签。Henk Holterman也和我说了同样的话。就个人而言,我认为VS Package并不意味着VSSDK。VS Packages需要VSSDK。人们可以辩论VSSDK和Packages是否是相同的,但这超出了本问题的范围。 - Sarah Weinberger
@HenkHolterman:我添加了 [tag:visual-studio-sdk]。 - John Saunders
1个回答

11

我曾经遇到过类似的问题,以下是我的解决方法。

在此之前,有几个事实需要说明:

1)VSCT.exe是一个32位的exe。 这是唯一提供的版本。 您可以通过查找错误消息中列出的exe并运行“dumpbin /headers vsct.exe”来确认它是x86(或32位)二进制文件。

2)64位exe / dll无法加载32位二进制文件。 如果尝试,则会出现您在异常详细信息中看到的“格式不正确”的异常。

3)MSBuild.exe作为64位和32位二进制文件提供。

答案:

如果您使用64位MSBuild.exe编译包含VSCTCompile目标的项目,则会出现此错误。 原因是VSCT.exe是32位exe,而您正在尝试从64位msbuild.exe调用它。

修复方法:

要解决此问题,您应该显式使用32位msbuild.exe或打开32位命令行窗口。 下面是操作步骤:http://www.tipandtrick.net/how-to-open-and-run-32-bit-command-prompt-in-64-bit-x64-windows/

如果您从32位命令行窗口运行msbuild,则构建应该成功。


我相信我正在使用32位版本的构建,详见我的更新。完整路径为“C:\Program Files (x86)\MSBuild\12.0\bin\amd64\msbuild.exe”。 - Sarah Weinberger
1
看一下你的路径中是否有amd64。你正在使用64位二进制文件。微软决定将64位二进制文件放在Program Files(x86)下有点奇怪,但事实就是如此。请使用以下路径:C:\Program Files (x86)\MSBuild\12.0\bin\msbuild.exe。 - user862268

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接