diff --git a/src/Dotnet.Script.Core/Scaffolder.cs b/src/Dotnet.Script.Core/Scaffolder.cs index 269291f9..c9181bf9 100644 --- a/src/Dotnet.Script.Core/Scaffolder.cs +++ b/src/Dotnet.Script.Core/Scaffolder.cs @@ -68,6 +68,20 @@ public void CreateNewScriptFile(string fileName, string currentDirectory) } } + /// + /// Platform specific registeration of .csx files to be executable + /// + public void RegisterFileHandler() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // register dotnet-script as the tool to process .csx files + _commandRunner.Execute("reg", @"add HKCU\Software\classes\.csx /f /ve /t REG_SZ /d dotnetscript"); + _commandRunner.Execute("reg", $@"add HKCU\Software\Classes\dotnetscript\Shell\Open\Command /f /ve /t REG_EXPAND_SZ /d ""\""%ProgramFiles%\dotnet\dotnet.exe\"" script \""%1\"" -- %*"""); + } + _scriptConsole.WriteSuccess($"...[Registered]"); + } + private void CreateScriptFile(string fileName, string currentWorkingDirectory) { if (string.IsNullOrWhiteSpace(fileName)) diff --git a/src/Dotnet.Script/Program.cs b/src/Dotnet.Script/Program.cs index d4adef6e..809fa63c 100644 --- a/src/Dotnet.Script/Program.cs +++ b/src/Dotnet.Script/Program.cs @@ -10,6 +10,7 @@ using System; using System.IO; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; namespace Dotnet.Script @@ -127,6 +128,23 @@ private static int Wain(string[] args) }); }); + // windows only + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + // on windows we have command to register .csx files to be executed by dotnet-script + app.Command("register", c => + { + c.Description = "Register .csx file handler to enable running scripts directly"; + c.HelpOption(helpOptionTemplate); + c.OnExecute(() => + { + var logFactory = CreateLogFactory(verbosity.Value(), debugMode.HasValue()); + var scaffolder = new Scaffolder(logFactory); + scaffolder.RegisterFileHandler(); + }); + }); + } + app.Command("publish", c => { c.Description = "Creates a self contained executable or DLL from a script"; pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy