When you install iTunes, the iTunes.exe
application gets registered as COM server (likely with regsvr32.exe
). It will have a small key group in the Computer\HKEY_CLASSES_ROOT
registry section with the GUID of: 9E93C96F-CF0D-43F6-8BA8-B807A3370712
To reference this COM server, in your C# program, you would add the following COMReference property to your csproj file:
<ItemGroup>
<COMReference Include="iTunesLib">
<Guid>{9E93C96F-CF0D-43F6-8BA8-B807A3370712}</Guid>
<VersionMajor>1</VersionMajor>
<VersionMinor>13</VersionMinor>
<Lcid>0</Lcid>
<WrapperTool>tlbimp</WrapperTool>
<Isolated>False</Isolated>
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMReference>
</ItemGroup>
This tells the build system to use the tlbimp
program to create a managed type library for the COM server that your managed module can reference. The tlbimp
program will create a module called Interop.iTunesLib.dll
and the build system will place a copy of this in both your bin
and obj
directories.
If you don't have iTunes installed, then there will be no COM server registered and your build will fail.
However, if you managed (no pun intended) to save a copy of Interop.iTunesLib.dll
, then without having iTunes installed, you can reference it like so:
<ItemGroup>
<COMFileReference Include="Interop.iTunesLib.dll">
<EmbedInteropTypes>True</EmbedInteropTypes>
</COMFileReference>
</ItemGroup>
In the include attribute
, you can / may need to add a path component, as well. There are probably a few versions of Interop.iTunesLib.dll
floating around the internet likely from different versions of iTunes.exe
. Best to get this file from a trusted source.
While using the COMFileReference
property will allow the project to build properly, attempting to execute the iTunes related functionality will crash the program, because that functionality is located in iTunes.exe
, which in this situation, is not present.
In my project, I get around this by first checking to see iTunes.exe
exists (\Program Files\iTunes\iTunes.exe
), before attempting to execute any of the iTunes functionality.