allow specifying a project display name

This commit is contained in:
Ell 2021-10-16 17:50:59 +02:00
parent 08413ae9d7
commit 78c02a5530
3 changed files with 12 additions and 9 deletions

View file

@ -11,21 +11,18 @@ namespace GameBundle {
public string OutputDirectory { get; set; } public string OutputDirectory { get; set; }
[Option('v', "verbose")] [Option('v', "verbose")]
public bool Verbose { get; set; } public bool Verbose { get; set; }
[Option('w', "win", HelpText = "Bundle for windows")] [Option('w', "win", HelpText = "Bundle for windows")]
public bool BuildWindows { get; set; } public bool BuildWindows { get; set; }
[Option('l', "linux", HelpText = "Bundle for linux")] [Option('l', "linux", HelpText = "Bundle for linux")]
public bool BuildLinux { get; set; } public bool BuildLinux { get; set; }
[Option('m', "mac", HelpText = "Bundle for mac")] [Option('m', "mac", HelpText = "Bundle for mac")]
public bool BuildMac { get; set; } public bool BuildMac { get; set; }
[Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")] [Option('b', "mac-bundle", HelpText = "Create an app bundle for mac")]
public bool MacBundle { get; set; } public bool MacBundle { get; set; }
[Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")] [Option("mac-bundle-resources", Default = new[] {"Content", "*.icns"}, HelpText = "When creating an app bundle for mac, things that should go into the Resources folder rather than the MacOS folder")]
public IEnumerable<string> MacBundleResources { get; set; } public IEnumerable<string> MacBundleResources { get; set; }
[Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")] [Option('z', "zip", HelpText = "Store the build results in zip files instead of folders")]
public bool Zip { get; set; } public bool Zip { get; set; }
[Option('e', "exclude", HelpText = "Files that should not be moved to the library folder")] [Option('e', "exclude", HelpText = "Files that should not be moved to the library folder")]
public IEnumerable<string> ExcludedFiles { get; set; } public IEnumerable<string> ExcludedFiles { get; set; }
[Option("32-bit", HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")] [Option("32-bit", HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]
@ -38,6 +35,8 @@ namespace GameBundle {
public string LibFolder { get; set; } public string LibFolder { get; set; }
[Option('n', "name-builds", HelpText = "Name the build output directories by the project's name")] [Option('n', "name-builds", HelpText = "Name the build output directories by the project's name")]
public bool NameBuilds { get; set; } public bool NameBuilds { get; set; }
[Option('d', "display-name", HelpText = "The name that should be used for --name-builds and the app bundle instead of the project's name")]
public string DisplayName { get; set; }
[Option('a', "build-args", HelpText = "Additional arguments that should be passed to the dotnet publish command")] [Option('a', "build-args", HelpText = "Additional arguments that should be passed to the dotnet publish command")]
public string BuildArgs { get; set; } public string BuildArgs { get; set; }

View file

@ -49,7 +49,7 @@ namespace GameBundle {
var dir = GetBuildDir(options, proj, "mac"); var dir = GetBuildDir(options, proj, "mac");
var res = Publish(options, proj, dir, "osx-x64", () => { var res = Publish(options, proj, dir, "osx-x64", () => {
if (options.MacBundle) if (options.MacBundle)
CreateMacBundle(options, new DirectoryInfo(dir), proj.FullName); CreateMacBundle(options, new DirectoryInfo(dir), proj);
}); });
if (res != 0) if (res != 0)
return res; return res;
@ -63,7 +63,7 @@ namespace GameBundle {
} }
private static int Publish(Options options, FileInfo proj, string path, string rid, Action additionalAction = null) { private static int Publish(Options options, FileInfo proj, string path, string rid, Action additionalAction = null) {
var publishResult = RunProcess(options, "dotnet", $"publish {proj.FullName} -o {path} -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}"); var publishResult = RunProcess(options, "dotnet", $"publish \"{proj.FullName}\" -o \"{path}\" -r {rid} -c {options.BuildConfig} /p:PublishTrimmed={options.Trim} {options.BuildArgs}");
if (publishResult != 0) if (publishResult != 0)
return publishResult; return publishResult;
@ -116,8 +116,8 @@ namespace GameBundle {
return null; return null;
} }
private static void CreateMacBundle(Options options, DirectoryInfo dir, string proj) { private static void CreateMacBundle(Options options, DirectoryInfo dir, FileInfo proj) {
var app = dir.CreateSubdirectory($"{Path.GetFileNameWithoutExtension(proj)}.app"); var app = dir.CreateSubdirectory($"{GetDisplayName(options, proj)}.app");
var contents = app.CreateSubdirectory("Contents"); var contents = app.CreateSubdirectory("Contents");
var resources = contents.CreateSubdirectory("Resources"); var resources = contents.CreateSubdirectory("Resources");
var macOs = contents.CreateSubdirectory("MacOS"); var macOs = contents.CreateSubdirectory("MacOS");
@ -146,9 +146,13 @@ namespace GameBundle {
private static string GetBuildDir(Options options, FileInfo proj, string osName) { private static string GetBuildDir(Options options, FileInfo proj, string osName) {
var dir = Path.GetFullPath(options.OutputDirectory); var dir = Path.GetFullPath(options.OutputDirectory);
if (options.NameBuilds) if (options.NameBuilds)
return $"{dir}/{Path.GetFileNameWithoutExtension(proj.Name)}-{osName}"; return $"{dir}/{GetDisplayName(options, proj)}-{osName}";
return $"{dir}/{osName}"; return $"{dir}/{osName}";
} }
private static string GetDisplayName(Options options, FileInfo proj) {
return string.IsNullOrEmpty(options.DisplayName) ? Path.GetFileNameWithoutExtension(proj.Name) : options.DisplayName;
}
} }
} }

View file

@ -1 +1 @@
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v "../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -wlm -bzn -s Test.csproj -o bin/Bundled -v -d "Test Project"