Home

Sharing Additional References and Namespace Imports with a team

I want to set up a default environment where LINQPad automatically references some of our assemblies and imports some commonly-used namespaces. I want to add this to source control, so that everyone on the team can easily start using this environment and we can track changes to it.

What I've done so far is to add LINQPad.exe to source control with a plugins sub-folder containig MyExtensions.FW46.linq, which contains relative paths, like this:

<Reference>..\..\Build\OurDll.dll</Reference>

It seems to be relative to the working directory, so it works if I launch LINQPad.exe by double-clicking on it in Explorer, but not if I double-click a .linq file in another directory, for instance. Is there a better way to do this? For example, is there a special directory like for the location of LINQPad.exe? That would do the trick.

The other problem is namespace imports. Unlike References, the Namespace Imports configured for My Extensions don't seem to be applied to new queries. (I'm not sure why it's different.) Is there an easy way share Imports? I know I can click "Set as default for new queries", but that only saves them for me, not for everyone.

Comments

  • take a look at %AppData%\LINQPad\DefaultQuery.xml
  • Yes, that's where the defaults are stored, but this is under the user's profile directory. Is there a way to get LINQPad to read it from a sub-directory of the EXE, like it reads My Extensions from the plugins sub-directory?
  • EM0EM0
    edited April 2016
    I tried setting Util.CurrentQuery.NamespaceImports, but it throws a NullReferenceException. :( Stack trace:

    at LINQPad.ObjectModel.Query.get_FileReferences()
    at LINQPad.ObjectModel.Query.ToQueryCore()
    at LINQPad.ObjectModel.Query.get_QueryCore()
    at LINQPad.ObjectModel.Query.set_NamespaceImports(IEnumerable`1 value)

    Same if I try to set Util.CurrentQuery.FileReferences.
  • Regarding the first part of your question, I don't understand how this can possibly work. If you start LINQPad by double-clicking a .linq file, it's up to Windows as to which copy of LINQPad.exe it starts, and this is determined by how the .LINQ file extension has been registered. So if the .LINQ file extension is associated with %programfiles%\LINQPad 5\LINQPad.exe, for instance, then this is the version that will always be started when you double click a .LINQ file.

    Regarding namespace imports, there's no solution to this right now. However, I can easily modify LINQPad so that it first looks for DefaultQuery.xml in the folder where LINQPad.exe is run, before looking in %userdata%\LINQPad. This would solve your problem, because DefaultQuery.xml contains default namespaces and references for new queries. However, your users would still need to start LINQPad by double-clicking your special copy of LINQPad.exe, rather than double-clicking a .LINQ file.

  • I have 'solved' this by placing LINQPad.exe in the queries folder and opening the file via explorer: drag the .linq file and drop it on the LINQPad executable.

    This overrides the default file association and doesn't require you to (e.g.) create a batch script for every LINQ file.

    Make sure LINQPad.exe is not running because it won't start a new instance if so.

    As with the 'Plugins' folder, it would be great if the DefaultQuery.xml would be used when placed in the execution folder.
  • My original post was meant to say: is there a special directory like <RuntimeDirectory> for the location of LINQPad.exe? The forum software seems to have swallowed the "HTML tag", completely changing the meaning. :) In other words, I'm looking for a way to make the reference paths relative to the LINQPad.exe path, rather than to the working directory.

    > I can easily modify LINQPad so that it first looks for DefaultQuery.xml in the folder where LINQPad.exe is run

    Yes, I think this would be a good start.

    A potential problem is that it would make it hard for users to override the team-shared settings if they want to. Ideally, DefaultQuery.xml in the LINQPad.exe directory would be the default, but users would have a way to say "no, use my settings" (i.e. the DefaultQuery.xml in %APPDATA%).
  • No, there's no token for the LINQPad directory. (Although any assemblies that you place directly in the LINQPad folder will be found automatically.)
  • OK, thanks. Do you think you could add one?

    I guess a workaround would be to add a batch file that changes the working directory to its own location (CD "%~dp0") and then runs LINQPad.exe.
  • Does Assembly.GetCallingAssembly().Location return what you need?
  • I've just uploaded a new LINQPad beta that allows you to localize the default references and namespaces:

    http://www.linqpad.net/download.aspx#beta

    I've also now written documentation on xcopy-deployment:
    http://www.linqpad.net/PortableDeployment.aspx
  • Great, thank you! That worked for me.
Sign In or Register to comment.