2

In Visual Studio, when you right click a reference, you can "Add Fakes Assembly", which kicks off a process that generates the *.Fakes.dll assembly.

enter image description here


When I looked into it, it seems that it utilizes one of the following files:

  • Fakes.exe
  • Fakes.v2.exe
  • Fakes.v2.x86.exe
  • Fakes.x86.exe

I'm not sure which one, but it has to be one of those. Those files are located in (at least on my machine, but this is the common path): C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Microsoft\VisualStudio\v15.0\Fakes

The problem here is that if I want to call the fakes generation tool through command line, I have to hard code in the path which may or may not be that path. I know in the past when I attempted to programmatically discover ildasm.exe and ilasm.exe someone showed me that it was possible: Guaranteed way to find the filepath of the ildasm.exe and ilasm.exe files regardless of .NET version/environment?

I'm wondering is there anything similar to get the correct path for the fakes tools without having to hard-code the path in since it is unreliable to assume everyone uses the default installation drive/path and also I shouldn't assume that everyone has Visual Studio 2015, 2017, or other future versions installed.


Update:

I think my original question was not clear in what I'm trying to do. If I have a solution/project, this is easy to do. However, I want to do this outside of a solution/project; I want to either use a standard command window or even a PowerShell script is acceptable. Basically, I don't want to have to create a solution/project merely to access the path to the fakes tooling.

Community
  • 1
  • 1
myermian
  • 31,823
  • 24
  • 123
  • 215
  • Any update for this issue? Does the answer resolve you question? if not, would you please let me know the latest information about this issue? Thanks. – Leo Liu Mar 22 '17 at 12:12

1 Answers1

1

I'm wondering is there anything similar to get the correct path for the fakes tools without having to hard-code the path in since it is unreliable to assume everyone uses the default installation drive/path

We could use the MSBuild predefined properties $(MSBuildExtensionsPath) and $(MSBuildToolsVersion) in MSBuild Reserved and Well-Known Properties to get the correct path for fakes tools without hard-code path.

I have tested it on Visual Studio 2015 and 2017 by pre/post build event, the result is able to get the path correctly:

enter image description here enter image description here

So you could use below command to get the correct path for the fakes tools without hard-code the path.

$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\Fakes
Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Sorry, perhaps my original question was not clear. I am trying to avoid doing this in any sort of sln/project, I want to purely use cmd.exe or even a PowerShell script. I'll update my question to reflect this. – myermian Apr 18 '17 at 14:33