I tried using Directory.Build.props to setup some variables for use with our different project types.
<Project>
<PropertyGroup>
<!-- For SDK style c# projects -->
<ApmTargetFramework>net481</ApmTargetFramework>
</PropertyGroup>
<PropertyGroup>
<ApmTargetFrameworkVersion>v4.8.1</ApmTargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<!-- For APM multi-targeted projects-->
<ApmMultiTargetFrameworks>net6.0;net481</ApmMultiTargetFrameworks>
</PropertyGroup>
</Project>
For the sdk style projects both of these work:
<TargetFrameworks>$(ApmMultiTargetFrameworks)</TargetFrameworks>
and
<TargetFramework>$(ApmTargetFramework)</TargetFramework>
In the old-style csproj files it doesn't seem to be working:
<TargetFrameworkVersion>$(ApmTargetFrameworkVersion)</TargetFrameworkVersion>
It seems to be working in the SDK style projects with and without multi-targeting.
It seems like it is probably coming up as "blank" or empty in the old-style csproj files.
As a test, I tried manually setting a value in the UI.
This showed up in the project file as:
<TargetFrameworkVersion>v4.8.1</TargetFrameworkVersion>
Looking through some of the documentation here:
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).
When I looked, some of our project files did not include Microsoft.Common.props. We have some of our own .props files and I think someone might have removed Microsoft.Common.props.
e.g. files that did not include this, did not work with Directory.Build.props
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />