接收CS0234:使用MSBuild.exe在名称空间“ Microsoft”中不存在类型或名称空间名称“ VisualStudio”

时间:2019-07-26 15:19:33

标签: jenkins-groovy msbuild-4.0

我正在尝试使用以下命令构建dotnet解决方案,但出现错误

CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' using MSBuild.exe

命令:

bat "\"${tool 'MSBuild'}\" Test.sln  /t:Rebuild /p:Configuration=Release /p:VisualStudioVersion=14.0 /p:NoWarn=7035 /p:Platform=\"Any CPU\" "

该代码存在于Bitbucket中,我正在从Jenkins触发构建。该代码正在Windows服务器中运行。

bat "\"${tool 'MSBuild'}\" Test.sln  /t:Rebuild /p:Configuration=Release /p:VisualStudioVersion=14.0 /p:NoWarn=7035 /p:Platform=\"Any CPU\" "

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

error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?) 

error CS0246: The type or namespace name 'TestInitialize' could not be found (are you missing a using directive or an assembly reference?)

error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,发现这是由使用Microsoft.VisualStudio.QualityTools.UnitTestFramework的旧版Visual Studio中创建的单元测试项目引起的。应该将其更改为使用Microsoft.VisualStudio.TestPlatform.TestFramework,这是以后的单元测试项目中使用的默认设置。解决步骤:

  1. 打开单元测试项目引用,并删除对Microsoft.VisualStudio.QualityTools.UnitTestFramework的引用: UnitTests References
  2. 打开项目的“管理NuGet程序包”,然后添加MSTest.TestFramework程序包。
  3. 在Visual Studio中重新运行单元测试(作为健全性检查),这些应该可以通过。
  4. 从Jenkins进行更改,推送,重新运行构建。