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.

Directory.Build.props should be imported before SDK props do anything

See original GitHub issue

Using a Directory.Build.props file is one way we’ve told people to set properties before the common props run (see https://github.com/Microsoft/msbuild/issues/1603). However, Directory.Build.props is currently evaluated after Microsoft.NET.Sdk.props, which means setting some properties such as the Configuration or Platform in Directory.Build.props leads to inconsistent results, as there are other default property values which are based on them in Microsoft.NET.Sdk.props.

A fix to this would be to duplicate the logic from MSBuild that imports Directory.Build.props in the SDK targets, and then set ImportDirectoryBuildProps to false so that the common props don’t try to import it again.

This would be a breaking change for projects that rely (likely accidentally) on the current behavior, so we’d need to assess the compat risk of this change.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
rainersigwaldcommented, Mar 1, 2017

I think it generally makes sense for an SDK to pull in d.b.props first and disable the common.props import. The idea of d.b.props is that it’s imported early. In the (old) default template, the common.props import was the first line, and the d.b.props import is very early in common.props–so d.b.props in the old world is basically first.

If we wind up making the core SDK a package (https://github.com/Microsoft/msbuild/issues/1686), we could separate out the d.b.props import into its own file so it could be more easily called by an SDK. Then the pattern for sdks could be

  <Import Project="Directory.Build.props" Sdk="Core"  />
  <Import Project="$(MSBuildThisFileDirectory)..\build\Microsoft.NET.Sdk.props"  />
  <Import Project="Microsoft.Common.props" Sdk="Core" />

It’s unfortunate that this would be a “standard pattern” rather than “done for you” but I don’t see a way around it that keeps explicit, ordered imports.

0reactions
rainersigwaldcommented, Mar 1, 2017

That’s up to the Sdk. MSBuild’s evaluation order constraints make this complicated–usually you want to set some stuff early and some stuff after common.props. We can’t disconnect the directory.build.props import from common.props (it has to be somewhere). If it’s not in the right place for Microsoft.NET.Sdk, there are options:

This is a limitation of the ordered-evaluation + import-whole-files + extensibility nature of MSBuild. We could change the order of imports but that only postpones the problem. We could shard into more files, but that pushes complexity into other layers (it’d be unpleasant if SDK.props had to import a dozen files from common in the right relative order, just to allow the possibility of avoiding this problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Customize your build by folder or solution - MSBuild
Directory.Build.props is imported early in the sequence of imported files, which can be important if you need a set a property that is...
Read more >
how use properties from Directory.Build.props in Import ...
Targets is always implicitly imported right after the Microsoft.Common.props and before others. Note: This feature only supports C# and VB, ...
Read more >
What is this Directory.Build.props file all about?
props is a user-defined file that provides customisation to projects under a directory. Directory.Build.props is imported very early in the ...
Read more >
How does `msbuild` know where to find the `Directory.Build ...
NET project, I noticed that msbuild will use definitions from a file called Directory.build.props several folders above my current working ...
Read more >
Common MSBuild properties and items with Directory.Build ...
Build.props anywhere in your repo, and it will be automatically imported by any project under the directory containing this file.
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