MSBuild故障排除故障

时间:2009-03-30 17:26:17

标签: tfs msbuild

我正在尝试将我的商店从使用VSS转换为TFS。

我们当前的代码库包含大量Visual Studio 2008解决方案,我注意到其中一些似乎导致MSBuild失败,但我无法弄清楚原因。实际的解决方案本身及其拥有的项目构建正确,但整体构建仍然失败。

ErrorsAndWarnings.txt和Release.txt文件显示没有错误,只是警告(我们需要清理的代码中的各种小东西)

BuildLog.txt文件当然是巨大的,并且有大量难以理解的文本。尽管如此,我可以判断,当它到达其中一个SLN文件时会出现问题,MSBuild只会导致崩溃并死亡。

Task "MSBuild"
  Global Properties:
    Configuration=Release
    Platform=Any CPU
    OutDir=C:\TFS\REPOSITORY\Full\Binaries\Release\
    PublishDir=C:\TFS\REPOSITORY\Full\Binaries\Release\
    SkipInvalidConfigurations=true
    RunCodeAnalysis=false
    VCBuildOverride=C:\TFS\REPOSITORY\Full\Sources\Code\Solution\Solution.sln.Release.vsprops
    VCBuildAdditionalLibPaths=
    VCBuildAdditionalOptions=
    VCBuildToolPath=
    VCBuildUseEnvironment=
    TeamBuildConstants=_TEAM_BUILD_
    TargetsNotLogged=GetTargetPath;GetNativeManifest;GetCopyToOutputDirectoryItems

C:\Program Files\MSBuild\Microsoft\VisualStudio\TeamBuild\Microsoft.TeamFoundation.Build.targets(1008,5): 
error MSB4018: The "MSBuild" task failed unexpectedly.
error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object.
error MSB4018:    at Microsoft.Build.BuildEngine.SolutionWrapperProject.AssignDependencyLevel(ProjectInSolution project, SolutionParser solution, Dictionary`2 projectsByDependencyLevel)
error MSB4018:    at Microsoft.Build.BuildEngine.SolutionWrapperProject.AssignDependencyLevel(ProjectInSolution project, SolutionParser solution, Dictionary`2 projectsByDependencyLevel)
error MSB4018:    at Microsoft.Build.BuildEngine.SolutionWrapperProject.AssignDependencyLevels(SolutionParser solution, Dictionary`2 projectsByDependencyLevel)
error MSB4018:    at Microsoft.Build.BuildEngine.SolutionWrapperProject.CreateSolutionProject(SolutionParser solution, Project msbuildProject, BuildEventContext projectBuildEventContext, String wrapperProjectToolsVersion, Engine parentEngine, String solutionProjectCache)
error MSB4018:    at Microsoft.Build.BuildEngine.SolutionWrapperProject.Generate(SolutionParser solution, Project msbuildProject, String toolsVersionOverride, BuildEventContext projectBuildEventContext)
error MSB4018:    at Microsoft.Build.BuildEngine.Project.Load(String projectFileName, BuildEventContext buildEventContext, ProjectLoadSettings projectLoadSettings)
error MSB4018:    at Microsoft.Build.BuildEngine.Engine.GetMatchingProject(Project existingProject, String projectFullPath, BuildPropertyGroup globalPropertiesToUse, String toolsVersion, String[] targetNames, BuildEventContext buildEventContext, Boolean toolsVersionPeekedFromProjectFile)
error MSB4018:    at Microsoft.Build.BuildEngine.Engine.BuildProjectFileInternal(BuildRequest buildRequest)
error MSB4018:    at Microsoft.Build.BuildEngine.Engine.EngineBuildLoop(BuildRequest terminatingBuildRequest)
error MSB4018:    at Microsoft.Build.BuildEngine.TaskExecutionModule.BuildProjectFile(Int32 handleId, String[] projectFileNames, String[] targetNames, IDictionary[] globalPropertiesPerProject, IDictionary[] targetOutputsPerProject, EngineLoggingServices loggingServices, String[] toolsVersions, Boolean useResultsCache, Boolean unloadProjectsOnCompletion, BuildEventContext taskContext)
error MSB4018:    at Microsoft.Build.BuildEngine.EngineProxy.BuildProjectFilesInParallel(String[] projectFileNames, String[] targetNames, IDictionary[] globalProperties, IDictionary[] targetOutputsPerProject, String[] toolsVersions, Boolean useResultsCache, Boolean unloadProjectsOnCompletion)
error MSB4018:    at Microsoft.Build.Tasks.MSBuild.ExecuteTargets(ITaskItem[] projects, Hashtable propertiesTable, ArrayList targetLists, Boolean stopOnFirstFailure, Boolean rebaseOutputs, IBuildEngine2 buildEngine, TaskLoggingHelper log, ArrayList targetOutputs, Boolean useResultsCache, Boolean unloadProjectsOnCompletion, String toolsVersion)
error MSB4018:    at Microsoft.Build.Tasks.MSBuild.BuildProjectsInParallel(Hashtable propertiesTable, ArrayList targetLists, Boolean success, Boolean[] skipProjects)
error MSB4018:    at Microsoft.Build.Tasks.MSBuild.Execute()
error MSB4018:    at Microsoft.Build.BuildEngine.TaskEngine.ExecuteInstantiatedTask(EngineProxy engineProxy, ItemBucket bucket, TaskExecutionMode howToExecuteTask, ITask task, Boolean& taskResult)
Done building target "CoreCompileSolution" in project "TFSBuild.proj" -- FAILED.
Done Building Project "C:\TFS\REPOSITORY\Full\BuildType\TFSBuild.proj" (CompileSolution target(s)) -- FAILED.
Done executing task "MSBuild" -- FAILED.
Done building target "CoreCompileConfiguration" in project "TFSBuild.proj" -- FAILED.
Done Building Project "C:\TFS\REPOSITORY\Full\BuildType\TFSBuild.proj" (CompileConfiguration target(s)) -- FAILED.
Done executing task "MSBuild" -- FAILED.
Done building target "CoreCompile" in project "TFSBuild.proj" -- FAILED.
Done Building Project "C:\TFS\REPOSITORY\Full\BuildType\TFSBuild.proj" (CoreCompile target(s)) -- FAILED.
Done executing task "MSBuild" -- FAILED.
Done building target "CallCompile" in project "TFSBuild.proj" -- FAILED.

我知道在Stack Overflow中粘贴令人难以置信的冗长错误消息是蹩脚的,但从上面得到的核心是 MSBuild崩溃,我无法弄清楚原因。它给出了通常的“对象引用未设置...”错误,如果不是您正在进行故障排除的代码或程序,这几乎是无用的。

我看到它引用了TeamFoundation.Build.targets。我查找该文件,但它并没有真正向我跳出问题所在。 (评论后面的行是上面引用的(1008,5))

<!-- Build using MSBuild task -->
<MSBuild BuildInParallel="$(BuildSolutionsInParallel)"
         Projects="$(Solution)"
         Properties="Configuration=$(Configuration);Platform=$(Platform);$(OutDirOption);$(PublishDirOption);SkipInvalidConfigurations=$(SkipInvalidConfigurations);$(FxCopDirOption);$(ReferencePathOption);$(CodeAnalysisOption);
                         VCBuildOverride=$(VsPropsFile);VCBuildAdditionalLibPaths=$(VCBuildAdditionalLibPaths);VCBuildAdditionalOptions=$(VCBuildAdditionalOptions);VCBuildToolPath=$(VCBuildToolPath);VCBuildUseEnvironment=$(VCBuildUseEnvironment);
                         TeamBuildConstants=$(TeamBuildConstants);TargetsNotLogged=$(TargetsNotLogged);$(CustomPropertiesForBuild);$(CustomProperties)"
         Targets="$(Targets)"
         StopOnFirstFailure="$(StopOnFirstFailure)">
  <Output TaskParameter="TargetOutputs" ItemName="CompilationOutputs" />
</MSBuild>

起初我以为这告诉我,节点中需要替换的项目之一丢失了,但其他没有问题的解决方案有相似/相同的设置。

我注意到MSBuild的调用堆栈中的一些项目与目标有关,问题似乎源于TeamFoundation.Build.targets文件,但我不知道接下来要做什么来解决它。

有没有人遇到过这个?

4 个答案:

答案 0 :(得分:4)

我认为解决方案文件已损坏,VS更容忍。 (如果我没记错的话,这种崩溃可能是由无法匹配的卷曲括号引起的)

如果可行,我会从VS中重新创建解决方案文件。 丹(msbuild团队)

答案 1 :(得分:2)

当你说:

  

实际解决方案本身及其所持有的项目构建正确

你的意思是他们在IDE中正确构建,或者你可以在命令行上访问那些解决方案目录并运行'msbuild foo.proj'或'msbuild bar.sln'?

无论如何,我会尝试的事情是首先缩小有问题的解决方案/项目,告诉TFS不要并行构建,关闭多CPU支持(例如'-maxcpucount:1'),通过修剪进行二进制搜索远离解决方案/项目。一旦你到达有问题的集合,使用'-v:diag'参数构建,以获得有关MSBuild引擎状态的更多细节。

或者,您可以编写一个小型C#应用程序,直接调用MSBuild引擎并通过捕获第一次机会异常并使用Reflector方便地调试该应用程序。看到 MSBuild Engine Class中的示例代码。

答案 2 :(得分:1)

嗯。您将获得NullReferenceException,这意味着该任务中的一个参数在不应该出现时为null。愚蠢的问题,但你有没有设置你想要构建的解决方案的TFSBuild.proj文件? IE浏览器。你投入的东西   - 项目组。

如果有,我建议将消息​​任务添加到失败任务正上方的Teambuild目标文件中,以写出诊断信息,如下所示:

这应该将一些诊断信息发布到您在下一次构建时粘贴的日志上方的构建日志中。

答案 3 :(得分:0)

您可能想尝试一下MSBuild-Sidekicks。他们为MSBuild提供了一个漂亮的小调试器,并提供了14天的试用版:http://www.attrice.info/msbuild/