question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet cli passing -target:Restore to MSBuild instead of -restore

See original GitHub issue

As seen in: https://github.com/xamarin/net6-samples/pull/52

We have a multi-targeted project with:

<TargetFrameworks>net6.0-android;net6.0-ios</TargetFrameworks>

To deploy to an Android device/emulator (and not iOS), you can run:

> dotnet build -t:Run -p:TargetFramework=net6.0-android

With .NET 6.0.100-alpha.1.21064.27, this command fails with:

error MSB4057: The target "Run" does not exist in the project.

The MSBuild arguments the dotnet cli is passing seem odd:

-target:Restore -t:Run

With .NET 6.0.100-alpha.1.20562.2, it used to pass:

-restore -t:Run

In fact, you can workaround the problem by doing:

> dotnet build -t:Run -p:TargetFramework=net6.0-android --no-restore

I tried creating other, simpler projects to reproduce this issue, but a console app with TargetFrameworks=net5.0;net6.0 works fine. I always see -restore being passed.

I think it is something to with .NET workloads and multi-targeting at the same time?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:15 (13 by maintainers)

github_iconTop GitHub Comments

1reaction
dsplaistedcommented, Mar 9, 2021

@sfoslund Could you work on fixing this? I tried, but ran into issues where an argument such as -t:Run got interpreted as the SlnOrProjectArgument by the parser, and thus wasn’t handled correctly by RestoringCommand.

Here is the change I made, which added some test coverage and tried to fix RestoringCommand: https://github.com/dsplaisted/sdk/commit/ad79b3f866829dba3ca4dd35e6edd3897b7bd460

1reaction
dsplaistedcommented, Mar 9, 2021

So theoretically I think switching to system.commandline “fixed” this bug in that now we try to use a separate restore command when the target framework is specified on the command line. However, this has created a bug here such that we pass the -t:run option to the separate restore command and it fails because we didn’t specify a target framework.

It seems like Sarah was correct here. Fixing one bug (It sounds like RestoringCommand wasn’t correctly detecting when it needed to run a separate restore command) exposed another bug. The new bug is that additional targets specified (such as Run) get passed through to the restore command, when they should be filtered out and only passed to the actual command run after the restore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet build command - .NET CLI
This command supports the dotnet restore options when passed in the long form (for example, --source ). Short form options, such as -s ......
Read more >
.net - Is it possible to set the TargetFramework ...
3. Try dotnet restore -p:TargetFramework=net5.0 · I would say that works! The-p switch appears to be undocumented (learn.microsoft.com/en-us/ ...
Read more >
Free style Jenkins build issue for net core application
Using below command MSBUILD. Exe /target:restore /target:build %workspace© Only restore alone happening Target build not executing But build ...
Read more >
Setting up a build with NUKE
Let's take a look at NUKE, a cross-platform build automation system with C# DSL. We'll use it to define the build for a...
Read more >
Automate your .NET project builds with NUKE a cross- ...
With such an execution plan defined by our targets, we can see that the Clean target is executed before the Restore target and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found