8

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?

Foxocube
  • 710
  • 9
  • 32
  • I have same problém but I use MS Build Tools 2017 on build server. Than path to msbuild is c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin – McMlok Jun 08 '17 at 13:47

3 Answers3

7

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.

zionyx
  • 1,927
  • 19
  • 14
  • Copying folders like that might be the violation of license. Should not be recommended. – HBhatia Feb 14 '19 at 04:52
  • Provided you already own higher tier VS editions of course. I don't see why you cannot copy your licensed Premium VS to a build environment that installs only BuildTools. – zionyx Feb 14 '19 at 09:06
5

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.

McMlok
  • 527
  • 4
  • 17
  • Thanks alot! But the path is a little hard to figure out on the build tools machine. Added my answer too. – zionyx Jul 05 '17 at 14:14
  • 1
    For Build Tools 2019, Fakes folder is in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VisualStudio\v16.0` and Targets are in `C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Microsoft.Common.Targets\ImportAfter`. Keep the same folder hierarchy on the build machine. – scottheckel Nov 15 '19 at 18:08
1

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

Antebios
  • 1,681
  • 1
  • 13
  • 22