What:

Fakes exposes some configuration options through .fakes file which is part of your solution. However, beyond this file there are some other options as well that are understood by the fakes engine. These options are not documented anywhere, so this blog describes some of those extra options which can be used to configure/override the default behavior of Fakes beyond what is provided by the .fakes file.

 

How:

To use the below options, locate your fakes targets file from a location like : "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\Fakes\Microsoft.QualityTools.Testing.Fakes.targets". Note that while some of the properties like TargetFrameworkversion are directly exposed, some others like msbuildpath are passed to the FakesEngine via FakesCommandLineArguments like this :

<FakesCommandLineArguments>$(FakesCommandLineArguments) /msbuildpath:"$(FakesMSBuildPath)"</FakesCommandLineArguments>

 

Glossary:

 

Configuration Option

PropertyName to Use

Description

Possible Values

Default Value

Available In Fakes file

 

 

 

 

 

 

TargetFrameworkVersion
 

TargetFrameworkVersion
 

Target DotNet framework version with which fakes assemblies should get compiled with.

A valid DotNet version

v4.5

Yes

TargetRuntimeVersion
 

TargetRuntimeVersion
 

CLR Runtime version to be used (corresponding fakes engine executable is invoked)

v4.0.30319, v2.0.50727

v4.0.30319

No

ToolsVersion

FakesCommandLineArguments
  with "/tv"

Build Toolset version to be used for creating fakes assemblies.

A valid toolset version

v4.0

No

Debug

FakesCommandLineArguments
  with "/d"

Generate the fakes assembly with 'debug' configuration.

NA

False. ie. Build Configuration is set to Release.

Yes

Properties

FakesCompilationProperties

Semicolon separated list of project properties to be set in the fakes project.

Format : <property name1>=<property value1>;<property name2>=<property value2>;

None

Yes

KeyFile

FakesCommandLineArguments
  with "/key:<filepath>"

Path to the KeyFile for signing the fakes assembly.

<filepath>

None

Yes

ProjectTemplate
 

FakesCommandLineArguments
  with "/pt:<projfilepath>"

Path to a .proj file which will be used as a template for creating fakes  assembly's.proj file. This option can be used to further customize fakes code generation if the rest of the options don’t suffice. For ex. Add a prebuild/postbuild event for the fakes assembly. Attaching a basic sample  template to start with.

<<ProjectTemplate.csproj>>

<proj file path>

None

Yes

MsbuildPath

FakesMsbuildPath

Path to the msbuild executable to be used for compiling fakes assemblies

<msbuild executable file path>

As specified by $MSBuildToolsPath

No

FrameworkPath
 

FakesBinPath

Directory Path where Microsoft.QualityTools.Testing.Fakes.dll is present

<directory path>

"C:\Program Files (x86)\MSBuild\Microsoft\ VisualStudio\v12.0\Fakes"

No

OutputPath

FakesOutputPath

Path to be used for dumping the generated fakes assemblies after copying them from intermediate path

<directory path>

<currentdirectory>\ FakesAssemblies

No

IntermediatePath
 

FakesIntermediatePath

Path to be used for dumping the intermediate code generated during creating fakes assemblies

<directory path>

<currentdirectory>\obj

No

CleanIntermediatePath
 

FakesCommandLineArguments
  with "/clean"

Delete the intermediate code that gets generated during fakes creation.

NA

False

No

ForceIntermediatePath
  (depcrecated)

FakesCommandLineArguments
  with "/fip"

Normally for each assembly, a folder is created under the intermediate path using the assembly name. If this option is set, the folder creation for each assembly does not happen, and instead the same folder is shared for all assemblies.

NA

False

No

ForceReadOnly

FakesCommandLineArguments
  with "/f"

If during fakes code generation or fakes compilation a file already exists as readonly, it won't get overwritten. Setting this option to true will ensure all readonly files are replaced.

NA

False

No

TargetX86

ForceX86

Force fakes engine to run as 32-bit process. Ideally the bitness is automatically determined from the assembly to be faked.

NA

Bitness as specified by the assembly to be faked

Yes

Elevated

FakesCommandLineArguments
  with "/admin"

Launch Fakes engine as elevated process. Ideally, if the invoking process is elevated, fakes process will automatically be launched elevated.

NA

Invoking process' elevation state

No

FakesFilesOnly
 

FakesCommandLineArguments
  with "/mfo"

Let's fakes accept only .fakes file, instead of accepting a .dll directly.

NA

False

No

ProcessCount

FakesCommandLineArguments
  "/pc:<integer>"

Number of concurrent fakes processes to spawn for generating Fakes. Ideally, if multiple assemblies are to be faked, fakes will automatically figure out and spawn the appropriate number of parallel processes based on machine's CPU Cores. This option can let you tune (lower) this value if required.

<integer>

Minimum of
{Number of CPU Cores, Number of fakes assemblies to be generated}

No

Leaf

FakesCommandLineArguments
  with "/l"

There are situations when the fakes engine needs to re-launch itself under a different environment to suite the Bitness/CLR/Elevation requirements. In some cases this might lead to an infinite invocation loop. This option can be used to avoid fakes re-launch itself  to avoid ending up in such a situation.

NA

False

No

Verbosity

FakesVerbosity

Verbosity level of Fakes engine.

Critical|Error|Warning|
 Message|Verbose|Noisy

Message

Yes

NamespaceFilter
 

FakesCommandLineArguments
  with "/nf:<filterstring>"

Filter out namespaces while generating stubs and shims

<filter string>

No filter

Yes

TypeFilter

FakesCommandLineArguments
  with "/tf:<filterstring>

Filter out types while generating stubs and shims

<filter string>

No filter

Yes

DisableStubs

FakesCommandLineArguments
  with "/nostubs"

Disable generation of stubs

<filter string>

False

Yes

DisableShims

FakesCommandLineArguments
  with "/noshims"

Disable generation of shims

<filter string>

False

Yes

AssemblyHash

FakesCommandLineArguments
  with "/ah:<hash string>"

Pass an assembly hash string, to determine if fakes code generation and fakes compilation should be skipped.

<string>

Null.

No

CompilationHash

FakesCommandLineArguments
  with "/ch:<hash string>"

Pass an assembly hash string, to determine if fakes compilation should be skipped.

<string>

Null.

No

ForceGeneration

FakesCommandLineArguments
  with "/fg"

Overrides all hash-validation checks which skip fakes generation and generates fakes forcefully.

NA

No

No

ReferenceAssemblies
 

FakesCommandLineArguments
  with "/r:<syntax>"

Semicolon separated list of all assembly paths that are required for resolving dependencies of the fakes assembly.

Path can contain environment variables.

Format : <assembly's fully qualified name>|<assembly's file path>. Ex: /r:ClassLibrary1,
  Version=1.0.0.0, Culture=neutral, PublicKeyToken=null| C:\Release\ClassLibrary1.dll

None

Yes

ComReferences
 

FakesCommandLineArguments
  with "/comr:<syntax>"

Path of COM references that are required for generating the fakes assembly.

-do-

None

No

DisableCodeContracts

FakesCommandLineArguments
  with "/nocc"

Skip Code Contracts during runtime instrumentation. This might be required when there are any issues with CodeContracts.

NA

False

Yes

NoLogo

FakesCommandLineArguments
  with "/n"

Disables emitting Fakes logo and copyright information

NA

False

No

 

Note:

You will see that some of the options are available via both places (.fakes file and .targets file). Avoid a situation where your configurations are setup in a conflicting way in both places.