Skip to content

Commit ecf9e3d

Browse files
committed
add support for passing in runtime ID when doing publish to exe
1 parent 8e7f056 commit ecf9e3d

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/Dotnet.Script.Core/ScriptPublisher.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public void CreateAssembly<TReturn, THost>(ScriptContext context, LogFactory log
5757
File.Copy(sourceNugetPropsPath, destinationNugetPropsPath, overwrite: true);
5858
}
5959

60-
public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory logFactory)
60+
public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory logFactory, string runtimeIdentifier = null)
6161
{
6262
const string AssemblyName = "scriptAssembly";
6363

@@ -73,11 +73,11 @@ public void CreateExecutable<TReturn, THost>(ScriptContext context, LogFactory l
7373

7474
CopyProgramTemplate(tempProjectDirecory);
7575

76-
var runtimeIdentifier = _scriptEnvironment.RuntimeIdentifier;
76+
runtimeIdentifier = runtimeIdentifier ?? _scriptEnvironment.RuntimeIdentifier;
7777

7878
var commandRunner = new CommandRunner(logFactory);
7979
// todo: may want to add ability to return dotnet.exe errors
80-
var exitcode = commandRunner.Execute("dotnet", $"publish \"{tempProjectPath}\" -c Release -r {runtimeIdentifier} -o {context.WorkingDirectory}");
80+
var exitcode = commandRunner.Execute("dotnet", $"publish \"{tempProjectPath}\" -c Release -r {runtimeIdentifier} -o {Path.Combine(context.WorkingDirectory, runtimeIdentifier)}");
8181
if (exitcode != 0) throw new Exception($"dotnet publish failed with result '{exitcode}'");
8282
}
8383

src/Dotnet.Script/Program.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ private static int Wain(string[] args)
138138
var dllOption = c.Option("--dll", "Publish to a .dll instead of a .exe", CommandOptionType.NoValue);
139139
var commandConfig = c.Option("-c | --configuration <configuration>", "Configuration to use for running the script [Release/Debug] Default is \"Debug\"", CommandOptionType.SingleValue);
140140
var publishDebugMode = c.Option(DebugFlagShort + " | " + DebugFlagLong, "Enables debug output.", CommandOptionType.NoValue);
141+
var runtime = c.Option("-r |--runtime", "The runtime to publish the self contained EXE to. Defaults to the your current platform.", CommandOptionType.SingleValue);
142+
141143
c.OnExecute(() =>
142144
{
143145
if (fileNameArgument.Value == null)
@@ -163,9 +165,13 @@ private static int Wain(string[] args)
163165
var context = new ScriptContext(code, absolutePublishDirectory, Enumerable.Empty<string>(), absoluteFilePath, optimizationLevel);
164166

165167
if (dllOption.HasValue())
168+
{
166169
publisher.CreateAssembly<int, CommandLineScriptGlobals>(context, logFactory, dllName.Value());
170+
}
167171
else
168-
publisher.CreateExecutable<int, CommandLineScriptGlobals>(context, logFactory);
172+
{
173+
publisher.CreateExecutable<int, CommandLineScriptGlobals>(context, logFactory, runtime.Value());
174+
}
169175

170176
return 0;
171177

0 commit comments

Comments
 (0)