Not sure why I cannot access ProjectElement.ElementName

pemby

New member
Joined
Jul 27, 2021
Messages
2
Programming Experience
5-10
Hi, I am attempting to use Microsoft.Build.Construction to parse a few .csproj files.
I am looping over a few csproj files to build a report. I am running into the following error

Not sure why I cannot access ProjectElement.ElementName

// ComplieTime ERROR:'ProjectElement' does not contain a definition for 'ElementName'
//and no accessible extension method 'Name' accepting a first argument of type
//'ProjectElement' could be found (are you missing a using directive or an assembly reference?)

Here is a code snippet that reproduces the error.

C#:
using (IEnumerator<ProjectItemGroupElement> itemEnums = ProjRootEl.ItemGroups.GetEnumerator())
{
    while (itemEnums.MoveNext())
    {
        ProjectItemGroupElement currItem = itemEnums.Current;
        IEnumerator<ProjectItemElement> currItemEnums = currItem.Items.GetEnumerator();

        using (currItemEnums)
        {
            while (currItemEnums.MoveNext())
            ProjectItemElement innerItems = currItemEnums.Current;

            bool someCondition = true;

            if (someCondition)
            {
                foreach(ProjectElement child in innerItems.Children)
                {
                    // ComplieTime ERROR:'ProjectElement' does not contain a definition for 'ElementName'
                    //and no accessible extension method 'Name' accepting a first argument of type
                    //'ProjectElement' could be found (are you missing a using directive or an assembly reference?)

                    string buffer = child.ElementName;                      
                }
            }
        }
    }
}
 
Is your code being compiled targeting .NET Core or a .NET Framework? If .NET Core, did you use NuGet to get the appropriate MSBuild packages? If .NET Framework, are you referencing the correct version of the MSBuild assemblies?
 
Back
Top Bottom