Registering COM referenced DLLs on a build server

前端 未结 4 1834
不思量自难忘°
不思量自难忘° 2020-12-14 02:53

We\'re developing a C# application that references a few COM libraries (AutoIT for example).

I am including all referenced components under source control, in a 3rd

相关标签:
4条回答
  • 2020-12-14 03:36

    I'm not sure, if there's any task in MSBuild, to call regsvr32, but REgisterAssembly is calling regasm.exe - that is - registering .NET components for COM interop.

    I am sure, that just calling regsvr32 manually would be the fastest way to achieve the desired result.

    Another thing is - what will happen if the COM DLLs are already registered by the previous build and you'll run your build script again? (I don't really know how the regsvr32 will react, just a thought here)

    0 讨论(0)
  • 2020-12-14 03:44

    For my original answer to a similar question see: TFS Build server and COM references - does this work?

    A better option for build servers may be to use the COMFileReference item in your project file instead of COMReference. An example would look like this:

    <ItemGroup>
       <COMFileReference Include="MyComLibrary.dll">
         <EmbedInteropTypes>True</EmbedInteropTypes>
       </COMFileReference>
    </ItemGroup>
    

    The COM dll doesn't need to be registered on the machine for this to work.

    Each COMFileReference item can also have a WrapperTool attribute but the default seems to work fine. The EmbedInteropTypes attribute is not documented as being applicable to COMFileReference, but it seems to work as intended.

    See https://docs.microsoft.com/en-ca/visualstudio/msbuild/common-msbuild-project-items#comfilereference for a little more detail. This MSBuild item has been available since .NET 3.5.

    0 讨论(0)
  • 2020-12-14 03:46

    1) Try to reference the COM libraries to your csproj as references - if you haven't done so.

    2) Try to append to your csproj file:

    <Project ... >
        ...
        <Target Name="BeforeBuild">
            <Exec Command="regsvr32.exe yourComponent.dll" />
        </Target>
    </Project>
    

    PS: if you are using some sort of build server software you should not modify the csproj but the script used by the build at the server.

    0 讨论(0)
  • 2020-12-14 03:48

    You don't register COM servers on a build server. That's only required when you actually want to run the compiled code. What you need is the type libraries for the COM servers so you can get the interop assemblies. Which you create with Tlbimp.exe.

    Whether you want to run Tlbimp on the build server or up front on a dev machine depends a great deal on how you deploy these COM servers. Keeping a copy of the COM executables and .tlb files very close to your interop libraries is a good idea. In other words, check them in. The installer can now retrieve a known-good version of the COM server as well.

    0 讨论(0)
提交回复
热议问题