Sandy
Sandy

Reputation: 11687

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?

Upvotes: 5

Views: 2412

Answers (3)

kshitij Sabale
kshitij Sabale

Reputation: 101

You are missing a project reference. To add a project reference, let the project A be the project which creates the DLL and Project B be the project that references the DLL. So in the solution explorer, double click on the project B and right click on References, select Add Reference. Add the reference to the project A.

Upvotes: 0

Tseng
Tseng

Reputation: 64121

It sounds like you have not set up project dependencies. You'll have to set up the build dependencies correctly, i.e.

  1. Webservice depends ProjectA and ProjectB
  2. Console Application depends on ProjectA, ProjectB and Webservice

It's important to make the console depend on the webservice, cause only then the webservice will be guaranteed to be built before the console Application.

For Visual Studio 2012 do, right click your solution > Properties > Project Dependencies >

Upvotes: 0

tweellt
tweellt

Reputation: 2161

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

Upvotes: 3

Related Questions