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

11,275

Solution 1

You need to install the visual studio to run the Unit tests on TeamCity build server. According to Team City documentation,

The appropriate Microsoft Visual Studio edition installed on the build agent is required.

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

Solution 2

For VS 2019, I had to change the Target Framework.

From target framework 4 to 4.6(last version)

Share:
11,275
SharpCoder
Author by

SharpCoder

Updated on June 04, 2022

Comments

  • SharpCoder
    SharpCoder almost 2 years

    I am using Visual Studio 2015 professional edition to run some test cases on my local machine. I am able to build the solution & run test cases locally.

    When I build my application on TeamCity server (build agent is also hosted on team city server), I am getting following errors:

    Controllers\OneControllerTest.cs(5, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    Controllers\LandingControllerTest.cs(2, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    Controllers\TwoControllerTest.cs(5, 17): error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)
    Controllers\OneControllerTest.cs(15, 10): error CS0118: 'My_api.Test.OneControllerTest.TestInitialize()' is a 'method' but is used like a 'type' 
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\OneControllerTest.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?)
    Controllers\LandingControllerTest.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?)
    Controllers\LandingControllerTest.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?)
    Controllers\LandingControllerTest.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?)
    Controllers\LandingControllerTest.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?)
    Controllers\TwoControllerTest.cs(18, 10): error CS0118: 'My_api.Test.Controllers.TwoControllerTest.TestInitialize()' is a 'method' but is used like a 'type'
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    Controllers\TwoControllerTest.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?)
    

    I am using following nuget packages:

    <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>
    

    My team city server box has .net framework 4.0 installed on it. I am trying to avoid installing Visual Studio on team city server,

    What could be the reason for this error?

    • vendettamit
      vendettamit almost 6 years
      You may need to install visual studio on BuildServer.
    • SharpCoder
      SharpCoder almost 6 years
      @vendettamit: That is what i was trying to avoid. I wonder if I can install some service pack and make it work.
  • SharpCoder
    SharpCoder almost 6 years
    Thank you for the reply. Is it possible not to run the unit test cases and only use team city for building and deploying the application ? i do not want to install VS on build server.
  • SharpCoder
    SharpCoder almost 6 years
    Please check this link confluence.jetbrains.com/display/TCD9/Visual+Studio+Tests it says Prior to TeamCity 9.1.5, the runner requires the appropriate Microsoft Visual Studio edition installed on the build agent. Since TeamCity 9.1.5, the Visual Studio Test Runner supports Visual Studio Test Agent installed on the agent machine (Microsoft Visual Studio is no longer required). .I am using team city 9.1.7.
  • vendettamit
    vendettamit almost 6 years
    That's interesting.. I didn't knew that as well. I had my server setup with VS installed on server. I use Visual studio sln as my build runner. It might be possible but would require more efforts configuring it with MSBUILD runner and using VS Agents. Good Luck!!
  • parameter
    parameter almost 5 years
    What was the target framework before? What did you end up changing it to?
  • Yousha Aleayoub
    Yousha Aleayoub almost 5 years
    @parameter From target framework 4 to 4.6(last version).
  • parameter
    parameter almost 5 years
    Thank you for the info, running into this same issue now trying to update teamcity..