# Why is Microsoft.SharePoint.Search.dll copied in my project?

When working on a VS project that involves referencing Microsoft.SharePoint.dll, building the project causes Microsoft.SharePoint.Search.dll to be copied to my bin folder. Why is this? Okay, maybe it's just a bug, but I want to know the mechanism. (Thanks to SO, I know how to prevent this from happening, but I still want to find out why it happens in the first place.)

-

I believe this happens because Microsoft.SharePoint.dll uses it as a dependency. As Microsoft.SharePoint.Search.dll is not in the GAC, Visual Studio copies it to the bin folder.

-
OK so I just read the SO answers which say essentially the same thing. What is it that you're not clear on? –  Alex Angas Oct 8 '09 at 19:58
Hmmm.. Microsoft.SharePoint.dll references a lot of other non-GAC assemblies (Microsoft.SharePoint.Security for example) but those don't get copied. Perhaps it is dragged in because a concrete constructor somewhere calls or can call something in the search.dll? –  Hafthor Oct 8 '09 at 20:33
I just found it really odd because I've never seen this behavior any other time. –  Hafthor Oct 8 '09 at 20:34
Have you checked if the other assemblies it references are already in the GAC? –  Alex Angas Oct 8 '09 at 20:59

Alex is correct, if you want to stop this happening you can use this hack:

1. Add a refernce to Microsoft.SharePoint.Search.dll (in the 12\ISAPI directory)
2. Select and in the Properties page set Copy Local = false

This makes it easier when you want to do post build events like coping DLL around.

-
Apologies - just saw the link to SO to explain how to stop this. I suppose it's useful here though as we build up our SPO (is that the right acronym?) –  AndrewWoody Oct 9 '09 at 10:54

If it works for you, try putting a build event in your project. Right click the project in Solution Explorer, click Properties, and then go to the Build tab. In Post Build events, put the text:

cd \$(ProjectDir)
del bin\Microsoft.SharePoint.Search.dll
del bin\Microsoft.SharePoint.Search.xml


This will delete the files after every build.

-