【发布时间】:2016-04-12 13:38:34
【问题描述】:
我需要强制我的所有项目使用存储在公共位置的dll's。我首先重构现有项目以指向我喜欢的dll's 源文件夹。所以我决定尝试一种编程方式来更改这些引用。
我读到dll 引用如下:
XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
XDocument projDefinition = XDocument.Load(filePath);
IEnumerable<string> references = projDefinition
.Element(msbuild + "Project")
.Elements(msbuild + "ItemGroup")
.Elements(msbuild + "Reference")
.Elements(msbuild + "HintPath")
.Select(refElem => refElem.Value);
下一步是根据引用名称更改引用HintPath。我计划创建一个引用字典,然后遍历它们以更新每个项目文件。
但是,我找不到任何基于Reference 内部csproj 的可靠方法来阅读和更改HintPath。
【问题讨论】:
-
查看类似问题的答案:stackoverflow.com/a/35233082/33082
-
答案准确地显示了我所做的,加上它将读取到的引用转储到 txt。不是很有用。我需要的是能够根据 Reference 修改 HintPath。
标签: c# reference msbuild csproj projects-and-solutions