问题
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?
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/44156571/msbuild-15-the-type-or-namespace-fakes-does-not-exist-in-the-namespace