public void WeavedAssembly_ShouldContainWeavedInfo() { using (var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = tempFilePath, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "FakeModuleWeaver", AssemblyName = "FodyIsolated.Tests", AssemblyPath = $@"{AssemblyLocation.CurrentDirectory}\Tests.dll" } } }) { innerWeaver.Execute(); } using (var readModule = ModuleDefinition.ReadModule(tempFilePath)) { var type = readModule.Types .Single(_ => _.Name == "ProcessedByFody"); var condition = type.Fields.Any(f => f.Name == "FodyIsolatedTests"); Assert.True(condition); } }
public void WeavedAssembly_ShouldContainWeavedInfo() { var moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock<ILogger>().Object, AssemblyFilePath = TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll", ModuleDefinition = moduleDefinition, DefineConstants = new List<string> { "Debug", "Release" }, Weavers = new List<WeaverEntry> { new WeaverEntry { TypeName = "ModuleWeaver", AssemblyName = "Sample.Fody", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\Sample.Fody.dll" } } }; innerWeaver.Execute(); moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); Assert.IsTrue(moduleDefinition.Types.Count(_ => _.Name == "FodyWeavingResults") >= 1); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").HasCustomAttributes); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").Fields.Any(f => f.Name == "SampleFody")); }
public void WeavedAssembly_ShouldContainWeavedInfo() { var moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll", ModuleDefinition = moduleDefinition, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "ModuleWeaver", AssemblyName = "Sample.Fody", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\Sample.Fody.dll" } } }; innerWeaver.Execute(); moduleDefinition = ModuleDefinition.ReadModule(TestContext.CurrentContext.TestDirectory + "\\DummyAssembly.dll"); Assert.IsTrue(moduleDefinition.Types.Count(_ => _.Name == "FodyWeavingResults") >= 1); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").HasCustomAttributes); Assert.IsTrue(moduleDefinition.Types.First(_ => _.Name == "FodyWeavingResults").Fields.Any(f => f.Name == "SampleFody")); }
private void WeaveImpl(List <WeaverEntry> entries, string references) { var innerWeaver = new InnerWeaver() { Logger = new Logger(), AssemblyFilePath = _assemblyPath, Weavers = entries, References = references }; innerWeaver.Execute(); }
static void Main(string[] args) { var logger = new ConsoleLogger(); CommandLineArguments clargs; try { clargs = args.As <CommandLineArguments>(); } catch (ArgumentException ex) { logger.LogException(ex); Console.WriteLine(); Console.WriteLine(AppArgs.HelpFor <CommandLineArguments>()); return; } var weavers = FindWeavers(clargs); using (IInnerWeaver innerWeaver = new InnerWeaver()) { // Default innerWeaver.KeyFilePath = ""; innerWeaver.SignAssembly = false; // Not from args innerWeaver.Logger = logger; innerWeaver.Weavers = weavers.ToList(); // From args innerWeaver.AssemblyFilePath = clargs.AssemblyFilePath; innerWeaver.References = clargs.References; innerWeaver.SolutionDirectoryPath = clargs.SolutionDirectory; innerWeaver.IntermediateDirectoryPath = Path.GetDirectoryName(clargs.AssemblyFilePath); innerWeaver.DefineConstants = clargs.DefineConstants.Split(';').ToList(); innerWeaver.ProjectDirectoryPath = clargs.ProjectDirectoryPath; innerWeaver.ReferenceCopyLocalPaths = clargs.ReferenceCopyLocalPaths?.Split(';').ToList(); innerWeaver.Execute(); } }
static void Main(string[] args) { var logger = new ConsoleLogger(); CommandLineArguments clargs; try { clargs = args.As<CommandLineArguments>(); } catch (ArgumentException ex) { logger.LogException(ex); Console.WriteLine(); Console.WriteLine(AppArgs.HelpFor<CommandLineArguments>()); return; } var weavers = FindWeavers(clargs); using (IInnerWeaver innerWeaver = new InnerWeaver()) { // Default innerWeaver.KeyFilePath = ""; innerWeaver.SignAssembly = false; // Not from args innerWeaver.Logger = logger; innerWeaver.Weavers = weavers.ToList(); // From args innerWeaver.AssemblyFilePath = clargs.AssemblyFilePath; innerWeaver.References = clargs.References; innerWeaver.SolutionDirectoryPath = clargs.SolutionDirectory; innerWeaver.IntermediateDirectoryPath = Path.GetDirectoryName(clargs.AssemblyFilePath); innerWeaver.DefineConstants = clargs.DefineConstants.Split(';').ToList(); innerWeaver.ProjectDirectoryPath = clargs.ProjectDirectoryPath; innerWeaver.ReferenceCopyLocalPaths = clargs.ReferenceCopyLocalPaths?.Split(';').ToList(); innerWeaver.Execute(); } }
public void WeavedAssembly_ShouldContainWeavedInfo() { var assemblyFilePath = $@"{TestContext.CurrentContext.TestDirectory}\DummyAssembly.dll"; var pdbFilePath = $@"{TestContext.CurrentContext.TestDirectory}\DummyAssembly.pdb"; var tempFilePath = $@"{TestContext.CurrentContext.TestDirectory}\Temp.dll"; var tempPdbFilePath = $@"{TestContext.CurrentContext.TestDirectory}\Temp.pdb"; File.Copy(assemblyFilePath, tempFilePath, true); File.Copy(pdbFilePath, tempPdbFilePath, true); var innerWeaver = new InnerWeaver { References = string.Empty, Logger = new Mock <ILogger>().Object, AssemblyFilePath = tempFilePath, DefineConstants = new List <string> { "Debug", "Release" }, Weavers = new List <WeaverEntry> { new WeaverEntry { TypeName = "FakeModuleWeaver", AssemblyName = "FodyIsolated.Tests", AssemblyPath = TestContext.CurrentContext.TestDirectory + "\\FodyIsolated.Tests.dll" } } }; innerWeaver.Execute(); using (var readModule = ModuleDefinition.ReadModule(tempFilePath)) { var type = readModule.Types .Single(_ => _.Name == "ProcessedByFody"); Assert.IsTrue(type.Fields.Any(f => f.Name == "FodyIsolatedTests")); } }
public Task <bool> RunAsync( string assemblyFilePath, IEnumerable <string> references, List <string> defineConstants, bool isDebugBuild, CancellationToken cancellationToken = default) { if (_weaverEntries == null) { throw new NotConfiguredException(); } return(Task.Run( () => { string assemblyFileName = Path.GetFileNameWithoutExtension(assemblyFilePath); if (assemblyFileName != null && _assemblyRegexes.TrueForAll(regex => !regex.IsMatch(assemblyFileName))) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because none of the configured" + " regular expressions match the assembly name."); return false; } if (!File.Exists(assemblyFilePath)) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because the file doesn't exist."); return false; } if (IsAssemblyProcessed(assemblyFilePath)) { _logForwarder.LogInfo( $"Not processing assembly '{assemblyFilePath}' because it has already been processed."); return false; } InnerWeaver innerWeaver = new InnerWeaver { AssemblyFilePath = assemblyFilePath, References = string.Join(";", references), ReferenceCopyLocalPaths = new List <string>(), DefineConstants = defineConstants, Logger = _logForwarder, Weavers = _weaverEntries, DebugSymbols = isDebugBuild ? DebugSymbolsType.External : DebugSymbolsType.None }; CancellationTokenRegistration cancellationTokenRegistration = // ReSharper disable once AccessToDisposedClosure cancellationToken.Register(() => innerWeaver.Cancel()); try { innerWeaver.Execute(); } finally { cancellationTokenRegistration.Dispose(); innerWeaver.Dispose(); } return true; }, cancellationToken)); }