Sync file version with assembly version

B

Bob Altman

Hi all,

I have a C++/CLI project (VS 2005) that produces a DLL that exports C bindings.
Internally, this DLL contains routines compiled with /clr.

I notice that my DLL doesn't have a version resource. I assume that, unlike C#
and VB, C++ doesn't automatically generate a version resource. Is there any way
to make this happen? In particular, I don't want to have to manually update the
file version in the version resource to keep it in sync with the AssemblyVersion
attribute.

TIA - Bob
 
C

Charles Wang[MSFT]

Hi Bob,
You can simply add a version resource in your C++/CLI project. Please refer
to the following steps:
In Solution Explorer, expand Resource Files, double click app.rc, right
click your app.rc folder and click Add Resource..., select Version and
click New.
Then you can change the version number.

Hope this helps. Please feel free to let me know if you have any other
questions or concerns. Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
===========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
===========================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for
non-urgent issues where an initial response from the community
or a Microsoft Support Engineer within 1 business day is acceptable.
Please note that each follow up response may take approximately
2 business days as the support professional working with you may
need further investigation to reach the most efficient resolution.
The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by
contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
============================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 
B

Bob Altman

No, I'm not asking how to create a version resource. I'm asking if there is
some way to automatically synchronize the file version in the version
resource with the assembly version, which is specified by the
AssemblyVersion attribute. In other .Net languages (VB and C#), you don't
deal directly with the version resource. The compiler creates a version
resource for you, using assembly attributes to fill in the various resource
values (file version, description, copyright, etc.). As near as I can tell,
in C++ I need to maintain these values in two places (the version resource
and AssemblyInfo.cpp), and I need to manually ensure that the values are the
same in both places.

Let me ask the question a little bit differently: I have a bunch of
projects (most in VB, some in C++) that I build at the same time. When I
build them, I want them all to have the same assembly and file version
strings. I have a string constant in one of my assemblies, defined (in VB)
as:

Public Class Version
Public Const AssemblyVersion = "1.2.3.4"
End Class

In all of my projects (both VB and C++) I use that constant to set the
assembly version. In C++, my AssemblyInfo.cpp contains something like this:

[AssemblyVersion(MyNamespace::Version::AssemblyVersion)]

In VB, that's all I need to do, and the resultant executable gets a version
resource with the file version equal to the assembly version. But in C++ I
apparently need to manually create an edit a version resource. But it's not
practical for me to manually update the version resource when the assembly
version changes. Often as not I'll make a change to some other project and
bump the assembly versions as a result. In that scenario, I never even
touch the C++ project, much less fiddle with its version resource.
 
B

Ben Voigt [C++ MVP]

Bob Altman said:
No, I'm not asking how to create a version resource. I'm asking if there
is some way to automatically synchronize the file version in the version
resource with the assembly version, which is specified by the
AssemblyVersion attribute. In other .Net languages (VB and C#), you don't
deal directly with the version resource. The compiler creates a version
resource for you, using assembly attributes to fill in the various
resource values (file version, description, copyright, etc.). As near as
I can tell, in C++ I need to maintain these values in two places (the
version resource and AssemblyInfo.cpp), and I need to manually ensure that
the values are the same in both places.

You could probably use a #define to accomplish this.
Let me ask the question a little bit differently: I have a bunch of
projects (most in VB, some in C++) that I build at the same time. When I
build them, I want them all to have the same assembly and file version
strings. I have a string constant in one of my assemblies, defined (in
VB) as:

Public Class Version
Public Const AssemblyVersion = "1.2.3.4"
End Class

In all of my projects (both VB and C++) I use that constant to set the
assembly version. In C++, my AssemblyInfo.cpp contains something like
this:

[AssemblyVersion(MyNamespace::Version::AssemblyVersion)]

In VB, that's all I need to do, and the resultant executable gets a
version resource with the file version equal to the assembly version. But
in C++ I apparently need to manually create an edit a version resource.
But it's not practical for me to manually update the version resource when
the assembly version changes. Often as not I'll make a change to some
other project and bump the assembly versions as a result. In that
scenario, I never even touch the C++ project, much less fiddle with its
version resource.

If you need the version from some other assembly, I guess you'd need to
define a pre-build step that runs a simple tool that uses reflection to
retrieve the value, and then writes a file which you'd #include in your main
..rc file.
 
B

Bob Altman

As near as I can tell, in C++ I need to maintain these values in two places
You could probably use a #define to accomplish this.

Thanks. That give me a way to tie it all together. I can create a public
Version.h file that everyone will use to get the current assembly version.
Version.h just contains:

#define ASSY_VERSION 1.2.3.4

I can eliminate the existing Version class (authored in VB) and replace it with
an equivalent class authored in C++. That class would set the AssemblyVersion
constant equal to the ASSY_VERSION symbol. All of my assemblies (whether VB,
C#, or C++) would continue to reference Version.AssemblyVersion in their
repsective AssemblyInfo.xxx files. That's the end of it for VB and C#, because
they will also generate a version resource for me. But my C++ assmemblies need
one more thing. They need to #include Version.h and use ASSY_VERSION in the .rc
file to give a value to the File Version string. (I've never fiddled with an
..rc file in this manner, but I assume it'll be obvious once I look into it.)
 
C

Charles Wang [MSFT]

Yes, it is a good idea to do so. If you have any other questions or
concerns, please feel free to let us know.

Have a nice day!

Best regards,
Charles Wang
Microsoft Online Community Support
=========================================================
Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the
support we provide to you. Please feel free to let my manager
know what you think of the level of service provided. You can
send feedback directly to my manager at: (e-mail address removed).
=========================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
=========================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top