Reading C # custom attributes in MSBuild

I have a custom attribute defined in the AssemblyInfo.cs file for a C # assembly and I would like to read the value of that custom attribute during the MSBuild process. I already have a somewhat hacky solution that reads the AssemblyInfo.cs file and gets the attribute value via RegEx, but this has some drawbacks, eg. the attribute is commented out but still matches the RegEx pattern.

I can see there is an AssemblyInfo MSBuild task, but it seems to only support reading non-standard attributes from dlls. Is there a way to extract the value of a custom attribute directly from a dll? I'm also open to any other solutions that are less fragile than parsing the AssemblyInfo.cs file. I would also prefer not to write my own task to do this, because we have no other custom tasks, and creating a custom build of tasks with a single task seems like overkill.

+3


source to share





All Articles