diff --git a/src/Cli/dotnet/Commands/Run/RunCommand.cs b/src/Cli/dotnet/Commands/Run/RunCommand.cs index 92ce418923a1..71c142ae9e0d 100644 --- a/src/Cli/dotnet/Commands/Run/RunCommand.cs +++ b/src/Cli/dotnet/Commands/Run/RunCommand.cs @@ -259,6 +259,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(RunCommandSelector select { globalProperties["Device"] = Device; var properties = new Dictionary { { "Device", Device } }; + selector.InvalidateGlobalProperties(properties); var additionalProperties = new ReadOnlyDictionary(properties); MSBuildArgs = MSBuildArgs.CloneWithAdditionalProperties(additionalProperties); } @@ -319,6 +320,8 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(RunCommandSelector select _restoreDoneForDeviceSelection = false; } + // Update the selector's global properties so DeployToDevice and other targets see the Device + selector.InvalidateGlobalProperties(properties); var additionalProperties = new ReadOnlyDictionary(properties); MSBuildArgs = MSBuildArgs.CloneWithAdditionalProperties(additionalProperties); } diff --git a/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsDevice.cs b/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsDevice.cs index 68ac24240d3e..e195eccc2cd4 100644 --- a/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsDevice.cs +++ b/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsDevice.cs @@ -296,10 +296,17 @@ public void ItCallsDeployToDeviceTargetWhenDeviceIsSpecified() result.Should().Pass() .And.HaveStdOutContaining($"Device: {deviceId}"); - // Verify the binlog file was created and the DeployToDevice target ran + // Verify the binlog file was created and the DeployToDevice target ran with the correct Device property File.Exists(binlogPath).Should().BeTrue("the binlog file should be created"); AssertTargetInBinlog(binlogPath, "DeployToDevice", - targets => targets.Should().NotBeEmpty("DeployToDevice target should have been executed")); + targets => + { + targets.Should().NotBeEmpty("DeployToDevice target should have been executed"); + var messages = targets.First().FindChildrenRecursive(); + var deployMessage = messages.FirstOrDefault(m => m.Text.Contains("DeployToDevice: Deployed to device")); + deployMessage.Should().NotBeNull("the DeployToDevice target should have logged the device"); + deployMessage.Text.Should().Contain(deviceId, "the Device property should be passed to DeployToDevice"); + }); } [Fact] @@ -353,9 +360,18 @@ public void ItCallsDeployToDeviceTargetWhenDeviceIsAutoSelected() // Verify the binlog file was created File.Exists(binlogPath).Should().BeTrue("the binlog file should be created"); - // DeployToDevice target should have been called since a device was selected + // DeployToDevice target should have been called with the correct Device and RuntimeIdentifier AssertTargetInBinlog(binlogPath, "DeployToDevice", - targets => targets.Should().NotBeEmpty("DeployToDevice target should have been executed when a device is selected")); + targets => + { + targets.Should().NotBeEmpty("DeployToDevice target should have been executed when a device is selected"); + var messages = targets.First().FindChildrenRecursive(); + var deployMessage = messages.FirstOrDefault(m => m.Text.Contains("DeployToDevice: Deployed to device")); + deployMessage.Should().NotBeNull("the DeployToDevice target should have logged the device"); + deployMessage.Text.Should().Contain("single-device", "the auto-selected Device should be passed to DeployToDevice"); + // The single-device has RuntimeIdentifier="$(NETCoreSdkRuntimeIdentifier)" which resolves to the current SDK RID + deployMessage.Text.Should().Contain(RuntimeInformation.RuntimeIdentifier, "the RuntimeIdentifier from the device should be passed to DeployToDevice"); + }); } [Fact]