Reputation: 153
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.
Upvotes: 13
Views: 18945
Reputation: 166
This MSDN article explains how to do it in a nice, DRY way: https://blogs.msdn.microsoft.com/kirillosenkov/2015/04/04/using-a-common-intermediate-and-output-directory-for-your-solution/
It allows you to specify those directories only once, and use those settings in multiple projects.
Steps:
Create a single common.props
file in solution, that will specify and overwrite output and intermediate paths for a project to a common directory (like Solution/bin
).
Here is a sample *.props
file that I found linked in the article:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<SolutionDir>$(MSBuildThisFileDirectory)</SolutionDir>
<Configuration Condition="$(Configuration) == ''">Debug</Configuration>
<OutputPath>$(SolutionDir)\bin\$(Configuration)\</OutputPath>
<OutDir>$(OutputPath)</OutDir>
<IntermediateOutputPath>
$(SolutionDir)\obj\$(Configuration)\$(MSBuildProjectName)\
</IntermediateOutputPath>
<UseCommonOutputDirectory>False</UseCommonOutputDirectory>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
</Project>
Include this file into every *.csproj
that you want to set the common output dirs for, by adding this line (the actual path may differ): <Import Project="..\Common.props" />
UPDATE: Nowadays you can put the contents of common.props
in Directory.Build.props
file that will be automatically imported by all projects in the directory tree.
Docs: https://learn.microsoft.com/en-us/visualstudio/msbuild/customize-by-directory?view=vs-2022&source=recommendations#directorybuildprops-and-directorybuildtargets
Upvotes: 11
Reputation: 51
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)
Upvotes: 1
Reputation: 885
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
Upvotes: 7
Reputation: 1885
For each project:
Upvotes: 1
Reputation: 2514
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.
Upvotes: 14