错误 CS0234:命名空间"Microsoft"中不存在类型或命名空间名称"VisualStudio"(是否缺少程序集引用?



我正在使用Visual Studio 2015专业版在本地计算机上运行一些测试用例。我能够构建解决方案并在本地运行测试用例。

当我在 TeamCity 服务器上构建应用程序(生成代理也托管在团队城市服务器上(时,出现以下错误:

ControllersOneControllerTest.cs(5, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
ControllersLandingControllerTest.cs(2, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
ControllersTwoControllerTest.cs(5, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
ControllersOneControllerTest.cs(15, 10): error CS0118: 'My_api.Test.OneControllerTest.TestInitialize()' is a 'method' but is used like a 'type' 
ControllersOneControllerTest.cs(15, 10): error CS0246: The type or namespace name 'TestInitializeAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(22, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(22, 10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(39, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(39, 10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(40, 10): error CS0246: The type or namespace name 'ExpectedException' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(40, 10): error CS0246: The type or namespace name 'ExpectedExceptionAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(11, 6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)
ControllersOneControllerTest.cs(11, 6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersLandingControllerTest.cs(10, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
ControllersLandingControllerTest.cs(10, 10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersLandingControllerTest.cs(7, 6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)
ControllersLandingControllerTest.cs(7, 6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(18, 10): error CS0118: 'My_api.Test.Controllers.TwoControllerTest.TestInitialize()' is a 'method' but is used like a 'type'
ControllersTwoControllerTest.cs(18, 10): error CS0246: The type or namespace name 'TestInitializeAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(44, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(44, 10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(60, 10): error CS0246: The type or namespace name 'TestMethod' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(60, 10): error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(13, 6): error CS0246: The type or namespace name 'TestClass' could not be found (are you missing a using directive or an assembly reference?)
ControllersTwoControllerTest.cs(13, 6): error CS0246: The type or namespace name 'TestClassAttribute' could not be found (are you missing a using directive or an assembly reference?)

我正在使用以下 nuget 包:

<packages>
<package id="Castle.Core" version="4.2.1" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net45" />
<package id="Microsoft.UnitTestFramework.Extensions" version="2.0.0" targetFramework="net45" />
<package id="Moq" version="4.8.0" targetFramework="net45" />
<package id="MSTest.TestAdapter" version="1.3.2" targetFramework="net45" />
<package id="MSTest.TestFramework" version="1.3.2" targetFramework="net45" />
<package id="Newtonsoft.Json" version="9.0.1" targetFramework="net45" />
<package id="System.Diagnostics.Contracts" version="4.0.1" targetFramework="net45" />
<package id="System.Threading.Tasks.Extensions" version="4.4.0" targetFramework="net45" />
<package id="System.ValueTuple" version="4.4.0" targetFramework="net45" />
<package id="Unity.AspNet.WebApi" version="4.0.1" targetFramework="net452" />
</packages>

我的团队城市服务器框上安装了 .net 框架 4.0。我试图避免在团队城市服务器上安装Visual Studio,

此错误的原因可能是什么?

您需要安装 Visual Studio 才能在 TeamCity 生成服务器上运行单元测试。根据团队城市文档,

需要在生成代理上安装相应的 Microsoft Visual Studio 版本。

见 https://confluence.jetbrains.com/display/TCD10/MSTest+Support

对于VS 2019,我不得不更改目标框架

从目标框架 4 到 4.6(最新版本(

最新更新