Set build order without using project reference

2019-08-17 04:36发布

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.

2条回答
仙女界的扛把子
2楼-- · 2019-08-17 05:18

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

查看更多
仙女界的扛把子
3楼-- · 2019-08-17 05:20

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.

查看更多
登录 后发表回答