Skip to content

Commit 6fe0c6f

Browse files
Merge pull request #506 from nathanwienand/add-publish-single-file
Added new build and start commandline options for single exe
2 parents f82d185 + da1838d commit 6fe0c6f

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class BuildCommand : ICommand
2020
"Optional: '/relative-path' to specify output a subdirectory for output." + Environment.NewLine +
2121
"Optional: '/absolute-path to specify and absolute path for output." + Environment.NewLine +
2222
"Optional: '/package-json' to specify a custom package.json file." + Environment.NewLine +
23-
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
23+
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
2424
"Full example for a 32bit debug build with electron prune: build /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \"";
2525

2626
public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
@@ -42,6 +42,7 @@ public BuildCommand(string[] args)
4242
private string _paramForceNodeInstall = "install-modules";
4343
private string _manifest = "manifest";
4444
private string _paramPublishReadyToRun = "PublishReadyToRun";
45+
private string _paramPublishSingleFile = "PublishSingleFile";
4546

4647
public Task<bool> ExecuteAsync()
4748
{
@@ -77,17 +78,17 @@ public Task<bool> ExecuteAsync()
7778
Console.WriteLine($"Build ASP.NET Core App for {platformInfo.NetCorePublishRid}...");
7879

7980
string tempPath = Path.Combine(Directory.GetCurrentDirectory(), "obj", "desktop", desiredPlatform);
80-
81+
8182
if (Directory.Exists(tempPath) == false)
8283
{
8384
Directory.CreateDirectory(tempPath);
84-
}
85+
}
8586
else
8687
{
8788
Directory.Delete(tempPath, true);
8889
Directory.CreateDirectory(tempPath);
8990
}
90-
91+
9192

9293
Console.WriteLine("Executing dotnet publish in this directory: " + tempPath);
9394

@@ -99,13 +100,23 @@ public Task<bool> ExecuteAsync()
99100
if (parser.Arguments.ContainsKey(_paramPublishReadyToRun))
100101
{
101102
publishReadyToRun += parser.Arguments[_paramPublishReadyToRun][0];
102-
}
103+
}
103104
else
104105
{
105106
publishReadyToRun += "true";
106107
}
107108

108-
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} --self-contained", Directory.GetCurrentDirectory());
109+
string publishSingleFile = "/p:PublishSingleFile=";
110+
if (parser.Arguments.ContainsKey(_paramPublishSingleFile))
111+
{
112+
publishSingleFile += parser.Arguments[_paramPublishSingleFile][0];
113+
}
114+
else
115+
{
116+
publishSingleFile += "true";
117+
}
118+
119+
var resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --self-contained", Directory.GetCurrentDirectory());
109120

110121
if (resultCode != 0)
111122
{
@@ -127,7 +138,7 @@ public Task<bool> ExecuteAsync()
127138

128139
if (Directory.Exists(checkForNodeModulesDirPath) == false || parser.Contains(_paramForceNodeInstall) || parser.Contains(_paramPackageJson))
129140

130-
Console.WriteLine("Start npm install...");
141+
Console.WriteLine("Start npm install...");
131142
ProcessHelper.CmdExecute("npm install --production", tempPath);
132143

133144
Console.WriteLine("ElectronHostHook handling started...");
@@ -156,7 +167,7 @@ public Task<bool> ExecuteAsync()
156167
}
157168
else if (parser.Arguments.ContainsKey(_paramOutputDirectory))
158169
{
159-
buildPath = Path.Combine(Directory.GetCurrentDirectory(),parser.Arguments[_paramOutputDirectory][0]);
170+
buildPath = Path.Combine(Directory.GetCurrentDirectory(), parser.Arguments[_paramOutputDirectory][0]);
160171
}
161172

162173
Console.WriteLine("Executing electron magic in this directory: " + buildPath);
@@ -178,7 +189,7 @@ public Task<bool> ExecuteAsync()
178189

179190
string manifestFileName = "electron.manifest.json";
180191

181-
if(parser.Arguments.ContainsKey(_manifest))
192+
if (parser.Arguments.ContainsKey(_manifest))
182193
{
183194
manifestFileName = parser.Arguments[_manifest].First();
184195
}
@@ -194,4 +205,4 @@ public Task<bool> ExecuteAsync()
194205
});
195206
}
196207
}
197-
}
208+
}

ElectronNET.CLI/Commands/StartElectronCommand.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public StartElectronCommand(string[] args)
2727
private string _manifest = "manifest";
2828
private string _clearCache = "clear-cache";
2929
private string _paramPublishReadyToRun = "PublishReadyToRun";
30+
private string _paramPublishSingleFile = "PublishSingleFile";
3031
private string _paramDotNetConfig = "dotnet-configuration";
3132
private string _paramTarget = "target";
3233

@@ -73,8 +74,18 @@ public Task<bool> ExecuteAsync()
7374
publishReadyToRun += "true";
7475
}
7576

77+
string publishSingleFile = "/p:PublishSingleFile=";
78+
if (parser.Arguments.ContainsKey(_paramPublishSingleFile))
79+
{
80+
publishSingleFile += parser.Arguments[_paramPublishSingleFile][0];
81+
}
82+
else
83+
{
84+
publishSingleFile += "true";
85+
}
86+
7687
// If target is specified as a command line argument, use it.
77-
// Format is the same as the build command.
88+
// Format is the same as the build command.
7889
// If target is not specified, autodetect it.
7990
var platformInfo = GetTargetPlatformInformation.Do(string.Empty, string.Empty);
8091
if (parser.Arguments.ContainsKey(_paramTarget))
@@ -96,7 +107,7 @@ public Task<bool> ExecuteAsync()
96107

97108
if (parser != null && !parser.Arguments.ContainsKey("watch"))
98109
{
99-
resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} --no-self-contained", aspCoreProjectPath);
110+
resultCode = ProcessHelper.CmdExecute($"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {publishReadyToRun} {publishSingleFile} --no-self-contained", aspCoreProjectPath);
100111
}
101112

102113
if (resultCode != 0)

0 commit comments

Comments
 (0)