Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

155
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda