Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add target framework information to the AttachDebugger callback #3701

Merged
merged 23 commits into from
Jun 6, 2022

Conversation

nohwnd
Copy link
Member

@nohwnd nohwnd commented May 31, 2022

Description

Add target framework information to the attach debugger callback so IDE (like VS) don't have to guess what engine to use for a given dll. This will either keep the information that is sent by testhost, or if the target framework is kept at the default, it will use the target framework of the given testhost.

Lot of the changes are because the interfaces that are used internally are also public, and so I can't really force ITestRuntimeProvider to tell me what framework it is running as.

Some steps towards additional compatibility work are done here. This PR introduces a new message, that is expandable EditorAttachDebugger2, that replaces EditorAttachDebugger that just carries an int. On the edge of the process we decide what message should be sent, to keep the message compatible.

Then in TranslationLayer, we are adapting the new message for use with either of the launcher implementations.

Adding new versions of interfaces is not great, but doing it properly is difficult when we have multiple non-expandable messages, so I want to give myself some more time to come up with a good design.

@nohwnd nohwnd marked this pull request as draft May 31, 2022 16:58
@nohwnd
Copy link
Member Author

nohwnd commented May 31, 2022

Just a draft right now, won't even build because of public apis. I could probably make the custom launcher use internal interface that has single verison of api as well, and then adapt it for use in FrameworkHandle and logger, but it was just references in too many places.

@nohwnd nohwnd mentioned this pull request Jun 1, 2022
2 tasks
@nohwnd nohwnd marked this pull request as ready for review June 3, 2022 07:25
@nohwnd nohwnd enabled auto-merge (squash) June 3, 2022 07:27
Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces.AttachDebuggerInfo.TargetFramework.set -> void
Microsoft.VisualStudio.TestPlatform.ObjectModel.Client.Interfaces.AttachDebuggerInfo.Version.get -> System.Version
Copy link
Member Author

@nohwnd nohwnd Jun 3, 2022

Choose a reason for hiding this comment

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

all those apis were marked as obsolete before, we can safely change them. And will probably mark them as obsolete again, while we pilot this with VS.

@@ -21,7 +21,7 @@ namespace TestPlatform.Playground;

internal class Program
{
static void Main(string[] args)
Copy link
Member

Choose a reason for hiding this comment

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

Is there any particular reason that prompted this change ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, because args are not used.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just revert all code in Playground before merging as always (unless I forget, as usual :D).


[TestClass]
public class UnitTest1
[ExtensionUri("uri://myadapter")]
Copy link
Member

Choose a reason for hiding this comment

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

Can we give this adapter a more suggestive name ? Asking because it will probably end up in the telemetry data and it would be nice to know it's ours.

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just revert all code in Playground before merging as always (unless I forget, as usual :D).

Copy link
Member Author

Choose a reason for hiding this comment

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

This won't end up in approved telemetry, and in unapproved telemetry anyone can post anything so it does not really matter.

@@ -1,18 +1,47 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.VisualStudio.TestTools.UnitTesting;
Copy link
Member

Choose a reason for hiding this comment

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

Don't know where to write this comment so I'll write it here. Given that this file no longer contains unit tests, should we change the name from UnitTest1.cs to something else ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just revert all code in Playground before merging as always (unless I forget, as usual :D).


@"C:\p\vstest\playground\MSTest1\bin\Debug\net472\MSTest1.TestAdapter.dll",

// @"C:\t\TestProject13_\TestProject1\bin\Debug\net48\TestProject1.dll",
Copy link
Member

Choose a reason for hiding this comment

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

Can we remove those commented-out sections ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just revert all code in Playground before merging as always (unless I forget, as usual :D).

<PropertyGroup>
<TestPlatformRoot Condition="$(TestPlatformRoot) == ''">..\..\</TestPlatformRoot>
<TargetLatestRuntimePatch>true</TargetLatestRuntimePatch>
<!-- MSB3270 Suppress warnings about testhost being x64 (AMD64)/x86 when imported into AnyCPU (MSIL) projects. -->
Copy link
Member

Choose a reason for hiding this comment

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

Is there anything we can do about those warnings so that their suppression is no longer needed ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I will just revert all code in Playground before merging as always (unless I forget, as usual :D). Also it it a file auto generated by VS. Not sure what started happening, but I see - Backup generated into my project from the dogfooding VS quite often lately.

Copy link
Member

Choose a reason for hiding this comment

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

@nohwnd What about adding a git exclusion for backup projects?

@@ -27,4 +25,22 @@ public TestProcessAttachDebuggerPayload(int pid)
/// </summary>
[DataMember]
public int ProcessID { get; set; }

[DataMember]
// Added in version 7.
Copy link
Member

Choose a reason for hiding this comment

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

Would the use of ProtocolVersion attribute make sense here ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I commented the same thing above. I just did not want to fiddle with usings, and adding too many overloads for that attribute, I will do that later.

@@ -1436,16 +1438,46 @@ private void AttachDebuggerToProcess(ITestHostLauncher customHostLauncher, Messa

try
{
var pid = _dataSerializer.DeserializePayload<int>(message);
// Handle EditorAttachDebugger2.
if (message.MessageType == MessageType.EditorAttachDebugger2)
Copy link
Member

Choose a reason for hiding this comment

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

Can we employ a Builder pattern here ? Seeing the code is mostly identical for the two message types but the only relevant difference is the way we build the AttachDebuggerInfo object, it looks like we can avoid duplicating code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let's merge it as is, and you can definitely PR a more elegant code, because I don't see one.

Co-authored-by: Amaury Levé <amaury.leve@gmail.com>
@nohwnd nohwnd disabled auto-merge June 6, 2022 11:43
@nohwnd nohwnd merged commit 27ea06b into microsoft:main Jun 6, 2022
@nohwnd nohwnd deleted the add-info-to-debugger branch June 6, 2022 11:44
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.

3 participants