Skip to content
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
48 changes: 47 additions & 1 deletion ElectronNET.CLI/Commands/BuildCommand.cs
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class BuildCommand : ICommand
"Optional: '/install-modules' to force node module install. Implied by '/package-json'" + Environment.NewLine +
"Optional: '/Version' to specify the version that should be applied to both the `dotnet publish` and `electron-builder` commands. Implied by '/Version'" + Environment.NewLine +
"Optional: '/p:[property]' or '/property:[property]' to pass in dotnet publish properties. Example: '/property:Version=1.0.0' to override the FileVersion" + Environment.NewLine +
"Optional: '/dotnet-publish [-a|--arch <ARCHITECTURE>] [-f | --framework<FRAMEWORK>] [--force] [--no-dependencies] [--no-incremental] [--no-restore] [--nologo]" + Environment.NewLine +
" [--no-self-contained] [--os <OS>] [--self-contained [true|false]] [--source <SOURCE>] [-v|--verbosity <LEVEL>] [--version-suffix <VERSION_SUFFIX>]'" + Environment.NewLine +
" to add additional dot net publish arguments." + Environment.NewLine +
"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 \"";

public static IList<CommandOption> CommandOptions { get; set; } = new List<CommandOption>();
Expand All @@ -46,6 +49,7 @@ public BuildCommand(string[] args)
private string _paramPublishReadyToRun = "PublishReadyToRun";
private string _paramPublishSingleFile = "PublishSingleFile";
private string _paramVersion = "Version";
private string _paramDotNetPublish = "dotnet-publish";

public Task<bool> ExecuteAsync()
{
Expand Down Expand Up @@ -107,8 +111,15 @@ public Task<bool> ExecuteAsync()
var dotNetPublishFlags = GetDotNetPublishFlags(parser);

var command =
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))} --self-contained";
$"dotnet publish -r {platformInfo.NetCorePublishRid} -c \"{configuration}\" --output \"{tempBinPath}\" {string.Join(' ', dotNetPublishFlags.Select(kvp => $"{kvp.Key}={kvp.Value}"))}";

// add any additional dotnet flags
var dotnetFlags = GetDotNetArgs(parser);
if (dotnetFlags.Any())
{
command += " " + string.Join(" ", dotnetFlags);
}

// output the command
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(command);
Expand Down Expand Up @@ -206,6 +217,41 @@ public Task<bool> ExecuteAsync()
});
}

private static List<string> DotNetFlagsWithValuesReserved = new List<string>
{
"-o", "--output", "-r", "--runtime", "-c", "--configuration"
};
private static List<string> DotNetFlagsToIgnore = new List<string>
{
"--interactive", "-h", "--help"
};
private List<string> GetDotNetArgs(SimpleCommandLineParser parser)
{
if (!parser.TryGet(_paramDotNetPublish, out var args)) return new List<string> { "--self-contained" };

var list = args
.Except(DotNetFlagsToIgnore)
.ToList();

// remove flags that are handled by design
foreach (var flag in DotNetFlagsWithValuesReserved)
{
var f = list.IndexOf(flag);
if (f > -1)
{
list.RemoveRange(f, 2);
}
}

// enforce backwards compatibility
if (!list.Contains("--no-self-contained") && !list.Contains("--self-contained"))
{
list.Add("--self-contained");
}

return list;
}

private Dictionary<string, string> GetDotNetPublishFlags(SimpleCommandLineParser parser)
{
var dotNetPublishFlags = new Dictionary<string, string>
Expand Down
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,21 @@ For certain NuGet packages or certain scenarios you may want to build a pure x86
electronize build /target custom "win7-x86;win32" /electron-arch ia32
```

### Additional DotNet Publish Flags

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:

```
electronize build /target osx /dotnet-publish --no-restore
```

#### Self-Contained
> `--self-contained` is enabled by default, to disable use `--no-self-contained` or `--self-contained false`

#### Ignored Flags
> `-r|--runtime`, `-o|--output`, `-c|--configuration`, `--interactive` &amp; `-h|--help` are ignored by design


The end result should be an electron app under your __/bin/desktop__ folder.

### Note
Expand Down