question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support common output directory root in SDK out of the box

See original GitHub issue

Currently, new projects using SDK build into per-project bin and obj directories. That’s good for simple projects that don’t participate in CI. For repos that build using CI servers it is often a requirement to produce all outputs under a single root directory with following (or similar) layout:

$(RootOutputPath)\$(Configuration)\bin\$(MSBuildProjectName)
$(RootOutputPath)\$(Configuration)\obj\$(MSBuildProjectName)
$(RootOutputPath)\$(Configuration)\packages

We have seen countless repos with build systems that are customized to do so, each in a different way. Such build customization is usually hard to get right.

I propose to add an out of the box option to the SDK that allows customers to create such repo layouts trivially.

The $(RootOutputPath) could perhaps be specified via implicit Directory.Build.props import feature: https://github.com/Microsoft/msbuild/issues/222.

Perhaps we could also consider $(RepositoryRootPath) a well-known property that has a documented meaning. It’s a generally useful property to have, imo.

To summarize I propose the user has the option to set the following properties in Directory.Build.props:

<!-- Default value for configuration is set after Directory.Build.props is imported -->  
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>

<RepositoryRootPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\'))</RepositoryRootPath>
<RootOutputPath>$(RepositoryRootPath)artifacts\$(Configuration)\bin\</RootOutputPath>
<RootIntermediateOutputPath>$(RepositoryRootPath)artifacts\$(Configuration)\obj\</RootIntermediateOutputPath>

And the SDK uses these variables to set the output paths like so:

<PropertyGroup Condition="'$(RootOutputPath)' != ''" >
  <BaseOutputPath Condition="'$(BaseOutputPath)' == ''">$(RootOutputPath)$(MSBuildProjectName)\</BaseOutputPath>
  <OutputPath>$(BaseOutputPath)</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(RootIntermediateOutputPath)' != ''" >
  <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)' == ''">$(RootIntermediateOutputPath)$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
</PropertyGroup>

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:26
  • Comments:42 (38 by maintainers)

github_iconTop GitHub Comments

2reactions
baronfelcommented, Jul 28, 2023

Circling back here, this shipped in .NET 8.0.100 preview 3 - the easiest way to enable it is to create a Directory.Build.props file with <ArtifactsPath>$(MSBuildThisFileDirectory)artifacts</ArtifactsPath> in your repo root. You can read more about it the preview 3 and preview 4 blog post updates.

2reactions
dsplaistedcommented, Jan 12, 2023

@stijnherreman The latest update is that we are considering some output path changes in .NET 8, which would include support for a RootArtifactsPath property which would let you put all of the output of a repo under a single folder. That design is here: https://github.com/dotnet/designs/pull/281

In the meantime, you can put the following in a Directory.Build.props file to redirect the bin and obj folders of each project under a common directory:

<Project>

  <PropertyGroup>
    <RootOutputPath>artifacts</RootOutputPath>
	  
    <RootOutputPath>$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\$(RootOutputPath)\'))</RootOutputPath>
    <BaseOutputPath>$(RootOutputPath)bin\$(MSBuildProjectName)\</BaseOutputPath>
    <BaseIntermediateOutputPath>$(RootOutputPath)obj\$(MSBuildProjectName)\</BaseIntermediateOutputPath>
  </PropertyGroup>

</Project>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Copy to Output Directory copies folder structure but only ...
You can add a Post Build Event to copy the files. Go to project properties, Build Events tab and add the following to...
Read more >
Common macros for MSBuild commands and properties
For example, in the left pane, select Configuration Properties > VC++ Directories, and then in the right pane, select Include directories. The ...
Read more >
User-defined macro not appearing when searching it in ...
While I am editing the remote root directory setting to include my user-defined macro, it appears to be extended on the grayed-out box...
Read more >
The Buildroot user manual
Buildroot output is stored in a single directory, output/ . This directory contains several subdirectories: images/ where all the images (kernel image, ...
Read more >
DBX Root Header Modes Guide - Developers
Information and examples on how to use path root header modes when calling the Dropbox ... The Dropbox-API-Path-Root header supports three different modes....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found