Home

Ability to add references/nuget via comment/directives?

Internally we're starting to adopt the usage of a snippet manager for sharing snippets across our team. We have a fairly sizeable library currently of LinqPAD queries that we want to clean up and snippetize.

I appreciate how LinqPAD makes it easy to take "using" statements in pasted code and offers to move them to the query preferences. I was hoping that there'd be some similar functionality for adding references/nuget/dlls? I know in Azure Functions before they used the concept of #r "Newtonsoft.Json" as a csx directive to install and use Newtonsoft.Json as an example I was hoping that something like that, would be available. Maybe even as a documentary comment:

/// <PackageReference name="Newtonsoft.Json" />

As an example. It'd be cool to see this be used for other references too - like absolute paths to dll's or fully qualified GAC assemblies.

Related to this - it'd be great to have a single "copy" command that would capture all of the usings, the references, and potentially a flag to set the query type/connection information, in a single text blob, that could then be used to reconfigure a new query with basically the same settings.

Does LinqPAD have support for any of these other features besides the using directive bit?

Comments

  • I guess better question is can we support .csx script?

  • Full csx isn't really necessary at this point, while it may have merits. The first/most important thing I was hoping to find was if there was some supported syntax that would add nuget package references from pasted code. The rest of the features requested above would just be the cherry on top.

  • edited February 26

    I appreciate how LinqPAD makes it easy to take "using" statements in pasted code and offers to move them to the query preferences. I was hoping that there'd be some similar functionality for adding references/nuget/dlls? I know in Azure Functions before they used the concept of #r "Newtonsoft.Json" as a csx directive to install and use Newtonsoft.Json as an example I was hoping that something like that, would be available. Maybe even as a documentary comment:

    Based on the documentation for Azure Functions, #r "Newtonsoft.Json" works only because they've special-cased the Newtonsoft.Json package (along with a handful of others). As far as I know, there is no general standard for specifying NuGet references inside C# code.

    Related to this - it'd be great to have a single "copy" command that would capture all of the usings, the references, and potentially a flag to set the query type/connection information, in a single text blob, that could then be used to reconfigure a new query with basically the same settings.

    Pressing Ctrl+Shift+N (New Query, Same Properties) does this. Also, you can press F4 and click "Save as Snippet". This will save the queries properties (using directives, references, advanced properties - basically everything except the connection - and even pieces of code) to a .snippet file which you can later recall by typing the snippet name followed by the TAB key.

  • @JoeAlbahari - yeah, I knew there was some special handling for those, was just giving them as an example of a known syntax I've seen used to do that. But you're correct, I know of no well-defined standard for doing that.

    Thanks for the snippet info..... I might could hijack the "Save as Snippet" function to get me close to what I'm looking for. The end container for all of these snippets is a https://www.cacher.io/ instance for our team. So saving as a snippet locally isn't exactly what we're looking for. This may be a stopgap at least.

    My ultimate goal is that we have all of our miscellaneous queries/snippets/blobs of code for all languages in cacher, easily searchable, and when we find one we'd just hit the "Copy" button on that snippet and be able to paste it and run in LinqPAD (or whatever target program). Using the "Save as Snippet" I could save it in LinqPAD to a snippet, add that as the snippet file in cacher, and then using it would have to be downloading the snippet and saving it locally, then invoking it in LinqPAD.

    As a tangent, the entire reason we're coming to Cacher is because we use so many linqpad scripts, but without these things it was getting untenable to manage:

    • An easy way to sync them (we solved that by a synced sharepoint document library) across the team
    • The ability to have more than one "snippet"/"queries" location (think a team/personal folder)
    • The ability to tag/search them easily - we have a lot of cross cut topics, so a straightforward hierarchical organization really hasn't worked well for us
    • A minor one, but a feature we love in cacher is a code review process too for new snippets

    I recognize a lot of that is out of the scope of what LinqPAD does, but it's really such an instrumental part of my day-to-day, we had to come up with something to enhance it's usability for our team.

Sign In or Register to comment.