dotnet / dotnet/msbuild

Common Flat Build Output via Directory.Build.props/.targets

Open
#7,300 3 comments 2 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

In [Common Flat Build Output](https://nietras.com/2021/11/19/bendingdotnet-common-flat-build-output/) I thought I'd finally found a clean solution to a long search for getting flat build output from msbuild for .NET. Unfortunately, this approach has a serious flaw as reported in [F12 not working across C# projects in solution perhaps due to customized output paths in VS22](https://developercommunity.visualstudio.com/t/f12-not-working-across-c-projects-in-solution-perh/1629596). I then tweeted a bit about trying to fix the issue in https://twitter.com/nietras1/status/1462885254755147780 but I cannot find a good solution for it that does not require changing `csproj` files.

The premise is that I want to change the build output fully by only changing the `Directory.Build.props/.targets` in a common parent directory, and not have to do any changes to `csproj` for this since that is very cumbersome for a solution with hundreds or thousands of projects. One of the problems here then seems to be that e.g. `TargetFramework` is not defined at the point of `Directory.Build.props`. The same issue btw relates to `Configuration` and `Platform` and this has been a long standing issue since many then try to use these but they are often not defined at the point when `Directory.Build.props` is imported. Import order is somewhat covered in https://github.com/dotnet/msbuild/issues/2767#issuecomment-514342730 as far as I can tell.

Source code from blog post with the go to definition issue:
[CommonFlatBuild.zip](https://github.com/dotnet/msbuild/files/7874596/CommonFlatBuild.zip)

For a MSBuild novice like me I would think we are missing a set of extension points that complement the "outermost" `Directory.Build.props/.targets` so we perhaps instead could have something like:
```
Directory.Build.props

Directory.Project.props

Directory.Project.targets

Directory.Build.targets
```
that is we would add "innermost" complements to `Directory.Build.*` in the form of say `Directory.Project.*`. This should cover more use cases.

However, perhaps there is another way of doing what I want that I just can't find.

cc: @KirillOsenkov @sharwell

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked CommonFlatBuild.zip and the import-order discussion in issue 2767; inspect how Directory.Build.props/.targets are imported relative to project evaluation. Compare the proposed Directory.Project.props/.targets extension points with the flat-output and Go To Definition requirements. Done means a scoped solution that avoids editing each csproj.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.