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

烈酒焚心 提交于 2021-02-08 06:27:38

问题


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.


回答1:


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




回答2:


If you want a consistent behavior from VSCode, VS and the dotnet CLI, I suggest editing the csproj file to set the output path by adding this:

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

The second property prevents the SDK from adding a subdirectory for the target framework, which is needed for multi-targeting builds, but not so if you only target a single framework (= when you only have a TargetFramework property).

You can also use other properties when setting the path, for instance:

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

Assuming your project is MyProj.csproj, the output path would then be ..\cusotm-output-dir\Debug\MyProj\



来源:https://stackoverflow.com/questions/46959632/how-can-i-change-the-default-build-output-directory-in-visual-studio-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!