Skip to content

Support Directory.Build.props for target framework configuration#362

Merged
runesoerensen merged 21 commits intomainfrom
support-directory-build-props-for-tfm
Dec 10, 2025
Merged

Support Directory.Build.props for target framework configuration#362
runesoerensen merged 21 commits intomainfrom
support-directory-build-props-for-tfm

Conversation

@runesoerensen
Copy link
Copy Markdown
Contributor

@runesoerensen runesoerensen commented Dec 9, 2025

This PR adds support for detecting the target framework via Directory.Build.props files. Previously, the buildpack required the TargetFramework to be explicitly defined in project files to determine the .NET SDK version.

The buildpack now mimics MSBuild behavior by walking up the directory tree to find the first Directory.Build.props file and inheriting the configuration.

As an example, the buildpack will inherit net8.0 as the target framework, unless explicitly defined, in projects or file-based apps located in the same directory and subdirectories of the following Directory.Build.props file:

<Project>
    <PropertyGroup>
        <TargetFramework>net8.0</TargetFramework>
    </PropertyGroup>
</Project>

Changes

  • When loading projects or file-based apps without an explicit TargetFramework, the buildpack now searches the directory tree to find, parse, and extract the property from a Directory.Build.props file.
  • Refactored project loading error types to use a unified FileLoadError enum. This reduces code duplication and ensures consistent error handling across project files, file-based apps, and Directory.Build.props files.
  • Updated error messages and the README to reflect that the target framework can now be resolved via Directory.Build.props.

Limitations

This implementation performs a "naive" parse of Directory.Build.props solely for SDK version detection.

Advanced MSBuild features are not supported during this detection phase:

  • Conditional property logic (e.g., Condition attributes).
  • Multi-level merging (Importing other .props or .targets files).
  • Property evaluation or variable substitution.

Note: These limitations only affect how the buildpack determines which .NET SDK to install. Once the SDK is installed, dotnet publish will process Directory.Build.props using the actual MSBuild engine, fully supporting all features (conditions, imports, etc.).

Closes #187

GUS-W-20429520

@runesoerensen runesoerensen changed the title Support Directory.Build.props target framework configuration Support Directory.Build.props for target framework configuration Dec 10, 2025
@runesoerensen runesoerensen force-pushed the support-directory-build-props-for-tfm branch from 7a1cab8 to 5f2673b Compare December 10, 2025 02:12
@runesoerensen runesoerensen marked this pull request as ready for review December 10, 2025 02:57
@runesoerensen runesoerensen requested a review from a team as a code owner December 10, 2025 02:57
@runesoerensen runesoerensen merged commit 55766b5 into main Dec 10, 2025
7 checks passed
@runesoerensen runesoerensen deleted the support-directory-build-props-for-tfm branch December 10, 2025 14:45
heroku-linguist Bot added a commit that referenced this pull request Dec 11, 2025
## heroku/dotnet

### Added

- Support for configuring the target framework using `Directory.Build.props`. ([#362](#362))
- Support for configuring the `AssemblyName` property in file-based apps. ([#359](#359))

### Fixed

- Fixed an issue where leading whitespace in file-based app configuration values was incorrectly included. ([#359](#359))
heroku-linguist Bot added a commit that referenced this pull request Dec 13, 2025
## heroku/dotnet

### Added

- Support for configuring the target framework using `Directory.Build.props`. ([#362](#362))
- Support for configuring the `AssemblyName` property in file-based apps. ([#359](#359))

### Fixed

- Fixed an issue where leading whitespace in file-based app configuration values was incorrectly included. ([#359](#359))
heroku-linguist Bot added a commit that referenced this pull request Dec 13, 2025
## heroku/dotnet

### Added

- Support for configuring the target framework using `Directory.Build.props`. ([#362](#362))
- Support for configuring the `AssemblyName` property in file-based apps. ([#359](#359))

### Fixed

- Fixed an issue where leading whitespace in file-based app configuration values was incorrectly included. ([#359](#359))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
heroku-linguist Bot added a commit to heroku/cnb-builder-images that referenced this pull request Dec 13, 2025
## heroku/dotnet

### Added

- Support for configuring the target framework using `Directory.Build.props`. ([#362](heroku/buildpacks-dotnet#362))
- Support for configuring the `AssemblyName` property in file-based apps. ([#359](heroku/buildpacks-dotnet#359))

### Fixed

- Fixed an issue where leading whitespace in file-based app configuration values was incorrectly included. ([#359](heroku/buildpacks-dotnet#359))
heroku-linguist Bot added a commit to heroku/cnb-builder-images that referenced this pull request Dec 13, 2025
## heroku/dotnet

### Added

- Support for configuring the target framework using `Directory.Build.props`. ([#362](heroku/buildpacks-dotnet#362))
- Support for configuring the `AssemblyName` property in file-based apps. ([#359](heroku/buildpacks-dotnet#359))

### Fixed

- Fixed an issue where leading whitespace in file-based app configuration values was incorrectly included. ([#359](heroku/buildpacks-dotnet#359))

Co-authored-by: heroku-linguist[bot] <136119646+heroku-linguist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect target framework from Directory.Build.props

2 participants