Freigeben über


How to: Change the build output directory

Applies to: yesVisual Studio noVisual Studio for Mac

Note

This article applies to Visual Studio 2017. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

You can specify the location of output generated by your project on a per-configuration basis (for debug, release, or both).

Change the build output directory

  1. To open the project's property pages, right-click on the project node in Solution Explorer and select Properties.

  2. Select the appropriate tab based on your project type:

    • For C#, select the Build tab.
    • For Visual Basic, select the Compile tab.
    • For C++ or JavaScript, select the General tab.
  3. In the configuration drop-down at the top, choose the configuration whose output file location you want to change (Debug, Release, or All Configurations).

  4. Find the output path entry on the page—it differs depending on your project type:

    • Output path for C# and JavaScript projects
    • Build output path for Visual Basic projects
    • Output directory for Visual C++ projects

    Type in the path to generate output to (absolute or relative to the root project directory), or choose Browse to browse to that folder instead.

    Note

    Some projects will by default include framework and runtime in the build path. To change this, right-click the project node in Solution Explorer, select Edit Project File, and add the following:

    <PropertyGroup>
      <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
      <AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
    </PropertyGroup>
    

Tip

If the output is not being generated to the location that you specified, make sure you're building the corresponding configuration (for example, Debug or Release) by selecting it on the menu bar of Visual Studio.

Build to a common output directory

By default, Visual Studio builds each project in a solution in its own folder inside the solution. You can change the build output paths of your projects to force all outputs to be placed in the same folder.

To place all solution outputs in a common directory

  1. Click on one project in the solution.

  2. On the Project menu, click Properties.

  3. Depending on the type of project, click on either the Compile tab or the Build tab, and set the Output path to a folder to use for all projects in the solution.

  4. Open the project file for the project, and add the following property declaration to the first property group.

    <PropertyGroup>
      <!-- existing property declarations are here -->
      <UseCommonOutputDirectory>true</UseCommonOutputDirectory>
    </PropertyGroup>
    

    Setting UseCommonOutputDirectory to true tells Visual Studio and its underlying build engine (MSBuild) that you're putting multiple project outputs in the same folder, and so MSBuild omits the copying step that normally happens when projects depend on other projects.

  5. Repeat steps 1-4 for all projects in the solution. You can skip some projects if you have some exceptional projects that should not use the common output directory.

To set the intermediate output directory for a project (.NET projects)

  1. Open the project file.

  2. Add the following property declaration to the first property group.

    <PropertyGroup>
      <!-- existing property declarations are here -->
      <IntermediateOutputPath>path</IntermediateOutputPath>
    <PropertyGroup>
    

    The path is relative to the project file, or you can use an absolute path. If you want to put the project name in the path, you can reference it by using the MSBuild properties $(MSBuildProjectName), $(MSBuildProjectDirectory). For more properties you can use, see MSBuild reserved and well-known properties.

  3. Visual Studio still creates the obj folder under the project folder when you build, but it's empty. You can delete it as part of the build process. One way to do that is to add a post-build event to run the following command:

    rd "$(ProjectDir)obj" /s /q
    

    See Specify custom build events.

    The obj folder is not created when you build from the MSBuild command line.

See also