开发者

TFS Build server and COM references - does this work?

开发者 https://www.devze.com 2023-04-06 04:19 出处:网络
On my Developer PC i have registered the according dll´s and referenced them. (Add reference -> COM)

On my Developer PC i have registered the according dll´s and referenced them. (Add reference -> COM) On the TFS build server this of course causes errors since the references are not regi开发者_StackOverflowstered there and wont be in the future.

What is the best way to circumvent this?


Using tlbimp.exe directly is not necessary. Try replacing any <COMReference> items in the project file with <COMFileReference>. 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://learn.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.


OK, the answer was more easy than one might think. Just use "tlbimp.exe" to create an according intrerop.dll which you include in your project and reference to this dll instead to the COM objects.

You may save the time using tlbimp.exe because Visual Studio creates this dll automatically when you reference a COM object. But it does not upload it to TFS. So finally I just used the automatically created dll and the TFS build Server was happy.

One may find the automatically created Interop dll in: "ProjectFolder\obj\x86\Development"


For anyone who's having trouble with namespace:

tl;dr: use tlbImp /namespace: YOUR_NAMESPACE to give your dll a namespace


This solution worked for Azure Pipeline too. But at first I was having trouble with COMFileReference. When I replaced COMReference with COMFileReference my VS build was failing saying "Namespace can't be found". Finally found the solution here.

I used tlbImp to generate a dll of the COM file using /namespace attribute following this article. Only then you can use the dll in COMFileReference. Here's a bit elaborate example:

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

or

<ItemGroup>
   <COMFileReference Include="..\My\parent\folder\MyComLibrary.dll">
     <EmbedInteropTypes>True</EmbedInteropTypes>
   </COMFileReference>
</ItemGroup>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号