Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

557
Views
Is it possible to set the TargetFramework on the commandline with dotnet build / restore?

I want to remove the TargetFramework specifier from my project files and pass it via the commandline. Sounds easy:

dotnet build -f net5

But the big problem is the NuGet aspect. Because

dotnet restore

complains about the missing framework:

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 TargetFramework value '' was not recognized. It may be misspelled. If not, then the TargetFrameworkIdentifier and/or TargetFrameworkVersion properties must be specified explicitly.

The problem is that dotnet restore 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 obj 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.

If this cannot be solved I would kick out NuGet and reference the package assemblies directly.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Since dotnet restore and dotnet build are wrappers around dotnet msbuild, you can use all MSBuild switches to change behavior of build system.

Here we need to set target framework, which can be done by

  • setting property in project file: <TargetFramework>net5.0</TargetFramework>

OR

  • setting property through command line docs: dotnet restore -p:TargetFramework=net5.0

OR

  • setting environment variable which is not recommended (by me)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!