public void Write_Version_WrittenAsAttribute()
        {
            var p = new MSBuildProject();

            p.LoadXml("<Project ToolsVersion=\"15.0\" />");
            ProjectPackageReference.AddKnownItemAttributes(p);

            var item             = p.AddNewItem("PackageReference", "Test");
            var packageReference = new TestableProjectPackageReference("Test", "1.2.3");

            packageReference.CallWrite(item);

            string xml = p.SaveToString();
            var    doc = new XmlDocument();

            doc.LoadXml(xml);

            var itemGroupElement        = (XmlElement)doc.DocumentElement.ChildNodes[0];
            var packageReferenceElement = (XmlElement)itemGroupElement.ChildNodes[0];

            Assert.AreEqual("PackageReference", packageReferenceElement.Name);
            Assert.AreEqual("1.2.3", packageReferenceElement.GetAttribute("Version"));
            Assert.AreEqual(0, packageReferenceElement.ChildNodes.Count);
            Assert.IsTrue(packageReferenceElement.IsEmpty);
        }
Ejemplo n.º 2
0
 public void AddKnownItemAttributes(MSBuildProject project)
 {
     if (HasSdk)
     {
         ProjectPackageReference.AddKnownItemAttributes(project);
     }
 }