1

In our solution we have more than 150 projects, now most of projects are using some .js file, which is generated by another project. So I need build this project before others. I know I can set the other projects are reference this project, but the problem is that we have nearly 100 projects that needs those .js file, add this project as reference project to 100 projects is not the best option.

So how can I set the build order without adding project reference?

Thanks any advice.

  • Right click on solution and select Project Build Order. On the dependencies tab, manually make your project dependent on the desired project. (This will not add project reference) This will make your solution built in desired order. – Sunil Jan 05 '18 at 06:14
  • @Sunil, Thanks for your suggestion, but you still need set dependencies for other 100 prrojects in the Project Dependencies windows. –  Jan 05 '18 at 06:27
  • The next best thing would be to add one dependency and observe the changes in solution file. Then just change directly in the solutions file. – Sunil Jan 05 '18 at 06:39

2 Answers2

2

In Visual Studio, for each project that depends on your dependant project X:

  1. Right-click project
  2. Choose Build Dependencies...
  3. Choose Project Dependencies
  4. Tick the project this project depends on
  5. Click OK
  6. Repeat steps 1-5 for all other projects

Sadly, selecting multiple projects (at least in VS2017) won't let you apply the settings to more than one project at a time

  • Thanks, but this should not what I want, in this way, I still need repeat 1-5 steps for nearly 100 projects. This is not what I want, I also said it in my question, anyway, thanks for your answer. –  Jan 05 '18 at 06:29
  • 2
    @John It's a legitimate solution. I think the bigger problem is why you have **100** projects in **one solution**. Also, it is **not** _"adding a project reference"_ –  Jan 05 '18 at 06:45
  • 1
    Reiterating that this answer is setting __build dependencies__, and not C# __project dependencies__ (even though there is a tab in this UI labeled "Project Dependencies"). This effectively is only setting the build order, and not providing dependencies for linking, etc... which is __great__ if that's exactly what you need. – bojolais Dec 01 '22 at 16:14
0

how can I set build order without adding project reference?

You do not want to set project reference or project dependencies to each of those 100 projects, but there is no such option that you can set multiple references at once.

To resolve this problem, I would like provide you two workarounds.

  • Build that referenced project first, then build the solution.

    In this way, you should pay a attention to manually build the referenced project first. It seems you are not independent developer, this way should not the best option.

  • Using batch file to set the build order.

You can use batch file to set build order, build the referenced project first, then build the solution:

    @echo OFF 
    call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
    echo "Starting Build for all Projects with proposed changes"
    MSBuild.exe "C:\Users\Admin\Source\repos\TestMSBuildOrder\GenerateJSFileProject\GenerateJSFileProject.csproj"
    MSBuild.exe "C:\Users\Admin\Source\repos\TestMSBuildOrder\TestMSBuildOrder.sln"
    pause
    echo "All builds completed." 

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • Liu, Thanks for your suggestion, this should be a great workaround, as optimization, I want set this bat file in the build event of that project so that I only need to build that project, do not need to manually run the bat file from outside. But I got the error error MSB3073: The command exited with code 1. https://stackoverflow.com/questions/48146611/execute-bat-file-in-the-build-event-got-the-error-error-msb3073-the-command-c. Could you help me for this issue? –  Jan 08 '18 at 08:41