// called via fody during msbuild public void Execute() { var nsubstituteAssemblyPath = NSubstituteAssemblyPath ?? Path.Combine(AddinDirectoryPath, "NSubstitute.dll"); if (!File.Exists(nsubstituteAssemblyPath)) { throw new FileNotFoundException($"Unable to weave without a valid NSubstitute assembly (given {nsubstituteAssemblyPath ?? "<none>"})"); } LogDebug("Using NSubstitute assembly: " + nsubstituteAssemblyPath); ModuleDefinition.Accept(new MockInjectorVisitor(AssemblyDefinition.ReadAssembly(nsubstituteAssemblyPath), ModuleDefinition)); // TODO: would be better to tune this with xml config rather than hard coded name matching if (Path.GetFileNameWithoutExtension(ModuleDefinition.FullyQualifiedName) == "NSubstitute.Weaver.Tests") { // this is copied from a sample, but let's leave it in here to check basic fody injection mechanics are set up right (there's a test for it elsewhere) var typeDefinition = new TypeDefinition("NSubstitute.Weaver.Tests", "InjectedTypeForTest", TypeAttributes.NotPublic, ModuleDefinition.Import(typeof(object))); ModuleDefinition.Types.Add(typeDefinition); } }