简体   繁体   English

获取列出的引用的路径csproj文件

[英]get paths of the references listed a csproj file

I know the path of a csproj file (among 100s of other project files). 我知道一个csproj文件的路径(在其他100个其他项目文件中)。 I want to check which references are present in the "bin", so that the "copy local" value of those references be set to false. 我想检查“ bin”中存在哪些引用,以便将这些引用的“本地复制”值设置为false。 For this, I need to get the paths of the references (or is there a better way??). 为此,我需要获取引用的路径(或者是否有更好的方法?)。 How can I get the Paths of the references listed in the csproj file? 如何获取csproj文件中列出的引用的路径?

Thanks in advance!! 提前致谢!!

Try following: 请尝试以下操作:

var project = ProjectRootElement.Open(fileName);
var referenceElements = project.Items
    .Where(x => x.ItemType.Equals("Reference"))
    .Where(x => x.HasMetadata && x.Metadata.Any(m => m.Name.Equals("HintPath") && CheckLocation(m.Value)));

    foreach (var projectItemElement in referenceElements) 
    {
        var copyLocalElement = projectItemElement.Metadata.FirstOrDefault(x => x.Name.Equals("CopyLocal"));
        if (copyLocalElement != null) 
        {
            copyLocalElement.Value = "false";
            continue;
        }
        projectItemElement.AddMetadata("CopyLocal", "false");
    }

Implement CheckLocation method as you need. 根据需要实现CheckLocation方法。 I don't fully test this, but I hope it shows right way. 我没有对此进行全面测试,但我希望它能显示正确的方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM