Skip to content

Commit f0003ae

Browse files
Merge fix: Support for additional dotnet publish flags #655
2 parents 1f5d70b + 5338749 commit f0003ae

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

ElectronNET.CLI/Commands/BuildCommand.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class BuildCommand : ICommand
2424
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
2525
"Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine +
2626
"Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine +
27+
"Optional: '/dotnet-publish [-a|--arch <ARCHITECTURE>] [-f | --framework<FRAMEWORK>] [--force] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]" + Environment.NewLine +
28+
" [--no-self-contained] [--os <OS>] [--self-contained [true|false]] [--source <SOURCE>] [-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>]'" + Environment.NewLine +
29+
" to add additional dot net publish arguments." + Environment.NewLine + Environment.NewLine +
2730
"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 \"" + Environment.NewLine +
2831
"Full example to pass publish parameters: build /PublishReadyToRun false /PublishSingleFile false /target custom win7-x86;win32 /dotnet-configuration Debug /electron-arch ia32 /electron-params \"--prune=true \"";
2932

@@ -49,6 +52,7 @@ public BuildCommand(string[] args)
4952
private string _paramPublishReadyToRun = "PublishReadyToRun";
5053
private string _paramPublishSingleFile = "PublishSingleFile";
5154
private string _paramVersion = "Version";
55+
private string _paramDotNetPublish = "dotnet-publish";
5256

5357
public Task<bool> ExecuteAsync()
5458
{
@@ -116,8 +120,19 @@ public Task<bool> ExecuteAsync()
116120
}
117121

118122
var command =
123+
<<<<<<< HEAD
119124
$"dotnet publish {project} -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
125+
=======
126+
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}";
127+
>>>>>>> 5338749e4d2b0fcd9c46bad1a61e5c7d7d0f18cc
120128

129+
// add any additional dotnet flags
130+
var dotnetFlags = GetDotNetArgs(parser);
131+
if (dotnetFlags.Any())
132+
{
133+
command += " " + string.Join(" ", dotnetFlags);
134+
}
135+
121136
// output the command
122137
Console.ForegroundColor = ConsoleColor.Green;
123138
Console.WriteLine(command);
@@ -228,7 +243,46 @@ public Task<bool> ExecuteAsync()
228243
});
229244
}
230245

246+
<<<<<<< HEAD
231247
internal static Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser parser, string defaultReadyToRun, string defaultSingleFile)
248+
=======
249+
private static List<string> DotNetFlagsWithValuesReserved = new List<string>
250+
{
251+
"-o", "--output", "-r", "--runtime", "-c", "--configuration"
252+
};
253+
private static List<string> DotNetFlagsToIgnore = new List<string>
254+
{
255+
"--interactive", "-h", "--help"
256+
};
257+
private List<string> GetDotNetArgs(SimpleCommandLineParser parser)
258+
{
259+
if (!parser.TryGet(_paramDotNetPublish, out var args)) return new List<string> { "--self-contained" };
260+
261+
var list = args
262+
.Except(DotNetFlagsToIgnore)
263+
.ToList();
264+
265+
// remove flags that are handled by design
266+
foreach (var flag in DotNetFlagsWithValuesReserved)
267+
{
268+
var f = list.IndexOf(flag);
269+
if (f > -1)
270+
{
271+
list.RemoveRange(f, 2);
272+
}
273+
}
274+
275+
// enforce backwards compatibility
276+
if (!list.Contains("--no-self-contained") && !list.Contains("--self-contained"))
277+
{
278+
list.Add("--self-contained");
279+
}
280+
281+
return list;
282+
}
283+
284+
private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser parser)
285+
>>>>>>> 5338749e4d2b0fcd9c46bad1a61e5c7d7d0f18cc
232286
{
233287
var dotNetPublishFlags = new Dictionary<string, string>
234288
{

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ For certain NuGet packages or certain scenarios you may want to build a pure x86
151151
electronize build /target custom "win7-x86;win32" /electron-arch ia32
152152
```
153153

154+
### Additional DotNet Publish Flags
155+
156+
For certain scenarios additional `dotnet publish` arguments may be required. To add additional publish flags use the `/dotnet-publish` flag and add any additional publish flags after. For example if you want to skip the default nuget restore you can do that like this:
157+
158+
```
159+
electronize build /target osx /dotnet-publish --no-restore
160+
```
161+
162+
#### Self-Contained
163+
> `--self-contained` is enabled by default, to disable use `--no-self-contained` or `--self-contained false`
164+
165+
#### Ignored Flags
166+
> `-r|--runtime`, `-o|--output`, `-c|--configuration`, `--interactive` &amp; `-h|--help` are ignored by design
167+
168+
154169
The end result should be an electron app under your __/bin/desktop__ folder.
155170

156171
### Note

0 commit comments

Comments
 (0)