Skip to content

Get AssemblyRef versions #11

@gitgitwhat

Description

@gitgitwhat

Here's code for 'dotnetfile.py' to return the assembly name along with the version. Use as is or modify as need but please just add something like this. Thanks.

# Table 35
@metatable
class AssemblyRef:

    ....

    def get_assemblyref_names_with_versions(self, deduplicate: bool = False) -> Dict:
        """
        Get a list of referenced assembly names and their versions
        """
        result = {}

        for table_row in self.dotnetpe.metadata_tables_lookup['AssemblyRef'].table_rows:
            string_address = table_row.string_stream_references['Name']
            if string_address:
                assembly_name = self.dotnetpe.get_string(string_address)
                if deduplicate:
                    if assembly_name in result:
                        continue
                vs = Struct.AssemblyInfo(table_row.MajorVersion.value, table_row.MinorVersion.value, table_row.BuildNumber.value, table_row.RevisionNumber.value)
                result[assembly_name] = f'{vs.MajorVersion}.{vs.MinorVersion}.{vs.BuildNumber}.{vs.RevisionNumber}'

        return result

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions