Setting/Obtaining Version Info in C++.Net v1.0

Posted on 2004-11-02
Last Modified: 2010-04-24

Is there a reliable way of setting and obtaining file version info in C++.Net v1.0? I can "successfully" set the version of the file by setting the AssemblyVersionAttribute (and AssemblyFileVersionAttribute) in AssemblyInfo.cpp, but the only way I can view this is by opening the file in ILDASM - not by positioning my mouse over the file or in the properties. However, this would be fine, except I cannot get the version progammatically. I've used Application, Form, and FileVersionInfo to no avail. Is there a way to set the version so that you can get the version programmatically in VC++.Net v1.0?

Question by:mpf1748
    LVL 1

    Accepted Solution

    Here's what I'm doing. Note: replace YOURASSEMBLYNAME with your own assembly's name. I've put the message box in here to show what the results are. You must then parse the resulting assembly string to get the Version=x.x.x.x value.

    // You'll need these namespaces
    using namespace System::Reflection; // for Assembly
    using namespace System::Threading; // for Thread

    // t hen in your code, do this

    Assembly * myAssemblies[] = Thread::GetDomain()->GetAssemblies();
    Assembly * myAssembly = 0;
    for (int i = 0; i < myAssemblies->Length; i++)
      if (String::Compare(myAssemblies[i]->GetName()->Name, S"YOURASSEMBLYNAME") == 0)
         myAssembly = myAssemblies[i];
    if (myAssembly != 0)
       MessageBox::Show(myAssembly->ToString(), S"Assembly string");

    // now parse the myAssembly->ToString() to get the Version=x.x.x.x value.

    P.S. if there's a better way, I'd like to know.
    LVL 3

    Author Comment


    Not as easy as I was hoping, but it works. There is Assembly::GetExecutingAssembly() that simply returns the original assembly that is loaded if that's the assembly you want the version from. Although you still have to parse out that Version.

    LVL 3

    Author Comment

    Actually that is the current current assembly, not the original executing assembly.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
    In Easy String Encryption Using CryptoAPI in C++ ( I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now