得到的参考路径上市的csproj文件 [英] get paths of the references listed a csproj file

查看:160
本文介绍了得到的参考路径上市的csproj文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道的csproj文件的路径(其他项目文件100S之间)。 我想检查哪些引用是present在仓,让那些引用的复制本地值设置为false。对于这一点,我需要引用的路径(或者是有没有更好的办法?)。 我怎样才能在的csproj文件中列出的参考的路径?

I know the path of a csproj file (among 100s of other project files). I want to check which references are present in the "bin", so that the "copy local" value of those references be set to 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?

在此先感谢!

推荐答案

请尝试以下操作:

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

实施CheckLocation方法,因为你需要。我不完全测试,但我希望它显示了正确的道路。

Implement CheckLocation method as you need. I don't fully test this, but I hope it shows right way.

这篇关于得到的参考路径上市的csproj文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆