Skip to content

Conversation

@jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Dec 10, 2025

c164a9b is mostly working with two issues I've discovered while testing:

  1. If ComputeAvailableDevices requires Restore to have run (which is actually the case for iOS and Android), dotnet run would fail unless you did an explicit dotnet restore first:
D:\src\helloandroid> D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\dotnet.exe run -bl
  failed with 1 error(s) (0.1s)
  D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1004: Assets file 'D:\src\helloandroid\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

We can test this by changing DotnetRunDevices.csproj:

<Target Name="ComputeAvailableDevices" DependsOnTargets="ResolveFrameworkReferences">

Doing an explicit Restore step before ComputeAvailableDevices resolves this.

  1. We were not passing all loggers to ProjectInstance.Build() calls in RunCommandSelector, so no logging output was shown during device computation. This is now fixed by creating a fresh console logger each time we call Build().

I tested this manually with a console app with a ComputeAvailableDevices target and a lengthy sleep:

helloconsole                 ComputeAvailableDevices (9.1s)

Comment on lines +307 to +309
// If the device added a RuntimeIdentifier, we need to re-restore with that RID
// because the previous restore (if any) didn't include it
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is only true if that runtime identifier isn't already part of the RuntimeIdentifiers list, no?

Copy link
Member Author

@jonathanpeppers jonathanpeppers Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just tested it, I think we can take this out. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once I fixed the bug copilot had found, it is needed in a test that selects:

<Devices Include="test-device-1" Description="Test Device 1" Type="Emulator" Status="Online" RuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)" />

Error is:

Microsoft.PackageDependencyResolution.targets(266,5): 
      error NETSDK1047: Assets file 'D:\src\dotnet\sdk\artifacts\tmp\Debug\testing\ItAutoSelects---A128676A\obj\project.assets.json' doesn't have a target for 'net10.0/win-x64'. Ensure that restore has run and that you have included 'net10.0' in the TargetFrameworks for your project. You may also need to include 
      'win-x64' in your project's RuntimeIdentifiers.

I think this could actually happen on iOS or Android if you build without a RID and then select a device.

c164a9b is mostly working with two issues I've discovered while testing:

1. If `ComputeAvailableDevices` requires `Restore` to have run (which
   is actually the case for iOS and Android), `dotnet run` would fail
   unless you did an explicit `dotnet restore` first:

    D:\src\helloandroid> D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\dotnet.exe run -bl
      failed with 1 error(s) (0.1s)
      D:\src\dotnet\sdk\artifacts\bin\redist\Debug\dotnet\sdk\11.0.100-dev\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(266,5): error NETSDK1004: Assets file 'D:\src\helloandroid\obj\project.assets.json' not found. Run a NuGet package restore to generate this file.

We can test this by changing `DotnetRunDevices.csproj`:

    <Target Name="ComputeAvailableDevices" DependsOnTargets="ResolveFrameworkReferences">

Doing an explicit `Restore` step before `ComputeAvailableDevices`
resolves this.

2. We were not passing loggers `ProjectInstance.Build()` calls in
   `RunCommandSelector`, so no logging output was shown during device
   computation. This is now fixed by creating a fresh console logger
   each time we call `Build()`.

I tested this manually with a console app with a
`ComputeAvailableDevices` target and a lengthy sleep:

    helloconsole                 ComputeAvailableDevices (9.1s)
@jonathanpeppers
Copy link
Member Author

There were some full framework tests that seem unrelated:

EXEC : error : Could not read the Windows SDK's Platform.xml at C:\Program Files (x86)\Windows Kits\10\Platforms\UAP\10.0.19041.0\Platform.xml [C:\h\w\A1B308E0\t\dotnetSdkTests\qionsq55.0dh\ManagedWinRTC---79256FB9\ManagedWinRTComponent\ManagedWinRTComponent.csproj]

I reran, to just see if that helps.

@baronfel
Copy link
Member

@jonathanpeppers I've been seeing that one too on unrelated things - @dotnet/domestic-cat do you know if there's a known build issue about this and/or something we need to get someone to look at?

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes two issues in the dotnet run device selection feature: (1) adding explicit Restore before ComputeAvailableDevices when the target depends on restored assets (like ResolveFrameworkReferences for iOS/Android), and (2) ensuring MSBuild logging output is shown during device computation by passing loggers to all ProjectInstance.Build() calls.

Key Changes:

  • RunCommandSelector now performs Restore before computing available devices (unless --no-restore is specified) and tracks whether restore was performed to avoid redundant operations
  • MSBuild loggers (console and binary) are now passed to all Build() calls through a new GetLoggers() method
  • Test project updated to simulate real-world scenario where ComputeAvailableDevices depends on ResolveFrameworkReferences

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
test/TestAssets/TestProjects/DotnetRunDevices/DotnetRunDevices.csproj Added DependsOnTargets="ResolveFrameworkReferences" to ComputeAvailableDevices target to test restore requirement
src/Cli/dotnet/Commands/Run/RunCommandSelector.cs Added restore logic before device computation, logger support via GetLoggers() method, and restoreWasPerformed tracking parameter
src/Cli/dotnet/Commands/Run/RunCommand.cs Added _restoreDoneForDeviceSelection field and logic to skip redundant restore in build phase when already performed during device selection

jonathanpeppers and others added 2 commits December 10, 2025 13:48
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers enabled auto-merge (squash) December 11, 2025 21:47
@jonathanpeppers jonathanpeppers merged commit 49c0d73 into main Dec 11, 2025
26 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/peppers/Restore-ComputeAvailableDevices branch December 11, 2025 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants