Visualstudio-docs: Further Directory.Build.props/targets inclusion can be made more generic

Created on 16 Aug 2018  Â·  2Comments  Â·  Source: MicrosoftDocs/visualstudio-docs

The current article recommends including the following Import to include subsequent Directory.Build.props files in your project's directory tree.
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />

This can be made more generic to work for both Directory.Build.props and Directory.Build.targets
<Import Project="$([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..))" />

Further, this can be made to work regardless of whether subsequent Directory.Build.* files exist (only recommended if you control and trust parent directories).
<Import Project="$([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..))" Condition="Exists($([MSBuild]::GetPathOfFileAbove($(MSBuildThisFile), $(MSBuildThisFileDirectory)..)))" />


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

doc-bug past-90-days resolved

Most helpful comment

actually I was having some strange errors with "value of the project attribute in element import is invalid " this solution solved my problem.

All 2 comments

actually I was having some strange errors with "value of the project attribute in element import is invalid " this solution solved my problem.

@grantborthwick Thank you for the feedback! Though while this solution is more flexible, it moves away from the main topic of concern which is Directory.Build.props.

Thank you for this suggestion and will definitely keep it under consideration for future restructuring of the article.

Was this page helpful?
0 / 5 - 0 ratings