Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda