I have the following Directory.Build.props files:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
<IncludePath>$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LibraryPath>$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
<IncludePath>$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LibraryPath>$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
<IncludePath>$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LibraryPath>$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
<IncludePath>$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
</Project>
Whenever I load a (C++) project in a subfolder (in visual Studio 2019), the project loses all inherited include and library paths:
I was thinking this might be due to me not appending to IncludePath and LibraryPath, so I did that and changed the props files as follow:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LibraryPath>$(LibraryPath);$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
<IncludePath>$(IncludePath);$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LibraryPath>$(LibraryPath);$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
<IncludePath>$(IncludePath);$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LibraryPath>$(LibraryPath);$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
<IncludePath>$(IncludePath);$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LibraryPath>$(LibraryPath);$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
<IncludePath>$(IncludePath);$(BOOST_ROOT)\</IncludePath>
</PropertyGroup>
</Project>
Then reloading the project, results in missing inherited values, again.
I double checked to see if the macros are present, and they are (VC_ and WindowsSDK_ macros):
I also tried changing Directory.Build.props to Directory.Build.targets to make it load after the projects have been loaded, but then the file does not get loaded at all.
How can I make sure that my Directory.Build.props inherits the default values, and appends my custom options?
The reason I want to do this is because I'm migrating away from the deprecated Microsoft.Cpp.Win32.user.props file.
Changing the extention to .targets works only for the build process, but intellisense / visual Studio doesn't pick up on the include files, and shows a lot of error (before compilation). This is not preferable.


I think you cannot use
Directory.Build.propsto overwrite a system property in the Project Property UI.From your info, the
LibraryPathandIncludePathhas lost there values. Please note this info about the Import order ofDirectory.Build.props:Directory.Build.props is imported very early in Microsoft.Common.props, and properties defined later are unavailable to it. So, avoid referring to properties that are not yet defined (and will evaluate to empty).
Directory.Build.targets is imported from Microsoft.Common.targets after importing .targets files from NuGet packages. So, it can override properties and targets defined in most of the build logic, but sometimes you may need to customize the project file after the final import.
You can refer to this link.
In detail,
Directory.Build.propslike a step to initialize the project and always run beforeMicrosoft.Common.propswhich set default values to most of the system properties such asLibraryPathandIncludePath. So at the beginning,it is normal that the values are empty . After this, when it executes theMicrosoft.Common.props, it has this below:And you have add
$(BOOST_ROOT)\lib32-msvc-14.2toIncludepathin theDirectory.Build.props, so when you execute next step, theIncludepathhas a value, so it will skip the operation of assigning system values and do not overwrite the values in this step and causes this strange behavior.For
Directory.Build.targets, it performs the override operation at the end, when both the includepath and LibraryPath properties have got the system values, and there is no problem with the override. But you can only get these values when you run the project, as you showed later.In brief,
Directory.Build.propsis suitable for defining some properties which would be used or overwrote in later andDirectory.Build.targetssuits for overwriting the values which are already defined during build process.Suggestion
1) To set the include directories, you can add them into your INCLUDE environment variable. you can set the INCLUDE and LIB variables, like so:
And then add
/p:"VCBuildAdditionalOptions= /useenv"to MSBuild arguments so that it takes the INCLUDE and LIB variables.You can refer to this.
2) Or you can use your initial function in the path
C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.xxx.user.propsto add the extra includepath,librarypath in it like:Hope it could help you.