Re: Adding and editing assembly info.

150 views
Skip to first unread message

Simon

unread,
Jul 28, 2012, 11:05:42 PM7/28/12
to mono-...@googlegroups.com
wonder if you need clear out existing attributes first?

On Saturday, 28 July 2012 08:49:40 UTC+10, Banksy wrote:
I had my friend write this function up, and it's only working partly.

Public Shared Sub AttachAttributes(ByRef asmDef As AssemblyDefinition, ByVal name As String, ByVal version As Version, ByVal title As String, ByVal description As String, ByVal configuration As String, _
 ByVal company As String, ByVal product As String, ByVal copyright As String, ByVal trademark As String, ByVal culture As String, ByVal Visible As Boolean)
        Dim mRefTitle = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyTitleAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefDesc = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyDescriptionAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefConfig = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyConfigurationAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefCompany = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyCompanyAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefProduct = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyProductAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefCopyright = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyCopyrightAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefTrademark = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyTrademarkAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefCulture = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyCultureAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefVisible = New CustomAttribute(asmDef.MainModule.Import(GetType(ComVisibleAttribute).GetConstructor(New Type() {GetType(Boolean)})))
        Dim mRefGuid = New CustomAttribute(asmDef.MainModule.Import(GetType(GuidAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefVersion = New CustomAttribute(asmDef.MainModule.Import(GetType(AssemblyFileVersionAttribute).GetConstructor(New Type() {GetType(String)})))
        Dim mRefDebug = New CustomAttribute(asmDef.MainModule.Import(GetType(DebuggableAttribute).GetConstructor(New Type() {GetType(DebuggableAttribute.DebuggingModes)})))

        mRefTitle.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyTitleAttribute)), If(title, "")))
        mRefDesc.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyDescriptionAttribute)), If(description, "")))
        mRefConfig.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyConfigurationAttribute)), If(configuration, "")))
        mRefCompany.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyCompanyAttribute)), If(company, "")))
        mRefProduct.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyProductAttribute)), If(product, "")))
        mRefCopyright.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyCopyrightAttribute)), If(copyright, "")))
        mRefTrademark.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyTrademarkAttribute)), If(trademark, "")))
        mRefCulture.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyCultureAttribute)), If(culture, "")))
        mRefVisible.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(ComVisibleAttribute)), False))
        mRefGuid.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(GuidAttribute)), Guid.NewGuid().ToString()))
        mRefVersion.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(AssemblyCultureAttribute)), If(version.ToString, "")))
        mRefDebug.ConstructorArguments.Add(New CustomAttributeArgument(asmDef.MainModule.Import(GetType(DebuggableAttribute)), (DebuggableAttribute.DebuggingModes.DisableOptimizations Or (DebuggableAttribute.DebuggingModes.EnableEditAndContinue Or (DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints Or DebuggableAttribute.DebuggingModes.Default)))))



        asmDef.CustomAttributes.Add(mRefTitle)
        asmDef.CustomAttributes.Add(mRefDesc)
        asmDef.CustomAttributes.Add(mRefConfig)
        asmDef.CustomAttributes.Add(mRefCompany)
        asmDef.CustomAttributes.Add(mRefProduct)
        asmDef.CustomAttributes.Add(mRefCopyright)
        asmDef.CustomAttributes.Add(mRefTrademark)
        asmDef.CustomAttributes.Add(mRefCulture)
        asmDef.CustomAttributes.Add(mRefVisible)
        asmDef.CustomAttributes.Add(mRefGuid)
        asmDef.CustomAttributes.Add(mRefVersion)
        asmDef.CustomAttributes.Add(mRefDebug)


        asmDef.Name = New AssemblyNameDefinition(name, version)
    End Sub

It adds to the assembly fine, as I can see it in reflector, but windows does not recognize it.



Jb Evain

unread,
Jul 29, 2012, 2:54:44 AM7/29/12
to mono-...@googlegroups.com
Hey,

On Jul 28, 2012, at 12:49 AM, Banksy wrote:
> It adds to the assembly fine, as I can see it in reflector, but windows does not recognize it.

Windows shows the Win32 properties of the assembly.
Cecil currently doesn't allow you to edit those. This is bug https://github.com/jbevain/cecil/issues/3

Jb

Reply all
Reply to author
Forward
0 new messages