Search code examples
c#visual-studio-code.net-corecsprojdotnet-cli

How can I change the default build output directory in Visual Studio Code


I'm new to Visual Studio Code. I want to define the output directory in my csproj. I don't know where to change in Visual Studio Code the destination folder to locate the dll files generated.


Solution

  • VSCode uses dotnet CLI and particularly for building the dotnet build command. Among others, it has the following option

    -o|--output <OUTPUT_DIRECTORY>
    Directory in which to place the built binaries.
    

    Assuming your building task is defined in .vscode/tasks.json file:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "taskName": "build",
                "command": "dotnet build",
                ...
            }
        ]
    }
    

    You may add -o arg with the desired path. For example, change to:

    ...
    "command": "dotnet build -o ${workspaceRoot}/bin/another_Debug/",
    ...
    

    where ${workspaceFolder} is one of VSCode predefined variables:

    ${workspaceFolder} the path of the workspace folder that contains the tasks.json file