Reputation: 1077
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?
Thanks in advance!!
Upvotes: 1
Views: 1614
Reputation: 7747
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. I don't fully test this, but I hope it shows right way.
Upvotes: 2