From 22579d7eab2aaece8c84d1ecc1d18dae4e107bb2 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Mon, 13 Jan 2020 18:30:35 +0000 Subject: [PATCH] Add application files --- App.xaml | 7 +++++ App.xaml.cs | 52 +++++++++++++++++++++++++++++++++++++ AssemblyInfo.cs | 10 +++++++ MainWindow.xaml | 41 +++++++++++++++++++++++++++++ MainWindow.xaml.cs | 28 ++++++++++++++++++++ VersionInfo.cs | 38 +++++++++++++++++++++++++++ dotnet-version-check.csproj | 15 +++++++++++ dotnet-version-check.sln | 25 ++++++++++++++++++ 8 files changed, 216 insertions(+) create mode 100644 App.xaml create mode 100644 App.xaml.cs create mode 100644 AssemblyInfo.cs create mode 100644 MainWindow.xaml create mode 100644 MainWindow.xaml.cs create mode 100644 VersionInfo.cs create mode 100644 dotnet-version-check.csproj create mode 100644 dotnet-version-check.sln diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..245209c --- /dev/null +++ b/App.xaml @@ -0,0 +1,7 @@ + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..7d1ebd4 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,52 @@ +using System; +using System.CommandLine; +using System.CommandLine.Invocation; +using System.Linq; +using System.Windows; + +namespace DotNetVersionCheck +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + private VersionInfo VersionInfo { get; set; } = new VersionInfo(); + + private void Application_Startup(object sender, StartupEventArgs e) + { + var rootCommand = new RootCommand(description: "Reports .NET runtime version information and triggers a prompt to install .NET Core runtime if applicable") + { + new Option(new[] { "--no-window" }, "Don't display window, write version information to console"), + new Option(new[] { "--silent" }, "Don't display window or write to console. Useful to only trigger .NET Core install if necessary") + }; + + rootCommand.Handler = CommandHandler.Create(RootCommand); + int result = rootCommand.Invoke(e.Args); + + if (result == 1 || e.Args.Any(a => a.Contains("--help") || a.Contains("-h") || a.Contains("--version"))) + { + Shutdown(); + } + else + { + var wnd = new MainWindow() { VersionInfo = VersionInfo }; + wnd.Show(); + } + } + + private int RootCommand(bool noWindow, bool silent) + { + if (noWindow) + { + Console.WriteLine($".NET Runtime Version: {VersionInfo.RuntimeVersion}"); + Console.WriteLine($".NET Target Version: {VersionInfo.TargetFramework}"); + } + + if (noWindow || silent) + return 1; + + return 0; + } + } +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..3c50569 --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly:ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..b6e25ab --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + +