title: Is it possible to set the TargetFramework on the commandline with dotnet build / restore?
body: <p>I want to remove the TargetFramework specifier from my project files and pass it via the commandline. Sounds easy:</p>
  <pre><code>dotnet build -f net5
  </code></pre>
  <p>But the big problem is the NuGet aspect. Because</p>
  <pre><code>dotnet restore
  </code></pre>
  <p>complains about the missing framework:</p>
  <blockquote>
  <p>dotnet restore common\common.csproj
  Determining projects to restore...
  C:\Program Files\dotnet\sdk\5.0.400\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.TargetFrameworkInference.targets(92,5): error NETSDK1013: The <strong>TargetFramework value '' was not recognized.</strong> It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.</p>
  </blockquote>
  <p>The problem is that <code>dotnet restore</code> does not accept a TargetFamework argument. So I am forced to write the TargetFramework into the config file: Even worse, there is always a single NuGet restoration in the <code>obj</code> directories, so upon every switch between target frameworks I need to modify the config file and do a fresh restore. This is extremely cumbersome and I wonder how this can be avoided.</p>
  <p>If this cannot be solved I would kick out NuGet and reference the package assemblies directly.</p>