We are using tlbimp to generate interop assemblies. We would like to stamp the interop assemblies with both a File Version and an Assembly Version. However, the /asmversion option on tlbimp seems to be setting both of these to the same value.
Does anyone know how to set up different File and Assembly versions on an interop assembly using tlbimp?
Remarks. Tlbimp.exe performs conversions on an entire type library at one time. You cannot use the tool to generate type information for a subset of the types defined within a single type library. It is often useful or necessary to be able to assign strong names to assemblies.
There are two ways to generate a primary interop assembly: Using the Type Library Importer (Tlbimp.exe) provided by the Windows SDK. The most straightforward way to produce primary interop assemblies is to use the Tlbimp.exe (Type Library Importer).
Navigate to C:\Program Files\Microsoft SDKs\Windows\vx. x\Bin in which the earlier . NET Framework version of TlbImp.exe is installed.
In the end we found a couple of links about a project called tlbimp2 on codeplex, and compiled our own modified version of tlbimp2:
I took the code from the tlbimp project of 2. and modified it along the lines of 1. There were a couple of problems we had to work around:
In TlbImp.cs I had explicitly to assemble the file version number from the result of FileVersionInfo.GetVersionInfo, since the FileVersion property was empty:
if (Options.m_strFileVersion == null)
{
// get the fileversion
var versionInfo =
FileVersionInfo.GetVersionInfo(Options.m_strTypeLibName);
Options.m_strFileVersion =
versionInfo.FileMajorPart
+ "." + versionInfo.FileMinorPart
+ "." + versionInfo.FileBuildPart
+ "." + versionInfo.FilePrivatePart;
}
In tlbimpcode.cs I had to switch:
AsmBldr.DefineVersionInfoResource(
strProduct,
strProductVersion,
strCompany,
strCopyright,
strTrademark);
to:
AsmBldr.DefineVersionInfoResource();
Or the custom resources would not be used.
Hope this helps someone else with the same problem.
It seems pretty unlikely you'll be able to do this using only tlbimp. You'll probably have to mess with the IL. You'll need to add something along the lines of:
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 0B 33 2E 35 2E 35 30 32 31 31 2E 31 00 00 ) // ...3.5.50211.1..
The format is 01 NN NN SS1 ... SSN 00 00
.
NN NN is the length of the string, SS comprises the ascii bytes representing the version.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With