Firstly I'd say that since you're using the same value in all cases you don't need it to be in a conditional property group. Just set it directly in directory.build.props
or in a property group without a condition.
<PropertyGroup>
<PreferredToolArchitecture>x86</PreferredToolArchitecture>
</PropertyGroup>
Secondly, the .props
stuff (and directory.build.props
for that matter) run before your project's properties are applied. Project properties override these values. So if you're also setting this in your project file then the project file wins every time. If you need to force all projects to use a property irrelevant of what the project file actually says then the correct solution is to use a conditional check in the project file that says to use value X when property Y is not already set.
Alternatively you can overwrite the property values after the project properties have been loaded. But to do that you have to use a directory.build.targets
file instead. You'll need to hook into the build process after the project file has been loaded but before compilation. I'm not 100% sure on C++ projects but BeforeBuild
is a good starting point. Within the Target
set the property to the value you want. This will overwrite any previous assignment.
<Project>
<Target Name="UpdateArchitecture" BeforeTargets="BeforeBuild">
<PropertyGroup>
<PreferredToolArchitecture>x86</PreferredToolArchitecture>
</PropertyGroup>
</Target>
</Project>
If you need the actual value to be configurable then create a custom property in your directory.build.props
(or equivalent) file and then use that in the .targets
file to set the actual value that MSBuild will use.