[dotnet-run] fix logging and Restore for device selection#52113
[dotnet-run] fix logging and Restore for device selection#52113jonathanpeppers merged 4 commits intomainfrom
Restore for device selection#52113Conversation
| // If the device added a RuntimeIdentifier, we need to re-restore with that RID | ||
| // because the previous restore (if any) didn't include it |
There was a problem hiding this comment.
this is only true if that runtime identifier isn't already part of the RuntimeIdentifiers list, no?
There was a problem hiding this comment.
Just tested it, I think we can take this out. 👍
There was a problem hiding this comment.
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)
ca5a917 to
880d09a
Compare
|
There were some full framework tests that seem unrelated: I reran, to just see if that helps. |
|
@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? |
There was a problem hiding this comment.
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:
RunCommandSelectornow performs Restore before computing available devices (unless--no-restoreis 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 newGetLoggers()method - Test project updated to simulate real-world scenario where
ComputeAvailableDevicesdepends onResolveFrameworkReferences
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 |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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)
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)
c164a9b is mostly working with two issues I've discovered while testing:
ComputeAvailableDevicesrequiresRestoreto have run (which is actually the case for iOS and Android),dotnet runwould fail unless you did an explicitdotnet restorefirst:We can test this by changing
DotnetRunDevices.csproj:Doing an explicit
Restorestep beforeComputeAvailableDevicesresolves this.ProjectInstance.Build()calls inRunCommandSelector, so no logging output was shown during device computation. This is now fixed by creating a fresh console logger each time we callBuild().I tested this manually with a console app with a
ComputeAvailableDevicestarget and a lengthy sleep: