Support common output directory root in SDK out of the box
See original GitHub issueCurrently, 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:
- Created 7 years ago
- Reactions:26
- Comments:42 (38 by maintainers)
Top GitHub Comments
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.@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/281In the meantime, you can put the following in a
Directory.Build.props
file to redirect thebin
andobj
folders of each project under a common directory: