BENBUN Coder
BENBUN Coder

Reputation: 4881

Assembly name from MSBUILD

I am developing an app that reads a MSBUILD file ( *.csproj ) to pull out various bits of information. A previous question on here revealed that I can get the resource files being used in the following manner

        Project project = new Project();
        project.Load(fullPathName);

        var embeddedResources =
            from grp in project.ItemGroups.Cast<BuildItemGroup>()
            from item in grp.Cast<BuildItem>()
            where item.Name == "EmbeddedResource"
            select item;

Now I want to get the assembly name for the project. My initial to look in the "BuildProperyGroup" for a "BuildProperty" with "Name = 'AssemblyName"

I fell at the first hurdle

        var test =
            from grp in project.ItemGroups.Cast<BuildProperyGroup>()

fails with an invalid cast.

Any clues as to where I am going wrong..

The solution I ended up with is as follows

        var PropG =
            from pg in project.PropertyGroups.Cast<BuildPropertyGroup>()
            from item in pg.Cast<BuildProperty>()
            where item.Name == "AssemblyName"
            select item.Value.ToString();

Upvotes: 1

Views: 1468

Answers (1)

user197015
user197015

Reputation:

ItemsGroups are for collections of files, generally (such as all the .cs files in the Compile group). It sounds like you want to be poking around in the project's PropertyGroups collection.

Upvotes: 1

Related Questions