How to build all projects in one single folder?

Viewed 13411

Is there a way to build solution into a single folder? I have several projects in this solution and each access a config file that should be in the current directory. I just move each project's build files into one and it still works, however, it looks so unorganized and messy. I just want to know it there are other ways on how to do it.

5 Answers

You can set output directory in the settings of every project in solution (if we are about Visual Studio). Menu: Project -> properties -> Build -> Output path. For example, I use ..\Build\ to build projects into Build directory of solution root.

You can change projects "Output path", by default it's bin directory of given project.

Right click on each project, select Properties from context menu, then select Build tab. Ont the bottom in Output section change Output path:. Set same path for each project.

I agree with comments under your question, you should not change it. Instead you may create post build action (PS script) that will copy all files from project's bin directories to one designated by you.

Update:

Set this script as Post Build command (Project's properties->Build Events tab->Post build event command line):

xcopy "$(TargetDir)*" "$(SolutionDir)Build" /s /i /Y

For each project:

  1. Go into the project properties, in the "Build" tab.
  2. Choose "All configurations", "all platforms", just in-case.
  3. In the output folder write "..\bin\" (or any path which is uniform for all of them - not in the current project directory). Alternatively, to organize DLLs in sub-folders you can write "..\bin\Sub-project-directory" in the output path. Then you should add an App.config file for the EXE project with a probing to all DLLs so they can be found and loaded on runtime.

Note that if we're talking about building multiple executables into the same output directory, you can also add them as project references to the main (startup) project. They will be automatically copied to the main project output directory everytime you build it.

(note: this applies to .NET Core projects in VS 2017 or VS 2019. I'm not sure if it would work for .NET Framework projects)

Related