2

I am trying to build a dotnet solution using the below command but getting error

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

Command:

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

The code is present in Bitbucket and I am triggering the build from Jenkins. The code is running in windows server.

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?)
halfer
  • 19,824
  • 17
  • 99
  • 186
user176961
  • 21
  • 3

1 Answers1

0

I ran into the same problem and found that it was caused by the unit test project being created in an older version of Visual Studio which used Microsoft.VisualStudio.QualityTools.UnitTestFramework. This should be changed to use use Microsoft.VisualStudio.TestPlatform.TestFramework, which is the default used in later unit-test projects. Steps to fix:

  1. Open the unit test project references and delete the reference to Microsoft.VisualStudio.QualityTools.UnitTestFramework: UnitTests References
  2. Open Manage NuGet Packages for the project, and add the MSTest.TestFramework package.
  3. Rerun your unit tests in Visual Studio (as a sanity check) and these should pass.
  4. Commit changes, push, rerun build from Jenkins.
Bassmanjase
  • 167
  • 4
  • 14