Reputation: 2230
I'm using Visual Studio 2010 and C# to build WinForms apps and class libraries. I have some common libraries that I use for all products, and then some product specific libraries for my apps. None of my assemblies are GAC'd. All projects copy their output from their respective bin\Debug folder to a common Repository folder, and all assembly references are pointed to that Repository folder.
For example, Common.DAL.dll, Common.BLL.dll, Product.DAL.dll, Product.BLL, and Product.exe
The references between assemblies are typically something like this:
When all these are included in the same solution, the build depencies are something like this:
Which makes the build order something like this:
Frequently, when attempting to run an app, I get the following error:
Could not load file or assembly 'Common.DAL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4e5249f2e70e1da8' or one of its dependencies. The system cannot find the file specified.
I have traced the problem down to the fact that not all of the assemblies built from the solution end up in Product.exe's bin\Debug folder.
If I clean the solution, and then rebuild it, the files appear something like this:
I have checked the properties of all of my projects and properties. They are all using .NET Framework 4. All references to my assemblies have 'Specific Version' property set to false, and 'Copy Local' property set to true.
I can force the missing assemblies to be copied to Product.exe\bin\Debug by adding references to the Common assemblies in the Product.exe project, but since Product.exe doesn't explicitly use the Common assemblies, this feels more like a kludge than a solution.
I've looked through MSDN and Visual Studio documentation to see if I could find out what influences or affects the copying of referenced assemblies, and I've searched SO for similar issues, but I haven't found anything helpful.
I'm at a loss for where to go or what to do next.
Upvotes: 2
Views: 2234
Reputation: 12624
In your question you say:
I can force the missing assemblies to be copied to Product.exe\bin\Debug by adding references to the Common assemblies in the Product.exe project, but since Product.exe doesn't explicitly use the Common assemblies, this feels more like a kludge than a solution.
I don't think I concur. It's not perfect, but Visual Studio sometimes requires this even intra-solution. It depends on how you are using the class.
While you may think it is a little kludge, it seems like your other (dare I say "kludgy") requirements (one project per solution) make things seem kludgy
Upvotes: 3
Reputation: 273631
You should only reference bare assemblies when they are relatively stable and outside of the Solution.
Inside your Solution, reference them from the Projects tab. This will make VS configure the correct dependencies and build-order between projects.
In your current setup, verify the Project dependencies (Solution|Properties).
Upvotes: 2