Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linqpad

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?

like image 719
Kebabbi Avatar asked Oct 18 '25 18:10

Kebabbi


2 Answers

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.

like image 103
Maslow Avatar answered Oct 22 '25 01:10

Maslow


A possible workaround is to make a "install.linq" to create symbolic links, for example in C:\ProgramData, and use those in References in the shared scripts.

Something like this, as administrator:

string codePath = null; // Please set path to code on your machine.

var service = "MyService"; // TODO: Loop over actual project-paths.

var path = Path.Combine(@"C:\ProgramData\MyCompany", service);
var pathToTarget = Path.Combine(codePath, service, @"bin\Debug\net7.0");

Directory.CreateSymbolicLink(path, pathToTarget);
like image 42
Grastveit Avatar answered Oct 22 '25 01:10

Grastveit