Home
Options

Writing custom visualizer for Linqpad 6

I want to upgrade my custom visualizer to support LINQPad 6 and have some questions about it. Currently it references LINQPad nuget. Do I need to now reference LINQPad.Runtime instead?

Is there a way to support both LINQPad 5 and 6 from a single nuget package ?

Comments

  • Options
    edited January 2020

    Add a reference to the LINQPad.Reference NuGet package - this contains reference assemblies for both versions of LINQPad.

    To create a NuGet package that works for both LINQPad 5 and 6, you must instruct VS to include assemblies for both .NET Framework (for LINQPad 5) and .NET Core (for LINQPad 6). Start by creating a multi-targeting project as follows:

    <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
    
        <PropertyGroup>
            <TargetFrameworks>netcoreapp3.0;net46</TargetFrameworks>
            <UseWpf>true</UseWpf>
            <AssemblyName>YourAssemblyName</AssemblyName>
            <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
        </PropertyGroup>
    
        <PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
            <DefineConstants>NETCORE</DefineConstants>
        </PropertyGroup>
    
        <ItemGroup>
            <PackageReference Include="LINQPad.Reference" Version="1.*" />
        </ItemGroup>
    
        <ItemGroup Condition="'$(TargetFramework)' == 'net46'">
            <Reference Include="System.Xaml">
                <RequiredTargetFramework>4.0</RequiredTargetFramework>
            </Reference>
            <Reference Include="WindowsBase" />
            <Reference Include="PresentationCore" />
            <Reference Include="PresentationFramework" />
        </ItemGroup>
    
    </Project>
    

    When you build, VS will automatically create a NuGet package whose lib folder contains both net46 and netcoreapp3.0 subfolders (net46 for LINQPad 5 and netcoreapp3.0 for LINQPad 6).

    If you need to do anything differently for LINQPad 5 vs 6, use the conditional compilation symbol defined in the project file above (NETCORE).

  • Options

    Does the above approach works if I want to use WinForms instead of Wpf?

  • Options
    edited January 2020

    Yes: add

    <UseWindowsForms>true</UseWindowsForms> 
    

    to your project file and add net46 references to System.Drawing and System.Windows.Forms.

  • Options

    What is object that is returned by Util.CurrentDataContext ? Previously it was DataContextBase but that type is missing from the .net core version of the LINQPad.Reference library.

  • Options
    edited January 2020

    In LINQPad 6, the built-in data context drivers have been completely decoupled from the runtime, so LINQPad.Runtime now has no concept of DataContextBase (which was based on LINQ-to-SQL's DataContext class).

    A benefit of this decoupling is that Util.CurrentDataContext now works for queries that use a different driver. For example if your query uses the built-in Entity Framework Core driver, Util.CurrentDataContext will return a DbContext object (whereas in LINQPad 5, it would return null). The same applies for third-party drivers.

    If you want to access properties of Util.CurrentDataContext, the safest option is to use dynamic binding or reflection.

  • Options

    I see. How does Linq to SQL work in Linqpad 6 ? As I saw it's not supported by .net core

  • Options

    That's right - they removed LINQ-to-SQL for .NET Core. LINQPad uses a forked version:
    https://github.com/albahari/LinqToSQL2

  • Options

    I guess there is no NuGet package for it right ?

  • Options

    There's no NuGet package. Is there a scenario that you can't easily solve with dynamic binding?

  • Options

    The current version of my visualizer depends on System.Data.Linq so I would need to make some changes to make it work again with dynamic binding

  • Options

    Let me know if you run into any blocking issues with dynamic binding (such as having to implement an interface).

  • Options

    Is EF 6 or 5 still supported by LINQPad 6 ?

  • Options

    LINQPad 6 does not support EF 5 or 6. EF 5 is .NET Framework-only, so that will never be an option. MS have recently released EF 6.3 for .NET Core, so it would be possible in theory to write a EF 6.3 driver for LINQPad 6, but it would only work for EF 6.3 projects that target .NET Core rather than .NET Framework.

  • Options

    Looks like there is no way to get the command from an iqueryable instance: Add interceptor on an existing DbContext item so I won't be able to make the visualizer work unless the user creates the context manually and adds an interceptor in the OnConfiguring method

    Maybe you can provide some kind of hook where either users or visualizer author can add options while the DbContext is being created in the OnConfiguring method ?

  • Options

    Or wait for EF Core 5 which solves the issue of getting command from IQueryable

  • Options

    @JoeAlbahari I have a nuget package that i'm trying to update to support both. The one thing I'm stuck on is PanelManager doesn't seem to be public in the new LinqPad.runtime package? Is there a recommendation?

    https://github.com/NMyVision/LinqPad.JsonVisualizer/blob/master/src/JsonVisualizer/JsonVisualizer.cs#L54

  • Options

    Nevermind, figured it out.

    #if NETCORE
        tv.Dump(title);
    #else
        LINQPad.PanelManager.DisplayControl(tv, title);            
    #endif
    
  • Options

    In this case, you don't even need the conditional: tv.Dump(title) will work for both LINQPad 5 and 6.

    The reason for not being able to access PanelManager is that LINQPad.Runtime does not have any desktop dependencies - those are now in LINQPad.Runtime.UI. Should it be necessary, I can publish LINQPad.Runtime.UI to NuGet, too.

Sign In or Register to comment.