public void Test() { var fileName = Path.GetTempFileName(); try { File.WriteAllText(fileName, "<Weavers />"); var configFiles1 = new[] { new WeaverConfigFile(fileName) }; var hasChanged = WeaversConfigHistory.HasChanged(configFiles1); Assert.False(hasChanged); WeaversConfigHistory.RegisterSnapshot(configFiles1); var configFiles2 = new[] { new WeaverConfigFile(fileName) }; hasChanged = WeaversConfigHistory.HasChanged(configFiles2); Assert.False(hasChanged); WeaversConfigHistory.RegisterSnapshot(configFiles2); File.WriteAllText(fileName, "<Weavers VerifyAssembly='true' />"); var configFiles3 = new[] { new WeaverConfigFile(fileName) }; hasChanged = WeaversConfigHistory.HasChanged(configFiles3); Assert.True(hasChanged); } finally { File.Delete(fileName); } }
void Inner() { ValidateSolutionPath(); ValidateProjectPath(); ValidateAssemblyPath(); ConfigFiles = ConfigFileFinder.FindWeaverConfigFiles(SolutionDirectory, ProjectDirectory, Logger).ToList(); if (!ConfigFiles.Any()) { ConfigFiles = new List <WeaverConfigFile> { ConfigFileFinder.GenerateDefault(ProjectDirectory, Weavers, GenerateXsd) }; Logger.LogWarning($"Could not find a FodyWeavers.xml file at the project level ({ProjectDirectory}). A default file has been created. Please review the file and add it to your project."); } ConfigEntries = ConfigFileFinder.ParseWeaverConfigEntries(ConfigFiles); var extraEntries = ConfigEntries.Values .Where(entry => !entry.ConfigFile.IsGlobal && !Weavers.Any(weaver => string.Equals(weaver.ElementName, entry.ElementName))) .ToArray(); const string missingWeaversHelp = "Add the desired weavers via their nuget package; see https://github.com/Fody/Fody/wiki on how to migrate InSolution, custom or legacy weavers."; if (extraEntries.Any()) { throw new WeavingException($"No weavers found for the configuration entries {string.Join(", ", extraEntries.Select(e => e.ElementName))}. " + missingWeaversHelp); } if (Weavers.Count == 0) { throw new WeavingException("No weavers found. " + missingWeaversHelp); } foreach (var weaver in Weavers) { if (ConfigEntries.TryGetValue(weaver.ElementName, out var config)) { weaver.Element = config.Content; weaver.ExecutionOrder = config.ExecutionOrder; } else { Logger.LogWarning($"No configuration entry found for the installed weaver {weaver.ElementName}. This weaver will be skipped. You may want to add this weaver to your FodyWeavers.xml"); } } ConfigFileFinder.EnsureSchemaIsUpToDate(ProjectDirectory, Weavers, GenerateXsd); Weavers = Weavers .Where(weaver => weaver.Element != null) .OrderBy(weaver => weaver.ExecutionOrder) .ToList(); if (TargetAssemblyHasAlreadyBeenProcessed()) { if (WeaversConfigHistory.HasChanged(ConfigFiles) || WeaversHistory.HasChanged(Weavers.Select(x => x.AssemblyPath))) { Logger.LogError("A re-build is required because a weaver has changed."); return; } } lock (mutex) { ExecuteInOwnAssemblyLoadContext(); } WeaversConfigHistory.RegisterSnapshot(ConfigFiles); }