Search code examples
c#nugetlinqpad

How can two users share a common nuget cache in Linqpad


I use Linqpad on a Windows server to run scripts as scheduled tasks via lprun. The scheduled tasks run as a service Windows account. I want to update the nuget packages used by these scripts. Normally, I would open Linqpad, go to the NuGet manager and click Update on each package. That downloads the latest version to the local NuGet cache folder. However, I need to do this without logging on to the server as the service account (InfoSec doesn't like interactive logins as a service account).

I've tried setting up both my normal windows account and the service account with a NUGET_PACKAGES environment variable pointing to the same folder (D:\nuget\packages, for example). When I update a package as my user, I see the new folder version appear in the common cache folder but when I run the script as the service account, it still tries to use the previous version of the nuget. This is easily reproduced when the new version of the nuget has a new method that the script relies on. It just fails to run.

It seems like sharing a common nuget cache folder isn't enough. Each user still has some reference to what it thinks is the latest version of the package but I haven't been able to find out where that is.

I don't know if it matters but some of these packages come from a private nuget repo. I've set up both users in Linqpad with the same connection details and token.

Any ideas what I'm missing?


Solution

  • LINQPad maintains its own cache that tells it the latest version of each package that its successfully downloaded (with dependencies). You can force LPRun to refresh this by calling it with the -nunuget switch. Here are all the command-line options:

    >LPRun7
    Usage: lprun7 [<options>] <scriptfile> [<script-args>]
    
    options: (all case-insensitive)
     -format={text|html|htmlfrag|csv|csvi}   Output format. csvi=invariant CSV.
     -cxname=<connection-name>               Sets/overrides a script's connection.
     -lang=<language>                        Sets/overrides a script's language.
     -warn                                   Writes compiler warnings (to stderr).
     -optimize                               Enables compiler optimizations.
     -compileonly                            Just checks that query will compile.
     -recompile                              Ignores compiler cache, forces build.
     -nunuget                                Freshens NuGet references to latest.
     -fx=<major.minor>                       Run under specified .NET version.
    
    scriptfile: Path to script. If it's a .linq file, -lang & -cxname are optional.
    
    script-args: Args following <script-filepath> are passed to the script itself.
    
    Examples:
      lprun7 TestScript.linq
      lprun7 TestScript.linq > results.txt
      lprun7 script1.linq | lprun7 script2.linq
      lprun7 -format=csv script.linq HelloWorld
    
    Go to http://www.linqpad.net/lprun.aspx for detailed help.
    

    Another solution is to reference a specific version of the NuGet package in your scripts. Then LPRun will not rely on its cache to know what version to use.