Well, in case someone works with outdated code and turns out to be cornered using Microsoft Moles, I have done extensive work on this topic and hope to retain some of the anger and frustration that I came across.
I tried using the accepted answer sentence, which meant going to the Moles directory (in C: \ Program Files ..) and running the command line utility (moles.exe) as an administrator. There are many options, one of which allows you to include reference assemblies (as suggested above).
However, even when I try to run the utility without reference assemblies, the utility eventually calls the C # compiler (csc.exe) with predefined reference assembly goals, in which I conclude that there is confusion between versions of the .NET Framework, I could not get it to not turn on these assembly paths.
My specific scenario was that I was trying to install Mole on a custom assembly, however, since I apparently had .NET 4.5 installed on this machine, it complained about a compilation about System.Collections.Generics IReadOnlyCollection, IReadOnlyDictionary, and I think different.
Solution . Decision I got is to use Mole filters, which I read about in other posts and on the Microsoft Moles website (there is a special link for troubleshooting .NET 4.5 on the main page). In Visual Studio, I simply added the Moles assembly to my unit test project for my custom assembly that is referenced by right-clicking in the solution explorer. Then I tried to build. For each error I received, I noticed classes that violate the rules and excluded them from Shimmed or Stubbed by adding the following to the moles file:
<Moles xmlns="http://schemas.microsoft.com/moles/2010/"> <Assembly Name = "MyCustomAssembly" /> <StubGeneration> <Types> <Remove TypeName="ClassThatUsesIReadOnlyCollectionEtc" /> </Types> </StubGeneration> <MoleGeneration> <Types> <Remove TypeName="ClassThatUsesIReadOnlyCollectionEtc" /> </Types> </MoleGeneration> </Moles>
Now itβs clear that you are not going to work if you need classes that you exclude from the mole / stub generation, but for my case this worked fine because the intruder classes were not important and I would not need a Stub or Helmet something- sometime in these classes.