为了修改 mvc 项目的 csproject 文件,我使用了如下代码片段,但未能实现。请你帮助我好吗?
var newReference = @"System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL";
var profiles = Directory.GetFiles(path, "*.csproj", SearchOption.AllDirectories);
foreach (var profile in profiles)
{
var doc = XDocument.Load(profile);
var parentElement = doc.Descendants("ItemGroup").FirstOrDefault();
if (parentElement != null)
{
var newNode = new XElement("Reference", new XAttribute("Include", newReference));
parentElement.Add(newNode);
}
doc.Save(profile);
}