title: Only build one TargetFramework while defining multiple <TargetFrameworks> to support custom builds for other TargetFramework
body: <p>The idea is simple:
  I want to have a single project file, that can build multiple target frameworks and have references to different DLLs based on the framework used.</p>
  <p>The issue that I am running into, is that when I select build on the project, it will build all frameworks defined in  - but the .DLL referenced is newer than one of those target frameworks (which I need to build the same project with an older framework)</p>
  <p>I only want to build a single framework automatically, then build the others manually.</p>
  <pre><code>&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot; InitialTargets=&quot;Test&quot;&gt;
    &lt;Target Name=&quot;Test&quot;&gt;
      &lt;Message Importance=&quot;high&quot; Text=&quot;-- Building $(MSBuildProjectFile), TF=$(TargetFramework), Config=$(Configuration), Version=$(MyCustomVersion) --&quot; /&gt;
    &lt;/Target&gt;
    &lt;PropertyGroup&gt;
      &lt;TargetFrameworks&gt;net472;net48&lt;/TargetFrameworks&gt;
      &lt;MyCustomVersion Condition=&quot;'$(MyCustomVersion)' == ''&quot;&gt;2022&lt;/MyCustomVersion&gt;
      &lt;OutputPath&gt;bin\$(Configuration)\$(MyCustomVersion)\&lt;/OutputPath&gt;
      &lt;Configurations&gt;Debug;Release&lt;/Configurations&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=&quot;'$(MyCustomVersion)' == '2021' &quot;&gt;
      &lt;PlatformTarget&gt;x64&lt;/PlatformTarget&gt;
      &lt;DefineConstants&gt;$(DefineConstants);V2021&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=&quot;'$(MyCustomVersion)' == '2021' &quot;&gt;
      &lt;PlatformTarget&gt;x64&lt;/PlatformTarget&gt;
      &lt;DefineConstants&gt;$(DefineConstants);V2021&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=&quot;'$(MyCustomVersion)' == '2021' &quot;&gt;
      &lt;PlatformTarget&gt;x64&lt;/PlatformTarget&gt;
      &lt;DefineConstants&gt;$(DefineConstants);V2021&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
    &lt;PropertyGroup Condition=&quot;'$(MyCustomVersion)' == '2022' &quot;&gt;
      &lt;PlatformTarget&gt;x64&lt;/PlatformTarget&gt;
      &lt;DefineConstants&gt;$(DefineConstants);V2022&lt;/DefineConstants&gt;
    &lt;/PropertyGroup&gt;
    &lt;ItemGroup Condition=&quot;'$(MyCustomVersion)' == '2022' &quot;&gt;
      &lt;Reference Include=&quot;Some48API&quot;&gt;
        &lt;HintPath&gt;path\to\Some48API.dll&lt;/HintPath&gt;
        &lt;Private&gt;False&lt;/Private&gt;
      &lt;/Reference&gt;
    &lt;/ItemGroup&gt;
    &lt;Target Name=&quot;BuildOthers&quot; BeforeTargets=&quot;DispatchToInnerBuilds&quot; Condition=&quot;'$(MyCustomVersion)' == '2022'&quot;&gt;
      &lt;Message Importance=&quot;high&quot; Text=&quot;*** building 2019 ***&quot; /&gt;
      &lt;MSBuild Projects=&quot;$(MSBuildProjectFile)&quot; Properties=&quot;Configuration=$(Configuration);TargetFramework=net472;MyCustomVersion=2019&quot; /&gt;
      &lt;Message Importance=&quot;high&quot; Text=&quot;*** building 2020 ***&quot; /&gt;
      &lt;MSBuild Projects=&quot;$(MSBuildProjectFile)&quot; Properties=&quot;Configuration=$(Configuration);TargetFramework=net472;MyCustomVersion=2020&quot; /&gt;
      &lt;Message Importance=&quot;high&quot; Text=&quot;*** building 2021 ***&quot; /&gt;
      &lt;MSBuild Projects=&quot;$(MSBuildProjectFile)&quot; Properties=&quot;Configuration=$(Configuration);TargetFramework=net48;MyCustomVersion=2021&quot; /&gt;
    &lt;/Target&gt;
  &lt;/Project&gt;
  </code></pre>
  <p>In the above project file, I have two TargetFrameworks: net472 and net48.
  If I instead replace that with <code>&lt;TargetFramework&gt;net48&lt;/TargetFramework&gt;</code> (and modify BeforeTargets=&quot;DispatchToInnerBuilds&quot; to BeforeTargets=&quot;PreBuildEvent&quot;), I will get a compile error</p>
  <pre><code>0&gt;C:\Program Files\dotnet\sdk\6.0.202\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(267,5): Error NETSDK1005 : Assets file 'C:\Users\me\source\repos\Solution1\ClassLibrary1\obj\project.assets.json' doesn't have a target for 'net472'. Ensure that restore has run and that you have included 'net472' in the TargetFrameworks for your project.
  </code></pre>
  <p>So it seems like I need to provide both  but I don't want to <em>build</em> both of them without my own custom control over it...</p>
  <p>This issue is inspired by <a href="https://TheBuildingCoder" rel="nofollow noreferrer">TheBuildingCoder</a> and specifically the RevitAPI dll files are net48 only for 2021/2022 - so I don't want to build net47 as I get compile errors due to broken reference...</p>