代码之家  ›  专栏  ›  技术社区  ›  Eduardo Slee

如何更改Visual Studio代码中的默认生成输出目录

  •  3
  • Eduardo Slee  · 技术社区  · 7 年前

    2 回复  |  直到 7 年前
        1
  •  4
  •   Set    7 年前

    VSCode使用dotnet CLI,尤其是用于构建 dotnet build 命令除其他外,它有以下选项

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

    假设您的构建任务在中定义 .vscode/tasks.json 文件:

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

    您可以添加 -o 具有所需路径的arg。例如,更改为:

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

    哪里 ${workspaceFolder} 是VSCode之一 predefined variables :

    ${workspaceFolder}包含任务的工作区文件夹的路径。json文件

        2
  •  3
  •   Martin Ullrich    7 年前

    如果希望VSCode、VS和dotnet CLI的行为一致,我建议编辑csproj文件,通过添加以下内容来设置输出路径:

    <PropertyGroup>
      <OutputPath>..\custom-output-dir\</OutputPath>
      <!-- Remove this if you multi-target and need the created net*, netcoreapp* subdirs -->
      <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    </PropertyGroup>
    

    第二个属性阻止SDK为目标框架添加子目录,这是多目标构建所需的,但如果您只针对单个框架(=当您只有 TargetFramework 属性)。

    设置路径时,也可以使用其他属性,例如:

    <OutputPath>..\custom-output-dir\$(Configuration)\$(MSBuildProjectName)\</OutputPath>
    

    MyProj.csproj ,则输出路径为 ..\cusotm-output-dir\Debug\MyProj\