diff --git a/dotnet-rpm/Program.cs b/dotnet-rpm/Program.cs new file mode 100644 index 0000000..d3d2e28 --- /dev/null +++ b/dotnet-rpm/Program.cs @@ -0,0 +1,83 @@ +using Microsoft.Extensions.CommandLineUtils; +using System; +using System.Diagnostics; +using System.Text; + +public class Program +{ + public static int Main(string[] args) + { + CommandLineApplication commandLineApplication = new CommandLineApplication(throwOnUnexpectedArg: true); + + CommandOption runtime = commandLineApplication.Option( + "-r |--runtime ", + "Target runtime of the RPM package. The target runtime has to be specified in the project file.", + CommandOptionType.SingleValue); + + CommandOption framework = commandLineApplication.Option( + "-f | --framework ", + "Required. Target framework of the RPM package. The target framework has to be specified in the project file.", + CommandOptionType.SingleValue); + + CommandOption configuration = commandLineApplication.Option( + "-c | --configuration ", + "Required. Target configuration of the RPM package. The default for most projects is 'Debug'.", + CommandOptionType.SingleValue); + + CommandOption versionSuffix = commandLineApplication.Option( + "---version-suffix ", + "Defines the value for the $(VersionSuffix) property in the project.", + CommandOptionType.SingleValue); + + commandLineApplication.HelpOption("-? | -h | --help"); + + commandLineApplication.OnExecute(() => + { + if (!framework.HasValue()) + { + Console.WriteLine("You must specify a target framework."); + return -1; + } + + if (!runtime.HasValue()) + { + Console.WriteLine("You must specify a target runtime."); + return -1; + } + + StringBuilder msbuildArguments = new StringBuilder(); + msbuildArguments.Append("msbuild /t:CreateRpm "); + msbuildArguments.Append($"/p:RuntimeIdentifier={runtime.Value()} "); + msbuildArguments.Append($"/p:TargetFramework={framework.Value()} "); + + if (configuration.HasValue()) + { + msbuildArguments.Append($"/p:Configuration={configuration.Value()} "); + } + + if (versionSuffix.HasValue()) + { + msbuildArguments.Append($"/p:VersionSuffix={versionSuffix.Value()} "); + } + + var psi = new ProcessStartInfo + { + FileName = "dotnet", + Arguments = msbuildArguments.ToString() + }; + + var process = new Process + { + StartInfo = psi, + + }; + + process.Start(); + process.WaitForExit(); + + return process.ExitCode; + }); + + return commandLineApplication.Execute(args); + } +} diff --git a/dotnet-rpm/dotnet-rpm.csproj b/dotnet-rpm/dotnet-rpm.csproj new file mode 100644 index 0000000..b9a3d38 --- /dev/null +++ b/dotnet-rpm/dotnet-rpm.csproj @@ -0,0 +1,36 @@ + + + + Exe + netcoreapp1.1 + 0.1.1 + Frederik Carlier + Quamotion + Copyright (c) Frederik Carlier and Contributors + https://github.com/qmfrederik/dotnet-packaging/blob/master/LICENSE + https://github.com/qmfrederik/dotnet-packaging/ + https://github.com/qmfrederik/dotnet-packaging/ + git + dotnet cli packaging rpm package installer + + Create RPM packages (.rpm files) of your .NET Core projects straight from the command line. + + Once you've installed this package as a .NET CLI tool, run dotnet rpm to generate a .rpm package which contains the publish output of your .NET Project. + + See https://github.com/qmfrederik/dotnet-packaging/ for more information on how to use dotnet rpm. + + Packaging Tools for .NET CLI + $(USERPROFILE)\.nuget\packages + + + + + + + + + true + lib\$(TargetFramework)\ + + + \ No newline at end of file