Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change Visual Studio's build order for reflection based project dependencies?

I have the need to dynamically load different versions of the same dll's depending on various situations.

The dll's are created as part of the build process for other projects within the same solution.

For example

/MainSolution
    /MainProject - Loads dll's using reflection dynamically
    /AbstractProject
    /DllProject1
    /DllProject2

DllProject1 and DllProject2 need to be built before MainProject. MainProject depends on AbstractProject, and through reflection DllProject1/DllProject2. However Visual studio currently forces MainProject to build before DllProject1 and DllProject2. How can I get Visual Studio to build DllProject1/DllProject2 before MainProject?

like image 331
CamHart Avatar asked Feb 08 '16 22:02

CamHart


People also ask

How do I change the project build order in Visual Studio?

From the main menu, select Window > Preferences . In the left pane, expand General, expand Workspace, and select Build Order. Disable the Use default build order option. Select a project from the list, then click the Up or Down buttons to position the project where you want it to appear in the build order list.

How do I change the build order on a project?

You can manually change the build order through the workspace preferences (Window > Preferences > General > Workspace > Build Order). Changing these preferences manually may cause build errors.

How does Visual Studio identify project dependencies?

You can view the project dependencies by selecting Build Dependencies\Project Dependencies from the context menu on a project in the solution explorer.


2 Answers

Visual Studio allows you to set explicit build dependencies in the solution (as opposed to implicity dependencies e.g. from traversing your references). Just right-click on your solution and find the Project Dependencies menu item:

Project Dependencies menu item

The dialog that opens will allow you to set build dependencies and show you the calculated build order (you can affect the order by changing the dependencies).

like image 85
Jimmy Avatar answered Oct 24 '22 00:10

Jimmy


The solution I found was to do the following:

Open up the .sln file, and change the order in which they projects are listed. Dropping MainProject down to the bottom. Then when I opened up the solution, it had DllProject1 and DllProject2 listed above MainProject in the build order.

Edit: While this works, there is no rhyme or reason for how it works. Randomly switching the order results in randomly changing the build order for projects that have the same dependents.

like image 40
CamHart Avatar answered Oct 24 '22 02:10

CamHart