Skip to content

Add register command for .csx file registration #431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/Dotnet.Script.Core/Scaffolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ public void CreateNewScriptFile(string fileName, string currentDirectory)
}
}

/// <summary>
/// Platform specific registeration of .csx files to be executable
/// </summary>
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))
Expand Down
18 changes: 18 additions & 0 deletions src/Dotnet.Script/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using System;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;

namespace Dotnet.Script
Expand Down Expand Up @@ -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";
Expand Down