part 1 finished

This commit is contained in:
Ellpeck 2020-04-09 18:06:01 +02:00
parent ccd9f5460c
commit b3ce0e118a
16 changed files with 220 additions and 28 deletions

View file

@ -2,6 +2,8 @@
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameBundle", "GameBundle\GameBundle.csproj", "{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GameBundle", "GameBundle\GameBundle.csproj", "{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -12,5 +14,9 @@ Global
{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Debug|Any CPU.Build.0 = Debug|Any CPU {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.ActiveCfg = Release|Any CPU {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.Build.0 = Release|Any CPU {18B83BC9-B35C-4E04-AA1C-85057CB2B6BB}.Release|Any CPU.Build.0 = Release|Any CPU
{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6FD8768A-7F59-4815-BF41-33DA9ACDB81A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View file

@ -3,7 +3,20 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<NuspecFile>Contentless.nuspec</NuspecFile>
<Authors>Ellpeck</Authors>
<Description>A tool to package MonoGame and other .NET Core applications into several distributable formats</Description>
<PackageTags>monogame mono xna netcore dotnet publish bundle tool library</PackageTags>
<PackageProjectUrl>https://github.com/Ellpeck/GameBundle</PackageProjectUrl>
<RepositoryUrl>https://github.com/Ellpeck/GameBundle</RepositoryUrl>
<PackageLicenseUrl>https://github.com/Ellpeck/GameBundle/blob/master/LICENSE</PackageLicenseUrl>
<PackAsTool>true</PackAsTool>
<ToolCommandName>gamebundle</ToolCommandName>
<VersionPrefix>0.0.1</VersionPrefix>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.7.82" />
</ItemGroup>
</Project> </Project>

View file

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<package>
<metadata>
<id>GameBundle</id>
<version>0.0.1</version>
<authors>Ellpeck</authors>
<description>A tool to package MonoGame and other .NET Core applications into several distributable formats</description>
<tags>monogame mono xna netcore dotnet publish bundle tool library</tags>
<projectUrl>https://github.com/Ellpeck/GameBundle</projectUrl>
<licenseUrl>https://github.com/Ellpeck/GameBundle/blob/master/LICENSE</licenseUrl>
<repository type="git" url="https://github.com/Ellpeck/GameBundle"/>
<readme>README.md</readme>
</metadata>
<files>
<file src="../README.md" target="README.md"/>
<file src="_._" target="lib/netcoreapp3.1/"/>
<file src="GameBundle.targets" target="build/GameBundle.targets"/>
<file src="bin\Debug\netcoreapp3.1\**\*" target="tools/"/>
</files>
</package>

View file

@ -1,5 +0,0 @@
<Project>
<Target Name="GameBundle" AfterTargets="AfterBuild">
<Exec Command="$(MSBuildThisFileDirectory)/../tools/GameBundle.exe"/>
</Target>
</Project>

29
GameBundle/Options.cs Normal file
View file

@ -0,0 +1,29 @@
using System.Collections.Generic;
using CommandLine;
namespace GameBundle {
public class Options {
[Option('s', "source", Required = true, HelpText = "The location of the .csproj file that should be built and bundled")]
public string SourceFile { get; set; }
[Option('o', "output", Required = true, HelpText = "The location of the directory that the bundles should be stored in")]
public string OutputDirectory { get; set; }
[Option('v', "verbose", Default = false)]
public bool Verbose { get; set; }
[Option('w', "win", Default = true, HelpText = "Bundle for windows")]
public bool BundleWindows { get; set; }
[Option('l', "linux", Default = true, HelpText = "Bundle for linux")]
public bool BundleLinux { get; set; }
[Option('m', "mac", Default = true, HelpText = "Bundle for mac")]
public bool BundleMac { get; set; }
[Option('e', "exclude", Default = new[] {"openal", "oal", "sdl2", "SDL2"}, HelpText = "Files like unmanaged libraries that should not be moved to the /Lib folder")]
public string[] ExcludedFiles { get; set; }
[Option("32bit", Default = false, HelpText = "Publish for 32 bit instead of 64 bit. Note that this is only possible on Windows")]
public bool Publish32Bit { get; set; }
[Option("trim", Default = true, HelpText = "If the application should be trimmed when being published")]
public bool Trim { get; set; }
}
}

View file

@ -1,7 +1,64 @@
namespace GameBundle { using System;
using System.Diagnostics;
using System.IO;
using System.Text.RegularExpressions;
using CommandLine;
namespace GameBundle {
internal static class Program { internal static class Program {
private static void Main(string[] args) { private static int Main(string[] args) {
return Parser.Default.ParseArguments<Options>(args).MapResult(Run, _ => -1);
}
private static int Run(Options options) {
if (RunProcess(options, "dotnet", "tool install nulastudio.ncbeauty -g") < 0)
return -1;
var proj = new FileInfo(options.SourceFile);
if (!proj.Exists) {
Console.WriteLine("Project file not found at " + proj.FullName);
return -1;
}
if (options.Verbose)
Console.WriteLine("Found project file at " + proj.FullName);
var bundleDir = new DirectoryInfo(Path.Combine(options.OutputDirectory, "Bundled"));
if (!bundleDir.Exists)
bundleDir.Create();
if (options.BundleWindows)
Publish(options, proj, $"{bundleDir}/win", options.Publish32Bit ? "win-x86" : "win-x64");
if (options.BundleLinux)
Publish(options, proj, $"{bundleDir}/linux", "linux-x64");
if (options.BundleMac)
Publish(options, proj, $"{bundleDir}/mac", "osx-x64");
return 0;
}
private static void Publish(Options options, FileInfo proj, string path, string rid) {
RunProcess(options, "dotnet", $"publish {proj.FullName} -o {path} -r {rid} /p:PublishTrimmed={options.Trim}");
// Run beauty
var excludes = string.Empty;
if (options.ExcludedFiles.Length > 0)
excludes = "excludes=" + string.Join(";", options.ExcludedFiles);
var log = options.Verbose ? "Detail" : "Error";
RunProcess(options, "ncbeauty", $"--loglevel={log} --force=True {path} Lib {excludes}");
// Remove the beauty file since it's just a marker
var beautyFile = new FileInfo(Path.Combine(path, "NetCoreBeauty"));
if (beautyFile.Exists)
beautyFile.Delete();
}
private static int RunProcess(Options options, string program, string args) {
if (options.Verbose)
Console.WriteLine($"$ {program} {args}");
var process = Process.Start(program, args);
process.WaitForExit();
return process.ExitCode;
} }
} }

View file

1
Test/Bundle.bat Normal file
View file

@ -0,0 +1 @@
"../GameBundle/bin/Debug/netcoreapp3.1/GameBundle.exe" -s Test.csproj -o bin -v

63
Test/Content/Content.mgcb Normal file
View file

@ -0,0 +1,63 @@
#----------------------------- Global Properties ----------------------------#
/outputDir:bin
/intermediateDir:obj
/platform:DesktopGL
/config:
/profile:Reach
/compress:False
#-------------------------------- References --------------------------------#
#---------------------------------- Content ---------------------------------#
#begin Textures/Anim.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/Anim.png
#begin Textures/AutoTiling.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/AutoTiling.png
#begin Textures/Test.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/Test.png
#begin Textures/Tree.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/Tree.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 710 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 896 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 248 B

13
Test/GameImpl.cs Normal file
View file

@ -0,0 +1,13 @@
using MLEM.Startup;
namespace Test {
public class GameImpl : MlemGame {
public static GameImpl Instance { get; private set; }
public GameImpl() {
Instance = this;
}
}
}

14
Test/Program.cs Normal file
View file

@ -0,0 +1,14 @@
using Microsoft.Xna.Framework;
using MLEM.Misc;
namespace Test {
public static class Program {
public static void Main() {
TextInputWrapper.Current = new TextInputWrapper.DesktopGl<TextInputEventArgs>((w, c) => w.TextInput += c);
using var game = new GameImpl();
game.Run();
}
}
}

21
Test/Test.csproj Normal file
View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.0</TargetFramework>
<PublishReadyToRun>false</PublishReadyToRun>
<TieredCompilation>false</TieredCompilation>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Contentless" Version="2.0.*" />
<PackageReference Include="MLEM.Startup" Version="3.2.*" />
<PackageReference Include="MonoGame.Content.Builder" Version="3.7.*" />
<PackageReference Include="MonoGame.Framework.DesktopGL.Core" Version="3.8.*" />
</ItemGroup>
<ItemGroup>
<MonoGameContentReference Include="Content\Content.mgcb" />
<Content Include="Content\*\**" />
</ItemGroup>
</Project>