Skip to content

Commit 79fc176

Browse files
committed
Create batch file for tools with runner=executable
Copilot prompt used to help generate batch file:: Can you write c# code that will generate a batch file? Inputs should be the path to the batch file and the path to an executable that the batch file will run. The C# code should find the relative path to the executable from the batch file path. The batch file it generates should use that relative path to launch the executable and forward any arguments passed in to it.
1 parent 4df6f2b commit 79fc176

File tree

1 file changed

+41
-7
lines changed

1 file changed

+41
-7
lines changed

src/Cli/dotnet/ShellShim/ShellShimRepository.cs

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,43 @@ public void CreateShim(ToolCommand toolCommand, IReadOnlyList<FilePath> packaged
4646
_fileSystem.Directory.CreateDirectory(_shimsDirectory.Value);
4747
}
4848

49-
if (TryGetPackagedShim(packagedShims, toolCommand.Name, out FilePath? packagedShim))
49+
if (toolCommand.Runner == "dotnet")
5050
{
51-
_fileSystem.File.Copy(packagedShim.Value.Value, GetShimPath(toolCommand.Name).Value);
52-
_filePermissionSetter.SetUserExecutionPermission(GetShimPath(toolCommand.Name).Value);
51+
if (TryGetPackagedShim(packagedShims, toolCommand, out FilePath? packagedShim))
52+
{
53+
_fileSystem.File.Copy(packagedShim.Value.Value, GetShimPath(toolCommand).Value);
54+
_filePermissionSetter.SetUserExecutionPermission(GetShimPath(toolCommand).Value);
55+
}
56+
else
57+
{
58+
_appHostShellShimMaker.CreateApphostShellShim(
59+
toolCommand.Executable,
60+
GetShimPath(toolCommand));
61+
}
62+
}
63+
else if (toolCommand.Runner == "executable")
64+
{
65+
if (OperatingSystem.IsWindows())
66+
{
67+
var shimPath = GetShimPath(toolCommand).Value;
68+
string relativePathToExe = Path.GetRelativePath(_shimsDirectory.Value, toolCommand.Executable.Value);
69+
70+
string batchContent = $"@echo off\r\n\"%~dp0{relativePathToExe}\" %*\r\n";
71+
File.WriteAllText(shimPath, batchContent);
72+
}
73+
else
74+
{
75+
// TODO: Create symlink
76+
throw new NotImplementedException();
77+
}
5378
}
5479
else
5580
{
56-
_appHostShellShimMaker.CreateApphostShellShim(
57-
toolCommand.Executable,
58-
GetShimPath(toolCommand.Name));
81+
throw new ToolConfigurationException(
82+
string.Format(
83+
CliStrings.ToolSettingsUnsupportedRunner,
84+
toolCommand.Name,
85+
toolCommand.Runner));
5986
}
6087
}
6188
catch (FilePermissionSettingException ex)
@@ -149,7 +176,14 @@ private FilePath GetShimPath(ToolCommand toolCommand)
149176
{
150177
if (OperatingSystem.IsWindows())
151178
{
152-
return _shimsDirectory.WithFile(toolCommand.Name.Value + ".exe");
179+
if (toolCommand.Runner == "dotnet")
180+
{
181+
return _shimsDirectory.WithFile(toolCommand.Name.Value + ".exe");
182+
}
183+
else
184+
{
185+
return _shimsDirectory.WithFile(toolCommand.Name.Value + ".cmd");
186+
}
153187
}
154188
else
155189
{

0 commit comments

Comments
 (0)