-
Notifications
You must be signed in to change notification settings - Fork 2
Autorun scripts
Autorun scripts is a feature of SPCoder that allows you to automatically execute some C# code on SPCoder startup.
By default the window is located at the bottom of the main screen. There you can see all the registered autorun scripts, view their code, change their order, delete them and save the autorun configuration.
There are 4 default autorun scripts and users can also add their own. The default autorun scripts are:
- Base Imports Script
- Base Script
- Base Plugins
- Base AutoConnect Script
Used for adding the assembly references to Roslyn execution context. If you want to call code from new assembly, you first need to add the reference to it in this file. It is equivalent to "Add reference" in Visual Studio's solution explorer. References can be added by using Roslyn's #r directive.
This #r "System.Windows.Forms"
would add reference to System.Windows.Forms
assembly from GAC. You can also add the reference to assembly by using the path: #r "C:\Projects\SPCoder\external\EPPlus.dll"
Important: #r directive must be the first thing that gets executed in roslyn context. If you need to add references to additional assemblies, you need to restart SPCoder application.
Note: You can use {{WorkingDirectory}}
as a placeholder in your autorun scripts if you need to include the value to current folder and SPCoder will replace that with the path to SPCoder's executable before executing it.
After adding the references, you can execute using
statements and you can call the code from namespaces you want.
This file contains some utility code that can be used in your scripts. For instance, here are the definition for some shortcut methods like print()
and println()
that can be used instead of Console.Write()
and Console.WriteLine()
respectively.
This file also contains the definition of execFile(string path)
function, that can be used if you want to execute a content of script file from file system and definition of logger
object that can be used to write to SPCoder's logger window.
This file contains the code for registering the SPCoder plugins. By default this code takes all the .csx files from Scripts\CSharp\Plugins\
folder and executes them. It also contains some utility methods used by some of the plugins. If you want to register your own plugin, you can save the code for plugin in the .csx file in mentioned folder and it will be automatically registered next time you start SPCoder.
Here you can put the code for connecting to data sources so the next time you start SPCoder it will connect to wanted data source at startup. It can be usefull if you work with one data source often so that you have available data immediately after SPCoder startup. By default this file contains multiple examples on how to connect to File system, Github repo, SharePoint.
If you want to save some file as autorun script, you can simply do it with "Save as autorun" menu button: