public ActionResult Index()
        {

            XDocument doc = XDocument.Load(@"G:\users\kim.gao\documents\visual studio 2015\Projects\test\test\test.csproj");
            ContainFileToCsproj(@"T4\AccountViewModels.cs", "", "", doc);
            doc.Save(@"G:\users\kim.gao\documents\visual studio 2015\Projects\test\test\test.csproj");
            return View();
        }
        public static void ContainFileToCsproj(string fileName, string solutionDir, string csprojName, XDocument doc)
        {
            string path = @"G:\users\kim.gao\documents\visual studio 2015\Projects\test\test\test.csproj";
            XElement root = doc.Root;
            string xmlns = "{" + root.Attribute("xmlns").Value + "}";
            IEnumerable<XElement> compileList = root.Elements(xmlns + "ItemGroup").Elements(xmlns + "Compile");
            XElement itemGroup = compileList.FirstOrDefault().Parent;
            if (compileList.Where(u => u.Attribute("Include").Value == fileName).Count() > 0)
            {
                compileList.Where(u => u.Attribute("Include").Value == fileName).Remove();
            }

            XElement compile = new XElement(xmlns + "Compile");
            compile.SetAttributeValue("Include", fileName);
            itemGroup.AddFirst(compile);
        }

 

相关文章:

  • 2021-11-13
  • 2021-11-01
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-17
猜你喜欢
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案