ListShortcuts.csx

sample output

image

Launch .CSX as conveniently as .BAT files

first, get Chocolatety if you don’t already have… killer handy

then make sure you have a .csx runner… either ScriptCS or csi.exe starting with Visual Studio 2015 update 3

setup the .csx to runner file association

%~2 means all args starting with #2… see ftype docs for more

FYI for TCC LE folks, apparently i’ve stumbled into a rare backwards compatibility gap… TCC LE doesn’t seem to support the %~2 syntax like cmd.exe and it escapes “%” differently, so substitute that portion of the ftype line above with “%%1 — %%2 %%3 %%4”

lastly, edit your PATHEXT system environment variable to include .CSX which allows us to leave off the extension to launch our scripts just like native commands! =)

refreshenv comes from Chocolately… it refreshes the current command line environment from registry, which we just updated via setx

or runas admin > C:\Windows\System32\rundll32.exe sysdm.cpl,EditEnvironmentVariables
image

with all that fun stuff in place, we can finally do something nifty like this:

beautiful! =)

see my other CSX examples

Using “C# Interactive” aka CSI/CSX for ETL

motivation

interactive C# offers typical REPL benefits ala powershell without the mental context switch required to leave our beloved C# syntax =)
 

notable

  • great MSDN reference article
  • CSX syntax can be executed from either Visual Studio 2015 (as of update 1) > View > Other Windows > C# Interactive
  • -or- C:\Program Files (x86)\MSBuild\14.0\bin\csi.exe
    • then #load file.csx

Extract

this example is based on a low fidelity web page as the raw data source
… it’s really nice to have all the convenient one liner RESTy methods of System.Net.WebClient available now vs the lower level WebRequest/WebResponse pattern that came with .Net 1.0. E.g. client.DownloadString, DownloadFile, etc.

Transform

trivially demonstrative in this case, simply a string.Split call 🙂

Load

demonstrates leveraging SQL Server’s Table-Valued-Parameter functionality to bulk upload rows which are then conveniently manifested inside the receiving stored procedure as a standard sql rowset, ready for tpyical DML like joining to other tables, etc.
 

SQL definition

scrape.csx

Bash script – loop over inline list of files