Frage

some times I will have to load up to 60 winforms or class library projects into a solution.. and change the output path and reference path for each of them..

so I wrote a wpf application for the same

private void Button_Click(object sender, RoutedEventArgs e)
{
    var path = txtRootPath.Text;
    var projFiles = System.IO.Directory.GetFiles(path, "*.csproj", SearchOption.AllDirectories);

    foreach (var item in projFiles)
    {
        var xDoc = XDocument.Load(item);
        var outputNodes = xDoc.Root.Descendants("OutputPath");
        foreach (var outoutNode in outputNodes)
        {
            //this part is never hit..
            outoutNode.Value = txtOutputPath.Text;
        }

        //similarly for referencePath
    }

    lblResult.Content = string.Format("Files: {0}", projFiles.Count());
}

but outputNodes collection will be empty

could somebody please tell what am I doing wrong here

EDIT:

I figured out that the problem is with xmlns="http://schemas.microsoft.com/developer/msbuild/2003" attribute in Project element..

Solution:

as given in this solution -
Parsing Visual Studio Project File as XML
Linq-to-XML with XDocument namespace issue

War es hilfreich?

Lösung

You have to use the default namespace when referring to "OutputPath" element.

    XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
    var outputNodes = xDoc.Root.Descendants(ns + "OutputPath");
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top