DEV Community

Dan Schnau
Dan Schnau

Posted on • Originally published at danschnau.com on

.NET 8 Preview 3: Simplified Output Path format for Builds

If you're like me, you're used to finding your .NET build artifacts in /bin and /obj directories inside your source projects. It's been this way my whole career.

In .NET 8 Preview 3, this can be changed to dump the /bin and /obj artifacts into an .artifacts directory instead of the source root.

.NET Manager Chet Husk Writes about it in the comments of 'What's new in .NET 8 Preview 3' discussion.

I'd like to test this little feature out. First, I needed to install .NET 8 Preview 3. It required a system restart.

First, a new console app in a directory testartifactsoutput.

~#@❯ dotnet new console ❮ 

Welcome to .NET 8.0!
---------------------
SDK Version: 8.0.100-preview.3.23178.7

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience..... *SNIP*

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring C:\danschnauprojects\testartifactsoutput\testartifactsoutput.csproj:
  Determining projects to restore...
  Restored C:\danschnauprojects\testartifactsoutput\testartifactsoutput.csproj (in 76 ms).
Restore succeeded.

Enter fullscreen mode Exit fullscreen mode

The default behavior is still to build to the /bin directory.

~#@❯ dotnet build ❮ 
MSBuild version 17.6.0-preview-23174-01+e7de13307 for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\8.0.100-preview.3.23178.7\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targ
ets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [C:\danschnaupr
ojects\testartifactsoutput\testartifactsoutput.csproj]
  testartifactsoutput -> C:\danschnauprojects\testartifactsoutput\bin\Debug\net8.0\testartifactsoutput.dll

Enter fullscreen mode Exit fullscreen mode

Then, we create a Directory.Build.Props file.

~#@❯ dotnet new buildprops ❮ 
The template "MSBuild Directory.Build.props file" was created successfully.

Enter fullscreen mode Exit fullscreen mode

The buildprops file is pretty sparse.

<Project>
  <!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
  <PropertyGroup>

  </PropertyGroup>
</Project>

Enter fullscreen mode Exit fullscreen mode

We add the UseArtifactsOutput flag to the file:

<Project>
  <!-- See https://aka.ms/dotnet/msbuild/customize for more details on customizing your build -->
  <PropertyGroup>
    <UseArtifactsOutput>true</UseArtifactsOutput>
  </PropertyGroup>
</Project>

Enter fullscreen mode Exit fullscreen mode

Now I cleaned up the build by deleting the /bin and obj directories.

~#@❯ ls ❮ 

    Directory: C:\danschnauprojects\testartifactsoutput

Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 4/20/2023 3:25 PM 212 Directory.Build.props
-a---- 4/20/2023 3:20 PM 105 Program.cs
-a---- 4/20/2023 3:20 PM 252 testartifactsoutput.csproj

Enter fullscreen mode Exit fullscreen mode

And now, a build:

~#@❯ dotnet build ❮ 
MSBuild version 17.6.0-preview-23174-01+e7de13307 for .NET
  Determining projects to restore...
  Restored C:\danschnauprojects\testartifactsoutput\testartifactsoutput.csproj (in 64 ms).
C:\Program Files\dotnet\sdk\8.0.100-preview.3.23178.7\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.RuntimeIdentifierInference.targ
ets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [C:\danschnaupr
ojects\testartifactsoutput\testartifactsoutput.csproj]
  testartifactsoutput -> C:\danschnauprojects\testartifactsoutput\.artifacts\bin\testartifactsoutput\debug\testartifactsoutput.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.20

Enter fullscreen mode Exit fullscreen mode

Ooh, I see the .artifacts directory in the output there.

The /bin and /obj directories are now in their own /.artifacts folder. Sweet.

~#@❯ ls ❮ 1s 452ms  

    Directory: C:\danschnauprojects\testartifactsoutput

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/20/2023 3:26 PM .artifacts
-a---- 4/20/2023 3:25 PM 212 Directory.Build.props
-a---- 4/20/2023 3:20 PM 105 Program.cs
-a---- 4/20/2023 3:20 PM 252 testartifactsoutput.csproj

~#@❯ ls .\.artifacts\ ❮ 

    Directory: C:\danschnauprojects\testartifactsoutput\.artifacts

Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 4/20/2023 3:26 PM bin
d----- 4/20/2023 3:26 PM obj

Enter fullscreen mode Exit fullscreen mode

Top comments (0)