0

I've used the answers to Using the same modules in multiple projects to migrate some shared code to a .dll file for use in new projects. The shared code has a few methods, all of which use two NuGet packages some of which use 'Microsoft.Office.Interop' to be able to also work with outlook messages.

I've created a new project as a test bed for the new .dll file and think I've probably done something "the long way", as I've had to manually add the nuget packages to this new project to get it working, and when I use an overloaded method that can either accept a string or an outlook object (as below) I get the error Cannot find the interop type that matches the embedded type 'Microsoft.Office.Interop.Outlook.MailItem'. Are you missing an assembly reference?

 Public Sub UpdateNextDesk(comment As String)
   'code
 end sub
 Sub UpdateNextDesk(ByRef withMail As Outlook.MailItem)
   'different code
 end sub

Is there a way of compiling the dll so that it automatically adds the right references to projects that include it? or conversely a way of including the dll and all the references it uses? If I create more overloads for my methods that accept even more types of object, will I need to create a list somewhere of all the different references I need to add to new projects?

Martin KS
  • 481
  • 7
  • 26
  • I don't know if it makes a difference, but I should probably have said I'm using Visual Studio Community 2017 – Martin KS Sep 04 '18 at 10:22
  • Demanding that the client programmer uses the same interop assembly as you did is fraught with DLL Hell trouble. The compiler gets antsy because it cannot determine which overload is the correct one when it doesn't know anything about Outlook.MailItem. Easily avoided by giving that overload a different name, like UpdateNextDeskFromMailItem(). If the client programmer wants to use it then he won't forget to add the interop assembly since he needs to cough up a MailItem. – Hans Passant Sep 04 '18 at 11:03
  • OK, and what about the NuGet packages? Nothing will work without a version of them. Even a message "the library will not work without x" would be a start. – Martin KS Sep 04 '18 at 11:06
  • Plan B: when I compile the dll it also compiles and exports the relevant parts of the nuget packages - a couple of executable files. Could I have them automatically used with the dll in some way? – Martin KS Sep 04 '18 at 11:40

0 Answers0