Share via


Modify / Add File Properties of an executable

Question

Friday, April 30, 2010 8:37 AM

Hello Everybody

Can anybody provide me, how to change file properties in an existing executable? It is about the details tab if you right click on a file and choose properties, then go to the details tab and there are several property / value fields, for example "Copyright, Product name etc.". My goal to achieve is to add a author field with a value where i get from an author attribute  via Reflection and then set it. Is it possible with C#? Maybe with Win32 API and DLLIMPORT?

i realy appreciate any hints

Best Regards,

Confederatio

 

All replies (8)

Friday, April 30, 2010 2:06 PM ✅Answered

Okay, thanks for your help i investigate about the use of /win32res option and if i can change the properties.


Friday, April 30, 2010 11:17 AM

You can do this, in following method.

 

1.Modifying AssemblyInfo.cs file under solution explorer. In solution explorer you will find a folder (greyed) Properties, expand that folder you will find AssemblyInfo.cs file. Modify it as per your requirement.

 

2.Go to Project Properties, by right clocking project on Solution explorer. In 'Application' Tab, you will find a Button AssemblyInfo. Click on it, you will find all necessary info.

 

hope this helps.

Thanks Mike Please mark as answer if it is useful


Friday, April 30, 2010 11:40 AM

Hi Mike

Thank you for your answer, but i want to use a custom field like this one:

// Allgemeine Informationen über eine Assembly werden über die folgenden 
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("My App")] // this become to "File Description"
[assembly: AssemblyDescription("Some app")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company")]
[assembly: AssemblyProduct("MyApp")] // become to "Product name"
[assembly: AssemblyCopyright("Copyright © Company Name")] // Become to "Copyright"
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("de-CH")] // become to "Language"
[assembly: AssemblyAuthor("Confederatio Helvetica")] // this is my custom attribute and i want to see that as "Author"

you see at the last line the attribute i want to use and which one i want to see at the file property detail  tab. Do you have any other suggestions how to achieve this?

Thanks anyway,

Confederatio


Friday, April 30, 2010 12:52 PM

It won't work just like that, you need to derive a class from System.Attribute to ad your own attributes.

See the example below. Add simillar code to AssemblyInfo.cs class.

public enum Animal
  {
    // Pets.
    Dog = 1,
    Cat,
    Bird,
  }

  public class AnimalTypeAttribute : System.Attribute 
  {
    // The constructor is called when the attribute is set.
    public AnimalTypeAttribute(Animal pet)
    {
      thePet = pet;
    }

    // Keep a variable internally ...
    protected Animal thePet;

    // .. and show a copy to the outside world.
    public Animal Pet
    {
      get { return thePet; }
      set { thePet = value; }
    }
  }

Hope this will fix your requirement.

Thanks Mike Please mark as answer if it is useful


Friday, April 30, 2010 1:03 PM

Hi again

 

I have already an attribute class see here

 

 [AttributeUsage(AttributeTargets.Assembly)]
  class AssemblyAuthorAttribute : Attribute
  {
    private string _author;

    public string Author 
    {
      get { return _author; }
      set { _author = value; }
    }


    public AssemblyAuthorAttribute(string author)
    {
      _author = author;
    }

  }

 

but how to set this as a file property like "Product name" or "Language"? I mean the properties in the file explorer, when you right click on the file and then on the details tab. Sorry for my english it's a foreign language for me.


Friday, April 30, 2010 1:11 PM

You can add any info to file propeties, using these attributes.

// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("My App")] // this become to "File Description"
[assembly: AssemblyDescription("Some app")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Company")]
[assembly: AssemblyProduct("MyApp")] // become to "Product name"
[assembly: AssemblyCopyright("Copyright © Company Name")] // Become to "Copyright"
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("de-CH")] // become to "Language"
[assembly: AssemblyAuthorAttribute("Confederatio Helvetica")] // this is my custom attribute and i want to see that as "Author"

Look at the class def. I said, System.Attribute not just Attribute. And class should accessibile from assembyinfo.cs. So i made it public

public class AssemblyAuthorAttribute : System.Attribute
{
    private string _author;

    public string Author
    {
        get { return _author; }
        set { _author = value; }
    }

    public AssemblyAuthorAttribute(string author)
    {
        _author = author;
    }

}

Thanks Mike Please mark as answer if it is useful


Friday, April 30, 2010 1:33 PM

Sorry but it doesn't work see at my picture to see what i mean:

 

Here are a picture

 

there should be a way to put the vaule into the pile properties, or not?

 


Friday, April 30, 2010 1:48 PM

  i'm sorry about that  , i cannot see the image.

File Attributes of assembly can be overridden using the /win32res compiler option to specify your own Win32 resource file.Those information’s are critical for Assembly versioning

 

 

Thanks Mike Mark best answers as Answer