文章出處

  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);
        }

 


文章列表




Avast logo

Avast 防毒軟體已檢查此封電子郵件的病毒。
www.avast.com


arrow
arrow
    全站熱搜
    創作者介紹
    創作者 大師兄 的頭像
    大師兄

    IT工程師數位筆記本

    大師兄 發表在 痞客邦 留言(0) 人氣()