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:
- Product.exe includes reference to Product.BLL
- Product.BLL includes references to Common.BLL and Product.DAL
- Product.DAL includes reference to Common.DAL
- Common.BLL includes refrence to Common.DAL
When all these are included in the same solution, the build depencies are something like this:
- Common.BLL depends on Common.DAL
- Product.DAL depends on Common.DAL
- Product.BLL depends on Common.BLL and Product.DAL
- Product.exe depends on Product.BLL
Which makes the build order something like this:
- Common.DAL
- Common.BLL
- Product.DAL
- Product.BLL
- Product.exe
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:
- Common.DAL\bin\Debug contains Common.DAL.dll
- Common.BLL\bin\Debug contains Common.BLL.dll and Common.DAL.dll
- Product.DAL\bin\Debug contains Common.DAL.dll and Product.DAL.dll
- Product.BLL\bin\Debug contains Common.BLL.dll, Common.DAL.dll,
Product.BLL.dll and Product.DAL.dll - but Product.exe\bin\Debug contains only Product.exe, Product.BLL and
Product.DAL. It is missing the Common assemblies. So when I run
Product.exe, I get the error listed above.
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.
In your question you say:
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