tags:

views:

459

answers:

1

I want to reference a COM DLL in a .NET project, but I also want to make sure that the interop DLL created will have the correct version (so that patches will know when the DLL must be changed).

If I use TlbImp I can specify the required version with the /asmversion flag but when I add it directly from VisualStudio it gets a version that has nothing to do with the original COM DLL's version.

I tried changing the version in the vcproj file

<ItemGroup>
    <COMReference Include="MYDLLLib">
        <Guid>{459F8813-D74D-DEAD-BEEF-00CAFEBABEA5}</Guid>
        <!-- I changed this -->
        <VersionMajor>1</VersionMajor> 
        <!-- This too -->   
        <VersionMinor>0</VersionMinor> 
        <Lcid>0</Lcid>
        <WrapperTool>tlbimp</WrapperTool>
        <Isolated>False</Isolated>
    </COMReference>
</ItemGroup>

But then the project failed to build with the following error:

error CS0246: The type or namespace name 'MYDLLLib' could not be found (are you missing a using directive or an assembly reference?)

Is there any way to get this done without creating all my COM references with TlbImp in advance?

If the answer is yes is there a way to specify a build number in addition to the major an minor versions? (e.g 1.2.42.0)

Thanks, Motti.

+1  A: 

The Guid refers to the Guid for the TypeLib not the DLL directly. The version numbers refer to the TypeLib's version not the DLLs.

The version number will come from your idl file, and I believe it only supports a major and minor version and not a build version. Is this version changing when you modify the typelib?

The version numbers will appear in the registry under: HKEY_CLASSES_ROOT\Typelib{typelib uuid}\Major.Minor

If the minor version is set to 0 then I believe it will import the 'latest' version that matches the major version, but the major version must be set to something.

Rob Walker