Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build fails on first attempt then passes

I have a solution with many projects and 2 of them are a Webservice and a ConsoleApplication. Webservice is the start up project in solution. My solution build order is as follows

  1. ProjectA
  2. ProjectB
  3. ConsoleApplication
  4. Webservice

ProjectA and ProjectB are referenced in both the projects. Now when I clean my solution and try to build the solution it fails for the first time. The error comes constructor of a class in ConsoleApplication project where I am instantiating XYZ class of ProjectA. Error is

The type 'XYZ' is defined in an assembly that is not referenced. You must add a reference to assembly 'ProjectA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. ProjectPath\Program.cs

However when I build the solution again it builds successfully. Can anyone help me to understand the behavior. It is not lethal for my project in any way but I don't want Visual Studio to decide when to do what. I want to know the reason for this behavior.

Also, when I build the solution for first time I could see no .dll of ProjectA or ProjectB in debug folder of ConsoleApplication. However on second attempt these dlls are visible in debug folder and build succeeds.

Any suggestions on how to fix this?

like image 568
Sandy Avatar asked Nov 02 '22 03:11

Sandy


1 Answers

Typically that's a build order problem... On your solution do right click and go to Build Order.

Then set the correct project build order.

Build Order

Cheers

like image 106
tweellt Avatar answered Nov 12 '22 20:11

tweellt