Esempio n. 1
0
        public static string ProjectFile(string xml, string fileName)
        {
            var original = XDocument.Parse(xml.Replace("xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"", string.Empty));
            var root     = new XElement(XName.Get("Project"));
            var isWpf    = IsWpf(original);

            root.SetAttributeValue(XName.Get("Sdk"), isWpf ? "Microsoft.NET.Sdk.WindowsDesktop" : "Microsoft.NET.Sdk");
            foreach (var element in original.Root.Elements())
            {
                var localName = element.Name.LocalName;
                switch (localName)
                {
                case "PropertyGroup":
                {
                    if (PropertyGroup.TryMigrate(element, fileName, isWpf, out var migratedElement))
                    {
                        if (migratedElement != null)
                        {
                            root.Add(migratedElement);
                        }
                    }

                    continue;
                }

                case "ItemGroup":
                {
                    if (ItemGroup.TryMigrate(element, isWpf, out var migratedElement))
                    {
                        if (migratedElement != null)
                        {
                            root.Add(migratedElement);
                        }
                    }

                    continue;
                }

                case "Choose":
                    continue;

                case "Import":
                {
                    if (element.Attribute(XName.Get("Project")) is { } pa)
                    {
                        switch (pa.Value)
                        {
                        case "$(MSBuildExtensionsPath)\\$(MSBuildToolsVersion)\\Microsoft.Common.props":
                        case "$(MSBuildToolsPath)\\Microsoft.CSharp.targets":
                        case "$(VSToolsPath)\\TeamTest\\Microsoft.TestTools.targets":
                            continue;
                        }
                    }

                    break;
                }
                }

                root.Add(element);
            }

            return(new XDocument(root).ToString());