簡體   English   中英

獲取列出的引用的路徑csproj文件

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

我知道一個csproj文件的路徑(在其他100個其他項目文件中)。 我想檢查“ bin”中存在哪些引用,以便將這些引用的“本地復制”值設置為false。 為此,我需要獲取引用的路徑(或者是否有更好的方法?)。 如何獲取csproj文件中列出的引用的路徑?

提前致謝!!

請嘗試以下操作:

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方法。 我沒有對此進行全面測試,但我希望它能顯示正確的方式。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM