Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Cli/dotnet/Commands/Run/RunCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ private bool TrySelectTargetFrameworkAndDeviceIfNeeded(RunCommandSelector select
{
globalProperties["Device"] = Device;
var properties = new Dictionary<string, string> { { "Device", Device } };
selector.InvalidateGlobalProperties(properties);
var additionalProperties = new ReadOnlyDictionary<string, string>(properties);
MSBuildArgs = MSBuildArgs.CloneWithAdditionalProperties(additionalProperties);
}
Expand Down Expand Up @@ -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<string, string>(properties);
MSBuildArgs = MSBuildArgs.CloneWithAdditionalProperties(additionalProperties);
}
Expand Down
24 changes: 20 additions & 4 deletions test/dotnet.Tests/CommandTests/Run/GivenDotnetRunSelectsDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message>();
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]
Expand Down Expand Up @@ -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<Message>();
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]
Expand Down
Loading