Skip to content

Commit

Permalink
Add application files
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmoore committed Jan 13, 2020
1 parent 2f79e96 commit 22579d7
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 0 deletions.
7 changes: 7 additions & 0 deletions App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application x:Class="DotNetVersionCheck.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:DotNetVersionCheck"
Startup="Application_Startup">
<Application.Resources></Application.Resources>
</Application>
52 changes: 52 additions & 0 deletions App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Linq;
using System.Windows;

namespace DotNetVersionCheck
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
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<bool, bool>(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;
}
}
}
10 changes: 10 additions & 0 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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)
)]
41 changes: 41 additions & 0 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<Window x:Class="DotNetVersionCheck.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:DotNetVersionCheck"
mc:Ignorable="d"
Title=".NET Version Check" Height="200" Width="600"
ResizeMode="NoResize"
Loaded="Window_Loaded" WindowStartupLocation="CenterOwner" WindowStyle="SingleBorderWindow">
<Window.Resources>
<Style x:Key="labelStyle" TargetType="Label">
<Setter Property="FontSize" Value="16"/>
<Setter Property="Margin" Value="10,0,10,0"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
<Style x:Key="buttonStyle" TargetType="Button">
<Setter Property="Height" Value="25"/>
<Setter Property="Width" Value="80"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Center"/>
<Setter Property="Margin" Value="0,0,15,10"/>
</Style>
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="3*"/>
<ColumnDefinition Width="5*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="5*"/>
<RowDefinition Height="5*"/>
<RowDefinition Height="4*"/>
</Grid.RowDefinitions>
<Label Content="Running .NET Version:" Grid.Column="0" Style="{StaticResource labelStyle}" />
<Label x:Name="labelRuntimeVersion" Content="[version]" Grid.Column="1" Grid.Row="0" Style="{StaticResource labelStyle}" />
<Label Content="Target .NET Version:" Grid.Column="0" Grid.Row="1" Style="{StaticResource labelStyle}" />
<Label x:Name="labelTargetVersion" Content="[version]" Grid.Column="1" Grid.Row="1" Style="{StaticResource labelStyle}" />
<Button x:Name="closeButton" Content="_Close" Grid.Column="1" Grid.Row="2" Style="{StaticResource buttonStyle}" Click="CloseButton_Click" />
</Grid>
</Window>
28 changes: 28 additions & 0 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Windows;

namespace DotNetVersionCheck
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}

public VersionInfo VersionInfo { get; set; }

private void Window_Loaded(object sender, RoutedEventArgs e)
{
labelRuntimeVersion.Content = VersionInfo?.RuntimeVersion;
labelTargetVersion.Content = VersionInfo?.TargetFramework;
}

private void CloseButton_Click(object sender, RoutedEventArgs e)
{
Close();
}
}
}
38 changes: 38 additions & 0 deletions VersionInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;
using System.Reflection;
using System.Runtime.Versioning;

namespace DotNetVersionCheck
{
public class VersionInfo
{
private string _targetFramework;
private string _runtimeVersion;

public string TargetFramework
{
get
{
if (_targetFramework == null)
{
_targetFramework = Assembly
.GetEntryAssembly()?
.GetCustomAttribute<TargetFrameworkAttribute>()?
.FrameworkName;
}

return _targetFramework;
}
}
public string RuntimeVersion
{
get
{
if (_runtimeVersion == null)
_runtimeVersion = Environment.Version.ToString();

return _runtimeVersion;
}
}
}
}
15 changes: 15 additions & 0 deletions dotnet-version-check.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

<PropertyGroup>
<!-- Needs to be WinExe to trigger install prompt for .NET Core. This does prevent console output though so have to work around that -->
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>DotNetVersionCheck</RootNamespace>
<UseWPF>true</UseWPF>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="System.CommandLine" Version="0.3.0-alpha.20054.1" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions dotnet-version-check.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

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}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
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
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {5F06B3CB-EA97-4662-A68D-216BE3E8B977}
EndGlobalSection
EndGlobal

0 comments on commit 22579d7

Please sign in to comment.