From d9280db442a1e778c2663f92ca31151b4f54b169 Mon Sep 17 00:00:00 2001 From: Tim Moore Date: Wed, 15 Jan 2020 20:51:02 +0000 Subject: [PATCH] Split into two projects, one for a WinExe app and another for console EXE. The former results in a prompt for runtime when not present and the latter just reports error with a suitable error code. --- .github/workflows/build.yml | 13 ++++--- VersionInfo.cs => Common/VersionInfo.cs | 0 Console/Program.cs | 35 +++++++++++++++++++ Console/dotnet-version-check-console.csproj | 26 ++++++++++++++ README.md | 34 +++++++++++------- App.xaml => WindowsWithPrompt/App.xaml | 0 App.xaml.cs => WindowsWithPrompt/App.xaml.cs | 0 .../AssemblyInfo.cs | 0 .../MainWindow.xaml | 0 .../MainWindow.xaml.cs | 0 .../dotnet-version-check-win.csproj | 11 +++--- dotnet-version-check.sln | 16 ++++++--- 12 files changed, 108 insertions(+), 27 deletions(-) rename VersionInfo.cs => Common/VersionInfo.cs (100%) create mode 100644 Console/Program.cs create mode 100644 Console/dotnet-version-check-console.csproj rename App.xaml => WindowsWithPrompt/App.xaml (100%) rename App.xaml.cs => WindowsWithPrompt/App.xaml.cs (100%) rename AssemblyInfo.cs => WindowsWithPrompt/AssemblyInfo.cs (100%) rename MainWindow.xaml => WindowsWithPrompt/MainWindow.xaml (100%) rename MainWindow.xaml.cs => WindowsWithPrompt/MainWindow.xaml.cs (100%) rename dotnet-version-check.csproj => WindowsWithPrompt/dotnet-version-check-win.csproj (70%) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 255bdeb..df9adde 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,9 +15,14 @@ jobs: with: dotnet-version: 3.1.100 - - name: Build x64 - run: dotnet publish -c Release -r win7-x64 + - name: Build x64 Win app + run: dotnet publish .\WindowsWithPrompt\dotnet-version-check-win.csproj -c Release -r win7-x64 - - name: Build x86 - run: dotnet publish -c Release -r win7-x86 + - name: Build x86 Win app + run: dotnet publish .\WindowsWithPrompt\dotnet-version-check-win.csproj -c Release -r win7-x86 + - name: Build x64 console app + run: dotnet publish .\Console\dotnet-version-check-console.csproj -c Release -r win7-x64 + + - name: Build x86 console app + run: dotnet publish .\Console\dotnet-version-check-console.csproj -c Release -r win7-x86 diff --git a/VersionInfo.cs b/Common/VersionInfo.cs similarity index 100% rename from VersionInfo.cs rename to Common/VersionInfo.cs diff --git a/Console/Program.cs b/Console/Program.cs new file mode 100644 index 0000000..0fad719 --- /dev/null +++ b/Console/Program.cs @@ -0,0 +1,35 @@ +using System; +using System.CommandLine; +using System.CommandLine.Invocation; +using System.Threading.Tasks; + +namespace DotNetVersionCheck +{ + public class Program + { + private static VersionInfo VersionInfo { get; set; } = new VersionInfo(); + + public static async Task Main(string[] args) + { + var rootCommand = new RootCommand(description: "Reports .NET runtime version information and/or results in an error code useful to determine no runtime installed") + { + new Option(new[] { "--silent" }, "Don't write to console, just return 0 if runtime present, otherwise host will raise error code") + }; + + rootCommand.Handler = CommandHandler.Create(RootCommand); + await rootCommand.InvokeAsync(args); + + // Normal operation returns 0. App host will return error code if there's an issue with the runtime. + return 0; + } + + private static void RootCommand(bool silent) + { + if (!silent) + { + Console.WriteLine($".NET Runtime Version: {VersionInfo.RuntimeVersion}"); + Console.WriteLine($".NET Target Version: {VersionInfo.TargetFramework}"); + } + } + } +} diff --git a/Console/dotnet-version-check-console.csproj b/Console/dotnet-version-check-console.csproj new file mode 100644 index 0000000..2b5bbc6 --- /dev/null +++ b/Console/dotnet-version-check-console.csproj @@ -0,0 +1,26 @@ + + + + Exe + netcoreapp3.1 + + + win7-x64;win7-x86 + false + true + true + + 0.2.0 + + DotNetVersionCheck + + + + + + + + + + + diff --git a/README.md b/README.md index c667073..bc135c7 100644 --- a/README.md +++ b/README.md @@ -2,31 +2,39 @@ ![](https://github.com/tjmoore/dotnet-version-check/workflows/build/badge.svg) -Reports .NET runtime version information and/or triggers a prompt to install .NET Core runtime if applicable +Sample apps to simply report .NET runtime version information and can aid with an installer to check runtime presence. This simply relies on .NET Core 3 app host ability to check runtime and report error or display a prompt to download the runtime. + +A use case for this is with an installer that installs a .NET Core FDD/FDE service but needs to check and install the runtime prior to starting the service, or likewise with a console or desktop app, but not wanting to wait for a prompt or error when the user launches the app itself, but install the runtime during install. + +There are two samples here: + +### Console + +This version is simply a console app and writes version info to the console. If the runtime is not present the dotnet host will report an error with advice to the console and will return an error code, which is one of https://github.com/dotnet/runtime/blob/master/docs/design/features/host-error-codes.md + +For example, CoreHostLibMissingFailure (0x80008083) can indicate a compatible runtime required based on the target is not present. An installer could check this and then run the required installer. + +### WindowsWithPrompt + +This version is built as a basic WPF windows app to do the same thing but shows a window with the runtime information. Perhaps useful for support scenarios. + +The key here though is when built as a WinEXE output type, the dotnet host will provide a prompt to the user to download the runtime if not present. Although currently it only directs the user's browser to the runtime download home page. + ## Usage ``` -dotnet-version-check: - Reports .NET runtime version information and/or triggers a prompt to install runtime if applicable - Usage: - dotnet-version-check [options] + dotnet-version-check(-win|-console) [options] Options: - --no-window Don't display window, write version information to console - --silent Don't display window or write to console. Useful to only trigger .NET Core install if necessary + --no-window Don't display window, write version information to console (Windows app only) + --silent Don't display window or write to console. Useful to only trigger .NET Core install if necessary (windows) or raise error code (windows & console) --version Display version information ``` This relies on .NET Core 3+ built-in support for prompting download and install of .NET Core runtime if not installed when running an executable. This only occurs with Windows GUI Executables. -This idea behind this is primarily for use when installing console or service applications that cannot self-prompt for install of the runtime. The solution here is by creating a WinExe executable targetting .NET Core 3 and running that during install, it should prompt for the missing runtime. This is as an alternative to scripting an installer to detect a compatible runtime globally installed which can be somewhat complex and the framework has built in support for this anyway. - -The executabe need do nothing other than start and shut down, but it does have to be a WinExe target. - -In this example it does a little more by providing a window showing the installed framework and/or reporting to console, but with a 'silent' option for use in an installer so it either does nothing or the user receives a prompt to install the runtime. - Note, this depends on Framework Dependent Executable (FDE) mode of deployment (which is also the default for FDD now in .NET Core 3). It's not relevant to Self Contained Deploment (SCD) as the published application will contain all the dependent runtime and is fixed to the specified target runtime version and platform. This primarily is aimed at .NET Core. It might be possible to target .NET Framework and it may report the versions, but even if that works, it likely won't prompt for install. diff --git a/App.xaml b/WindowsWithPrompt/App.xaml similarity index 100% rename from App.xaml rename to WindowsWithPrompt/App.xaml diff --git a/App.xaml.cs b/WindowsWithPrompt/App.xaml.cs similarity index 100% rename from App.xaml.cs rename to WindowsWithPrompt/App.xaml.cs diff --git a/AssemblyInfo.cs b/WindowsWithPrompt/AssemblyInfo.cs similarity index 100% rename from AssemblyInfo.cs rename to WindowsWithPrompt/AssemblyInfo.cs diff --git a/MainWindow.xaml b/WindowsWithPrompt/MainWindow.xaml similarity index 100% rename from MainWindow.xaml rename to WindowsWithPrompt/MainWindow.xaml diff --git a/MainWindow.xaml.cs b/WindowsWithPrompt/MainWindow.xaml.cs similarity index 100% rename from MainWindow.xaml.cs rename to WindowsWithPrompt/MainWindow.xaml.cs diff --git a/dotnet-version-check.csproj b/WindowsWithPrompt/dotnet-version-check-win.csproj similarity index 70% rename from dotnet-version-check.csproj rename to WindowsWithPrompt/dotnet-version-check-win.csproj index 98f6e62..a8a11c9 100644 --- a/dotnet-version-check.csproj +++ b/WindowsWithPrompt/dotnet-version-check-win.csproj @@ -11,15 +11,16 @@ true true + 0.2.0 + DotNetVersionCheck true - DotNetVersionCheck - 0.1.0 - tjmoore - Reports .NET runtime version information and/or triggers a prompt to install .NET Core runtime if applicable - https://github.com/tjmoore/dotnet-version-check + + + + diff --git a/dotnet-version-check.sln b/dotnet-version-check.sln index aabfdb6..de4cf94 100644 --- a/dotnet-version-check.sln +++ b/dotnet-version-check.sln @@ -3,7 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 16 VisualStudioVersion = 16.0.29613.14 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-version-check", "dotnet-version-check.csproj", "{56EFF347-3480-4868-B13B-C7C275940DF0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-version-check-win", "WindowsWithPrompt\dotnet-version-check-win.csproj", "{32ECB62C-D36F-4617-BCCC-E088B46CAA54}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "dotnet-version-check-console", "Console\dotnet-version-check-console.csproj", "{EC1DAE36-142B-4300-97E8-A0F1907E3F0F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -11,10 +13,14 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {56EFF347-3480-4868-B13B-C7C275940DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {56EFF347-3480-4868-B13B-C7C275940DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU - {56EFF347-3480-4868-B13B-C7C275940DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU - {56EFF347-3480-4868-B13B-C7C275940DF0}.Release|Any CPU.Build.0 = Release|Any CPU + {32ECB62C-D36F-4617-BCCC-E088B46CAA54}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {32ECB62C-D36F-4617-BCCC-E088B46CAA54}.Debug|Any CPU.Build.0 = Debug|Any CPU + {32ECB62C-D36F-4617-BCCC-E088B46CAA54}.Release|Any CPU.ActiveCfg = Release|Any CPU + {32ECB62C-D36F-4617-BCCC-E088B46CAA54}.Release|Any CPU.Build.0 = Release|Any CPU + {EC1DAE36-142B-4300-97E8-A0F1907E3F0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EC1DAE36-142B-4300-97E8-A0F1907E3F0F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EC1DAE36-142B-4300-97E8-A0F1907E3F0F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EC1DAE36-142B-4300-97E8-A0F1907E3F0F}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE