views:

2092

answers:

5

Hi there,

I am using Visual Studio 2005, .NET 2.0

I am not really sure yet under what circumstances it happens, but here is the scenario: I have a solution with a project structure like this: A library project Foo, a library project Bar which references Foo, and a library project Quux which references Foo and Bar.

Compiling fails with the Error message "Metadata file 'Foo.dll' could not be found" from Bar, and "Metadata file 'Foo.dll' could not be found" and "Metadata file 'Bar.dll' could not be found" from Quux.

Looking in my target directory (I have a combined target directory for all 3 projects), it is empty, so no project at all is compiled. Now I can get that Bar and Quux fail if there is no output from Foo. Problem is: Why does Foo silently fail? There is no error from it, and just building Foo instead of the entire solution works fine.

The "funny" thing is, after just pushing the build button again, the Foo.dll file appears, Bar no longer complains but does not produce any output file either, and Quux complains about missing Bar.dll. Pushing the button again, the Bar.dll appears, there are no more errors but no Quux.dll. Only after pushing the button yet again, the Quux.dll appears, once again with no errors.

The project dependencies are all set correctly, the solution build order says exactly the right thing.

I have even tried creating a new solution and new project files, then adding the sources again to those. No joy, either. Same thing happens.

I am completely stumped. Does anyone know a way out of this mess?

A: 

The problem is build order. If some project depends on another then that second project must be built first. Use build dependencies in the solution properties to overcome this.

sharptooth
I already wrote: "The project dependencies are all set correctly, the solution build order says exactly the right thing."
Do they really build in this order (at least try)?
sharptooth
Yes. Foo, then Bar, then Quux. Foo says it compiled, Bar and Quux fail due to missing Foo. And there is no Foo in the target directory.
Then I guess there's some step that deletes the assembly. Try to use separate directories for the results of each project. Add custom build step to copy the assembly to the necessary common folder to have all them in one place if you need this.
sharptooth
Could it be that you may be using a post-build event in any of the projects, so as to copy the dlls to your combined target directory?
El Padrino
If this turns out really weird, Process Monitor could help (http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx).
sharptooth
A: 

Check you build order so that all seems right there.. Try to run a clean solution and build again is this when it happens?

Petoj
+4  A: 

You should have separate output directory for each project. Each time a project builds, it clears the output directory, so it won't find any dependencies on the next one.

Don't fear losing any DLLs, they'll be copied on each bin directory where they are needed.

Fabian Vilers
+1  A: 

I think a work around to your problem could be using post build events that deletes previous version of your dlls and copies the new ones to your combined target directory.

When you set up the three projects to work this way, you will find that you are compiling each project to it's correspondent bin folder and to a combined target directory. There is a second thing you should do if you decide to work with this, set up for each project in your solution a reference path pointing to the combined target directory. Compiling order must still exist.

This way each project dll will be found in the combined target directory, each time you compile.

Although, this solution has it's own problems such as when a post-build event forgets to wrok properly; but it's rare.

Hope this helps

El Padrino
A: 

Drag your project file into note pad and Find with "Import" tag and replace that tag with this

Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets"

Its should work

Ramana