得到的参考路径上市的csproj文件路径、文件、csproj

由网友(疯言疯语)分享简介:我知道的csproj文件的路径(其他项目文件100S之间)。我想检查哪些引用是present在仓,让那些引用的复制本地值设置为false。对于这一点,我需要引用的路径(或者是有没有更好的办法?)。我怎样才能在的csproj文件中列出的参考的路径?I know the path of a csproj file (...

我知道的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.

阅读全文

相关推荐

最新文章