tlbimp2 setting file version?

Apr 9, 2010 at 2:10 PM

Is there a reason that tlbimp2 is cannot set the file version to a different value to the assembly version of the generated interop assembly?

We have a situation where we need to re-build our interop but keep the assembly version the same (to keep compatibility with other assemblies which are using un-changed interfaces).  unfortunately, msi patches don't seem to update the file as it relies on the file version to determine if the file should be patched... i can change the code of tlbimp2 to do set this, however i was wondering if there is a reason that this version cannot currently be set?


Feb 8, 2011 at 1:04 PM

I would also like this for the reasons outlined above - it makes it very hard to patch these dlls without the ability to set the file version. At the moment we use tlbimp, then our own custom tool for updating the file version, and then we have to resign the dll again, it's a bit of a laborious process. In lieu of this not being a feature in tlbimp2, has anyone already made the modification to allow this? Perhaps you could share the code to prevent us repeating your work?


Feb 8, 2011 at 4:03 PM

these were simple changes to make.

we added the m_strFileVersion member to the TlbImpOptions class, just implemented it to use the same File Version number from the source file:


We made modifications to the ParseArguments function in tlbimp.cs:

         // if the fileversion wasn't given, use the version number of the input file

         if (Options.m_strFileVersion == null)
            // get the fileversion
            FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(Options.m_strTypeLibName);
            Options.m_strFileVersion = versionInfo.FileVersion;
We also modified the DoImport function in tlbimpcode.cs to pass the file version string, and generate the new attribute:
        if (!String.IsNullOrEmpty(strFileVersion))
           CustomAttributeBuilder wb = new CustomAttributeBuilder(typeof(System.Reflection.AssemblyFileVersionAttribute).GetConstructor(new Type[] { typeof(string) }), new object[] { strFileVersion });
the same could be done for the product number, and i guess you could implement it to accept a value on the command line. this was beyond what we needed to do, so we didn't!