void FindWeavers() { var stopwatch = Stopwatch.StartNew(); Logger.LogDebug("Finding weavers"); ReadProjectWeavers(); addinFinder = new AddinFinder(Logger.LogDebug, SolutionDirectory, MSBuildDirectory, NuGetPackageRoot, WeaverFilesFromProps); addinFinder.FindAddinDirectories(); FindWeaverProjectFile(); ConfigureWhenWeaversFound(); ConfigureWhenNoWeaversFound(); ConfigFile.EnsureSchemaIsUpToDate(ProjectDirectory, WeaverFilesFromProps, Weavers, GenerateXsd); Logger.LogDebug($"Finished finding weavers {stopwatch.ElapsedMilliseconds}ms"); }
public void XmlConfigShouldOverrideMSBuildPropertyForXsdGeneration() { File.WriteAllText(xmlPath, @" <Weavers GenerateXsd=""true""> <TestWeaver /> </Weavers> "); var wellKnownWeaverFiles = new[] { @"something\TestWeaver.Fody.dll" }; var configs = ConfigFile.FindWeaverConfigs(Guid.NewGuid().ToString(), testDir, new Mock <BuildLogger>().Object, wellKnownWeaverFiles, false); ConfigFile.EnsureSchemaIsUpToDate(testDir, wellKnownWeaverFiles, null, false); Assert.Single(configs); Assert.Equal(xmlPath, configs[0]); Assert.True(File.Exists(xsdPath)); var xml = XDocumentEx.Load(xmlPath); Assert.NotNull(xml.Root); Assert.Equal("FodyWeavers.xsd", xml.Root.Attribute(schemaInstanceNamespace + "noNamespaceSchemaLocation")?.Value); }
public void ShouldOptOutOfXsdThroughMSBuildProperty() { File.WriteAllText(xmlPath, @" <Weavers> <TestWeaver /> </Weavers> "); var wellKnownWeaverFiles = new[] { @"something\TestWeaver.Fody.dll" }; var configs = ConfigFile.FindWeaverConfigs(Guid.NewGuid().ToString(), testDir, new Mock <BuildLogger>().Object, wellKnownWeaverFiles, false); ConfigFile.EnsureSchemaIsUpToDate(testDir, wellKnownWeaverFiles, null, false); Assert.Single(configs); Assert.Equal(xmlPath, configs[0]); Assert.False(File.Exists(xsdPath)); var xml = XDocumentEx.Load(xmlPath); Assert.NotNull(xml.Root); Assert.Null(xml.Root.Attribute(schemaInstanceNamespace + "noNamespaceSchemaLocation")); }
public void ShouldCreateXsd() { File.WriteAllText(xmlPath, @" <Weavers> <TestWeaver /> </Weavers> "); File.WriteAllText(Path.Combine(testDir, "WeaverWithSchema.Fody.xcf"), @" <xs:complexType xmlns:xs=""http://www.w3.org/2001/XMLSchema""> <xs:attribute name=""TestAttribute"" type=""xs:string"" /> </xs:complexType> "); var wellKnownWeaverFiles = new[] { @"something\TestWeaver.Fody.dll", Path.Combine(testDir, "WeaverWithSchema.Fody.dll") }; var configs = ConfigFile.FindWeaverConfigs(Guid.NewGuid().ToString(), testDir, new Mock <BuildLogger>().Object, wellKnownWeaverFiles, true); ConfigFile.EnsureSchemaIsUpToDate(testDir, wellKnownWeaverFiles, null, true); Assert.Single(configs); Assert.Equal(xmlPath, configs[0]); Assert.True(File.Exists(xsdPath)); var xml = XDocumentEx.Load(xmlPath); Assert.NotNull(xml.Root); Assert.Equal("FodyWeavers.xsd", xml.Root.Attribute(schemaInstanceNamespace + "noNamespaceSchemaLocation")?.Value); var xsd = XDocumentEx.Load(xsdPath); Assert.NotNull(xsd.Root); var elements = xsd.Root.Descendants(schemaNamespace + "all").First().Elements().ToList(); Assert.Equal(2, elements.Count); var defaultElem = elements[0]; Assert.Equal("element", defaultElem.Name.LocalName); Assert.Equal("TestWeaver", defaultElem.Attribute("name")?.Value); Assert.Equal("xs:anyType", defaultElem.Attribute("type")?.Value); Assert.Equal("0", defaultElem.Attribute("minOccurs")?.Value); Assert.Equal("1", defaultElem.Attribute("maxOccurs")?.Value); var elemWithSchema = elements[1]; Assert.Equal("element", elemWithSchema.Name.LocalName); Assert.Equal("WeaverWithSchema", elemWithSchema.Attribute("name")?.Value); Assert.Null(elemWithSchema.Attribute("type")); Assert.Equal("0", elemWithSchema.Attribute("minOccurs")?.Value); Assert.Equal("1", elemWithSchema.Attribute("maxOccurs")?.Value); var elemWithSchemaType = Assert.Single(elemWithSchema.Elements()); Assert.NotNull(elemWithSchemaType); Assert.Equal("complexType", elemWithSchemaType.Name.LocalName); var elemWithSchemaTypeAttr = Assert.Single(elemWithSchemaType.Elements()); Assert.NotNull(elemWithSchemaTypeAttr); Assert.Equal("attribute", elemWithSchemaTypeAttr.Name.LocalName); Assert.Equal("TestAttribute", elemWithSchemaTypeAttr.Attribute("name")?.Value); }