$npx -y skills add wshaddix/dotnet-skills --skill dotnet-artifacts-outputUsing artifacts output layout. UseArtifactsOutput, ArtifactsPath, impact on CI and Docker.
| 1 | # dotnet-artifacts-output |
| 2 | |
| 3 | Reference guide for the .NET SDK artifacts output layout, which centralizes build outputs (`bin/`, `obj/`, `publish/`, `package/`) into a single `artifacts/` directory at the repo root. Available since .NET 8 as an opt-in feature. Recommended for new projects; evaluate tradeoffs before migrating existing projects. |
| 4 | |
| 5 | **Prerequisites:** Run [skill:dotnet-version-detection] first to confirm .NET 8+ SDK -- artifacts output layout is not available in earlier SDK versions. |
| 6 | |
| 7 | **Scope boundary:** [skill:dotnet-project-structure] covers source tree organization (`.sln`, `.csproj`, `src/`, `tests/`). This skill covers build output organization (`artifacts/bin/`, `artifacts/obj/`, `artifacts/publish/`). Source tree vs output tree. |
| 8 | |
| 9 | Cross-references: [skill:dotnet-project-structure] for solution layout, [skill:dotnet-containers] for Dockerfile path adjustments, [skill:dotnet-gha-build-test] for CI artifact upload paths, [skill:dotnet-scaffold-project] for generating new projects with artifacts output enabled. |
| 10 | |
| 11 | --- |
| 12 | |
| 13 | ## Why Use Artifacts Output |
| 14 | |
| 15 | Traditional .NET build output scatters `bin/` and `obj/` directories throughout the source tree, one per project. The artifacts output layout consolidates all build outputs under a single `artifacts/` directory next to `Directory.Build.props`. |
| 16 | |
| 17 | Benefits: |
| 18 | - **Simpler `.gitignore`** -- one `artifacts/` entry replaces per-project `bin/` and `obj/` entries |
| 19 | - **Easier clean builds** -- delete one directory instead of hunting for scattered `bin/`/`obj/` folders |
| 20 | - **Predictable output paths** -- tooling can anticipate where to find build outputs without traversing the source tree |
| 21 | - **Cleaner source tree** -- no build artifacts mixed into project directories |
| 22 | |
| 23 | Tradeoffs: |
| 24 | - **Breaking path assumptions** -- existing CI pipelines, Dockerfiles, and tooling that reference `bin/Debug/net10.0/` paths must be updated |
| 25 | - **IDE/tool compatibility** -- some older tools may not resolve the new output paths correctly |
| 26 | - **Migration effort** -- existing projects require updating all hardcoded output path references |
| 27 | |
| 28 | --- |
| 29 | |
| 30 | ## Enabling Artifacts Output |
| 31 | |
| 32 | Add `UseArtifactsOutput` to your `Directory.Build.props` at the repo root: |
| 33 | |
| 34 | ```xml |
| 35 | <Project> |
| 36 | <PropertyGroup> |
| 37 | <UseArtifactsOutput>true</UseArtifactsOutput> |
| 38 | </PropertyGroup> |
| 39 | </Project> |
| 40 | ``` |
| 41 | |
| 42 | Alternatively, generate a new `Directory.Build.props` with artifacts output pre-configured: |
| 43 | |
| 44 | ```bash |
| 45 | dotnet new buildprops --use-artifacts |
| 46 | ``` |
| 47 | |
| 48 | This creates: |
| 49 | |
| 50 | ```xml |
| 51 | <Project> |
| 52 | <PropertyGroup> |
| 53 | <ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath> |
| 54 | </PropertyGroup> |
| 55 | </Project> |
| 56 | ``` |
| 57 | |
| 58 | Setting `ArtifactsPath` directly is equivalent to `UseArtifactsOutput=true` and additionally lets you customize the root directory location. |
| 59 | |
| 60 | --- |
| 61 | |
| 62 | ## Output Path Structure |
| 63 | |
| 64 | All build outputs are organized under `artifacts/` with three levels: output type, project name, and pivot (configuration/TFM/RID). |
| 65 | |
| 66 | ``` |
| 67 | artifacts/ |
| 68 | bin/ |
| 69 | MyApp/ |
| 70 | debug/ # Single-targeted project |
| 71 | debug_net10.0/ # Multi-targeted project |
| 72 | release_linux-x64/ # RID-specific build |
| 73 | MyApp.Core/ |
| 74 | debug/ |
| 75 | obj/ |
| 76 | MyApp/ |
| 77 | debug/ |
| 78 | publish/ |
| 79 | MyApp/ |
| 80 | release/ # dotnet publish output |
| 81 | release_linux-x64/ # RID-specific publish |
| 82 | package/ |
| 83 | release/ # NuGet .nupkg files (no project subfolder) |
| 84 | ``` |
| 85 | |
| 86 | ### Output Type Directories |
| 87 | |
| 88 | | Directory | Contents | Traditional equivalent | |
| 89 | |-----------|----------|----------------------| |
| 90 | | `artifacts/bin/` | Compiled assemblies and dependencies | `<project>/bin/` | |
| 91 | | `artifacts/obj/` | Intermediate build files, generated code | `<project>/obj/` | |
| 92 | | `artifacts/publish/` | Published application output | `<project>/bin/<config>/<tfm>/publish/` | |
| 93 | | `artifacts/package/` | NuGet packages (`.nupkg`, `.snupkg`) | `<project>/bin/<config>/` | |
| 94 | |
| 95 | ### Pivot Naming |
| 96 | |
| 97 | The pivot subfolder combines configuration, TFM, and RID joined by underscores. Components that are not present are omitted: |
| 98 | |
| 99 | | Scenario | Pivot | Full path example | |
| 100 | |----------|-------|-------------------| |
| 101 | | Single-targeted, debug | `debug` | `artifacts/bin/MyApp/debug/` | |
| 102 | | Multi-targeted, debug | `debug_net10.0` | `artifacts/bin/MyApp/debug_net10.0/` | |
| 103 | | Release, RID-specific | `release_linux-x64` | `artifacts/bin/MyApp/release_linux-x64/` | |
| 104 | | Package output | `release` | `artifacts/package/release/` | |
| 105 | |
| 106 | Note: `artifacts/package/` omits the project name subfolder. The pivot includes only the configuration. |
| 107 | |
| 108 | --- |
| 109 | |
| 110 | ## Customizing the Artifacts Path |
| 111 | |
| 112 | ### Custom Root Directory |
| 113 | |
| 114 | Set `ArtifactsPath` to change the root location: |
| 115 | |
| 116 | ```xml |
| 117 | <PropertyGroup> |
| 118 | <ArtifactsPath>$(MSBuildThisFileDirectory).output</ArtifactsPath> |
| 119 | </PropertyGroup> |
| 120 | ``` |
| 121 | |
| 122 | This places all build outputs under `.output/` instead of `artifacts/ |