Maintain the correct version for a COM dll referen

2019-08-01 15:08发布

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 Visual Studio 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 and minor versions? (e.g 1.2.42.0)

标签: .net c++ com
1条回答
孤傲高冷的网名
2楼-- · 2019-08-01 15:31

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.

查看更多
登录 后发表回答