【问题标题】:doing msbuild from the command line: getting errors for the referenced namespace 'Microsoft.VisualStudio.TestTools'从命令行执行 msbuild:获取引用的命名空间“Microsoft.VisualStudio.TestTools”的错误
【发布时间】:2010-10-02 21:22:50
【问题描述】:

我正在用 msbuild 用这行代码编译一个 .net 3.5 解决方案:

msbuild.exe n:\temp\Thisnight.sln /p:Configuration=Debug /v:diag

它给了我这个错误:

 error CS0234: The type or namespace name 'UnitTesting' does not exist in the namespace 'Microsoft.VisualStudio.TestTools' (are you missing an assembly reference?)

我已经获得了(当然)在 VS2010 本身中构建的最新源代码。

似乎无法弄清楚我在这里缺少什么......

编辑

在命令窗口的上方看到此消息:

  C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.Common.targets : warning MSB3245: Could not resolve this reference.
 Could not locate the assembly "Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutra
l, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

我不认为我必须在我的项目中包含这个 DLL(因为它是一个 MS dll?)

编辑 我现在所看到的:所有项目都是针对 .Net 3.5 框架的,但 testproject(这是给我带来问题的项目)是针对 .Net 4.0 框架的。 奇怪的是:我无法改变它。

这是一个带有 web 的 vs2010 解决方案。 webservice、winforms、dll、设置和测试项目

【问题讨论】:

  • 您能详细说明您的解决方案的内容吗?用当前的信息尝试和重现这个有点困难。
  • 这是一个带有 16 个项目(web、webservice、winforms 和 dll)的 vs2010 解决方案。

标签: msbuild


【解决方案1】:

您是否在 cmd shell 中运行了 vcvars32.bat?

【讨论】:

  • 我也可以从我的巡航控制中安排它吗(因为当我让 msbuild 运行时,我想从我的巡航控制中运行它),或者我现在贪婪:)
  • 它是 vs 发行版的一部分,在 Common7\Tools 文件夹下。
  • 我已经在命令提示符下运行了批处理文件并运行了 msbuild 任务,但它没有用。还有其他建议吗?
  • 顺便说一句:它在开发机器上,所以我安装了 VS2010。
  • 嗯。没有把握。尝试在该机器上的 VS 中打开解决方案,并查看 IDE 是否识别引用选项卡中的引用。你是如何引用这个 DLL 的?您可以尝试删除引用并再次将其重新添加到项目中。 VS运行msbuild来构建项目,所以一定是进程启动的环境有细微差别。另外 - 你确定它是相同类型的 VS2010 安装吗?测试环境在基础版本中不可用,仅在某些版本(如专业版和测试版)上可用
【解决方案2】:

如果您查看 Microsoft.Common.Targets 文件,您会看到:

<!--
    The SearchPaths property is set to find assemblies in the following order:

        (1) Files from current project - indicated by {CandidateAssemblyFiles}
        (2) $(ReferencePath) - the reference path property, which comes from the .USER file.
        (3) The hintpath from the referenced item itself, indicated by {HintPathFromItem}.
        (4) The directory of MSBuild's "target" runtime from GetFrameworkPath.
            The "target" runtime folder is the folder of the runtime that MSBuild is a part of.
        (5) Registered assembly folders, indicated by {Registry:*,*,*}
        (6) Legacy registered assembly folders, indicated by {AssemblyFolders}
        (7) Resolve to the GAC.
        (8) Treat the reference's Include as if it were a real file name.
        (9) Look in the application's output folder (like bin\debug)
    -->

VS 在自己的环境中运行 MSBuild,我也不知道有什么区别,但是您是否尝试通过修改 AssemblyFolders 项在命令行中添加缺少的程序集路径。你在这里有一个tuto:http://www.beefycode.com/post/Resolving-Binary-References-in-MSBuild.aspx

希望这会有所帮助。

【讨论】:

  • 不确定是否可以在命令行中覆盖 AssemblySearchPaths。您是否尝试添加自定义目标,就像教程中显示的那样?或者你可以直接修改 Microsoft.Common.Targets 但我认为这不是一个好的解决方案......
  • 没有让它工作,希望有一天有人会阅读这篇文章并给我一个解决方案。没想到前期会这么难。已经为此工作了 6 个小时以上,而且还不够重要,无法继续。是否将此标记为 BB 所付出努力的答案。
  • 我忘记了这个问题。我目前面临同样的问题,我认为您根本无法在 VS 之外运行 VS 单元测试(即使用 MsBuild)。缺少的 dll 在 VS10\Common7\IDE 目录中,即使我很好地引用了它,我也无法让它在 VS 之外工作。也许它使用了 MsTest 或者需要一些 VS 的东西才能工作。我将问题标记为收藏,看看是否有人有更好的答案。
【解决方案3】:

尝试运行:

msbuild /版本

确保它是 3.5 版本,而不是旧版本。

确保 MS dll 在这里,或类似的地方:

C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-14
    • 1970-01-01
    • 2020-05-09
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多