Search code examples
linqpad

Is it possible to use environment variables in references of a linqpad script?


My team has a lot of linqpad scripts that we share through a git repository. We use references to our own codebase of which the local path may differ per member of our team. So if we want to run such a script we need to edit its references first to point to the correct location. Example of such a reference:

D:\git_repos\codebase\bin\example.dll

I tried using an environment variable set to the location of our codebase. E.g.:

%codebase%\bin\example.dll

This seems to work, Linqpad will load the DLLs correctly. However, when I save the script it saves the expanded version of the environment variable. Is it possible to stop LINQPad from storing the expanded versions of the environment variables in the References? If not, is there an alternative approach?


Solution

  • There's nothing built-in that will let you do this in linqpad automagically.

    However, I wrote a script for cleaning out the <Connection> info from linqpad scripts for commiting to a repo.

    It really wouldn't take much to modify it to expand environment-variable-reference tags temporarily then revert when done. Or Conversely, modify it to replace all established relative or absolute paths with something derived from expanding environment variables for auto revert when you stop running the script.