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


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?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mpf1748Author Commented:

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.

mpf1748Author Commented:
Actually that is the current current assembly, not the original executing assembly.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual C++.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.