1
votes

I'm trying to add Windows/System32/Shell32.dll DLL to my project. The issue is, it copies the reference to the directory! Since this is a windows file, it shouldn't have to come with me if I were to deploy my application.

I have tried stopping it from copying to the directory, tried looking for how to embed the resource in the application and even added reference paths to System32. It seems so much more challenging than the program just using the local DLL from the system...

What can I do?

1
You should not need to add it as a reference to the project. Just use DllImport Can you explain more what you are trying to do.Scott Chamberlain
@ScottChamberlain I'm creating an updater. Files will be transported in a CAB file to a client machine. There, it will be unpacked and each file will be allocated a destination where it will be used. I'll have a go at DllImport!Daaksin
For system files you do not include the files in your project, you just use them directly.Scott Chamberlain
Don't use [DllImport], this is a COM server. You can't pinvoke COM.Hans Passant

1 Answers

1
votes

Shell32.dll is a COM component. You should not get a copy of it in your project. What you get instead is Interop.Shell32.dll. Which is a .NET assembly, not a copy of Shell32.dll. It contains the COM interface and class declarations, converted from the type library definition inside Shell32.dll to friendly .NET declarations that the CLR knows how to easily handle.

This is an optimization, it avoids having to make the conversion at runtime. Which is expensive, subject to various options (check the MSDN docs for Tlbimp.exe) and may easily fail because there is no general requirement that the type library is also available on the target machine.

You must deploy Interop.Shell32.dll to the target machine, just like you do with any .NET class libraries you'd use.

Do note that this interop library is no longer needed on .NET 4 and VS2010. Which acquired the "Embed Interop Types" feature. In other words, instead of keeping the interop types in a separate assembly, the C# and VB.NET compilers can now embed them in your program. Very highly recommended, just set the option to True in the Properties window view of the Shell32 reference.