jcansdale / TestDriven.Net-Issues

Issue tracking for TestDriven.Net
https://github.com/jcansdale/TestDriven.Net-Issues/issues
24 stars 2 forks source link

Support `Test With > In-Proc (VS SDK)` targeting services that have been linked, not referenced #131

Closed jcansdale closed 6 years ago

jcansdale commented 6 years ago

For many Visual Studio services, TestDriven.Net is able to infer the service type from the service interface when targeting a method using Test With > In-Proc (VS SDK).

For example if you target the following method:

        [STAThread]
        void ShowActiveView(IVsTextManager textManager)
        {
            ErrorHandler.ThrowOnFailure(textManager.GetActiveView(1, null, out IVsTextView activeView));
            activeView.GetCaretPos(out int line, out int col);
            Console.WriteLine($"Caret is on line {line}");
        }

It is able to find the SVsTextManager type by using the IVs -> SVs naming convention and looking for it in the same assembly as IVsTextManager or one of its referenced assemblies. It can then call IServiceProvider.GetService and pass in the returned service object.

Unfortunately this breaks down when a service interface has been embedded as opposed to reference. In this case is doesn't know where to probe in order to find the service type.

Related

Here is the contents of Microsoft.VisualStudio.SDK.EmbedInteropTypes.targets:

<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <!-- This file can be deprecated when this issue is fixed:
       https://github.com/NuGet/Home/issues/2365
       and when the VS SDK NuGet packages have been updated to leverage the new feature.  -->
  <Target Name="LinkVSSDKEmbeddableAssemblies" AfterTargets="ResolveReferences" BeforeTargets="FindReferenceAssembliesForReferences">
    <ItemGroup>
      <ReferencePath Condition="
              '%(FileName)' == 'Microsoft.VisualStudio.Imaging.Interop.14.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Imaging.Interop.15.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Setup.Configuration.Interop'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Embeddable'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.10.0'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.11.0'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.12.0'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.12.1.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.14.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.15.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.15.3.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.15.5.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.15.6.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Shell.Interop.15.7.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.TextManager.Interop.11.0'
           or '%(FileName)' == 'Microsoft.VisualStudio.TextManager.Interop.12.0'
           or '%(FileName)' == 'Microsoft.VisualStudio.TextManager.Interop.12.1.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.TextManager.Interop.14.2.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.TextManager.Interop.15.1.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.Feedback.Interop.12.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.ProjectSystem.Interop'
           or '%(FileName)' == 'NuGet.VisualStudio'
           or '%(FileName)' == 'stdole'
           or '%(FileName)' == 'microsoft.visualstudio.designer.interfaces'
           or '%(FileName)' == 'EnvDTE80'
           or '%(FileName)' == 'EnvDTE90'
           or '%(FileName)' == 'EnvDTE100'
           or '%(FileName)' == 'Microsoft.VisualStudio.CommandBars'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Appid.Interop.10.0.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.10.0.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.11.0.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.14.0.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.14.1.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.14.2.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Interop.15.5.DesignTime'
           or '%(FileName)' == 'Microsoft.Internal.VisualStudio.Shell.Embeddable'
           or '%(FileName)' == 'Microsoft.VisualStudio.LicenseManagement.Interop.12.0.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.LicenseManagement.Interop.12.1.DesignTime'
           or '%(FileName)' == 'Microsoft.VisualStudio.LicenseManagement.Interop.14.0.DesignTime'
              ">
        <EmbedInteropTypes>true</EmbedInteropTypes>
      </ReferencePath>
    </ItemGroup>
  </Target>
</Project>