Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 964
Foxocube Avatar asked May 24 '17 11:05

Foxocube


2 Answers

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.

like image 103
zionyx Avatar answered Oct 13 '22 00:10

zionyx


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.

like image 41
McMlok Avatar answered Oct 13 '22 01:10

McMlok