Foxocube
Foxocube

Reputation: 740

MSBuild 15 - The type or namespace 'Fakes' does not exist in the namespace

I'm trying to set up automated builds and unit testing for a project which uses the Fakes library for it's unit tests. The project builds and tests fine on my Windows 10 PC (VS 2017 Enterprise installed), however using the same command to compile the project on the build server (also windows 10 with VS 2017 Enterprise) gives several errors about the Fakes not existing. The exact errors look like this:

XControllerTests.cs(10,20): error CS0234: The type or namespace 'Fakes' does not exist in the namespace 'System.Data.Common' (are you missing an assembly reference?) [C:\Runner\builds\xxx\XTests.csproj]

From my research, this is caused by using an old version of MSBuild, however I have checked the server, and confirmed it has the latest version & updates for visual studio installed. I also confirmed that the build script is using the correct version of MSBuild.exe, which is c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe. Using this version on my desktop correctly compiles the project.

Why does the build not work on the (identical setup) build server?

Upvotes: 9

Views: 10819

Answers (3)

Antebios
Antebios

Reputation: 1781

For Visual Studio 2022 Build Tools, here are updated instructions:

Fake Assembly Folder

Source: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VisualStudio\v17.0\Fakes

Target: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Microsoft\VisualStudio\v17.0\Fakes

Fake Targets:

Source: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Microsoft.Common.Targets\ImportAfter\Microsoft.QualityTools.Testing.Fakes.ImportAfter.targets

Target: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Microsoft.Common.Targets\ImportAfter

Test Assemblies

Source:

  • C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\IDE\PublicAssemblies\
    • Microsoft.QualityTools.Testing.Fakes.dll
    • Microsoft.VisualStudio.QualityTools.Common.dll
    • Microsoft.VisualStudio.QualityTools.ExecutionCommon.dll
    • Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
    • Microsoft.VisualStudio.QualityTools.Vsip.dll

Target Directory: C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\IDE\PublicAssemblies

Upvotes: 2

zionyx
zionyx

Reputation: 2085

To extend @McMlok's answer above, i'll include what i did.

  • Source: My local VS2017 Premium Update 1 dev machine.
  • Target: The VS2017 Build Tools VM.

Copy Fakes folder:

  • From Source: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\
  • To Target: c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\

Copy Microsoft.QualityTools.Testing.Fakes.ImportAfter.targets file:

  • From Source: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.targets\ImportAfter\
  • To Target: c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Microsoft.Common.Targets\ImportAfter\

Copy Microsoft.QualityTools.Testing.Fakes.dll file:

  • From Source: c:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\PublicAssemblies\
  • To Target: GAC / %windir%\Microsoft.NET\assembly

Builds fine now. Thanks McMlok.

Upvotes: 7

McMlok
McMlok

Reputation: 537

I have some workaround but It's not elegant.

You need to check path C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0 if there is Fakes folder. If not you need to install TestTools workload or copy from another machine.

Next you need to check C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Microsoft.Common.Targets\ImportAfter if there is file Microsoft.QualityTools.Testing.Fakes.ImportAfter.targets if not copy it from another machine. In this file is code for including fakes target to build process.

And finally you need to check if you have assembly Microsoft.QualityTools.Testing.Fakes.dll in GAC or another location where MSBuild find it.

This I did on my build machine with MS Build Tools 2017 and now build generate fakes assemblies.

Upvotes: 5

Related Questions