Add dotnet-versioninfo tool

This commit is contained in:
Rich Lander 2020-08-21 11:08:47 -07:00
parent 9a39b6b01e
commit f4ddfe4f59
3 changed files with 85 additions and 0 deletions

View file

@ -0,0 +1,36 @@
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using static System.Console;
namespace versioninfo
{
class Program
{
static void Main(string[] args)
{
WriteLine("**.NET Core information");
WriteLine($"{nameof(Environment.Version)}: {Environment.Version}");
WriteLine($"{nameof(RuntimeInformation.FrameworkDescription)}: {RuntimeInformation.FrameworkDescription}");
WriteLine($"Libraries version: {((AssemblyInformationalVersionAttribute[])typeof(object).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute),false))[0].InformationalVersion.Split('+')[0]}");
WriteLine($"Libraries hash: {((AssemblyInformationalVersionAttribute[])typeof(object).Assembly.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false))[0].InformationalVersion.Split('+')[1]}");
WriteLine();
WriteLine("**Environment information");
WriteLine($"{nameof(RuntimeInformation.OSDescription)}: {RuntimeInformation.OSDescription}");
WriteLine($"{nameof(Environment.OSVersion)}: {Environment.OSVersion}");
WriteLine($"{nameof(RuntimeInformation.OSArchitecture)}: {RuntimeInformation.OSArchitecture}");
WriteLine($"{nameof(Environment.ProcessorCount)}: {Environment.ProcessorCount}");
WriteLine();
if(RuntimeInformation.OSDescription.StartsWith("Linux") && Directory.Exists("/sys/fs/cgroup"))
{
WriteLine("**CGroup info**");
WriteLine($"cfs_quota_us: {System.IO.File.ReadAllLines("/sys/fs/cgroup/cpu/cpu.cfs_quota_us")[0]}");
WriteLine($"memory.limit_in_bytes: {System.IO.File.ReadAllLines("/sys/fs/cgroup/memory/memory.limit_in_bytes")[0]}");
WriteLine($"memory.usage_in_bytes: {System.IO.File.ReadAllLines("/sys/fs/cgroup/memory/memory.usage_in_bytes")[0]}");
}
}
}
}

View file

@ -0,0 +1,28 @@
# dotnet-versioninfo tool
Produces information about your .NET, OS and hardware environment. It is also a demonstration of the APIs you can use to get this information for your own uses. This information is likely useful for logging.
## Installation
```console
dotnet install -g dotnet-versioninfo
```
[dotnet-versioninfo package](https://www.nuget.org/packages/dotnetsay/)
## Usage
```console
dotnet-versioninfo
**.NET Core information
Version: 3.1.7
FrameworkDescription: .NET Core 3.1.7
Libraries version: 3.1.7-servicing.20366.2
Libraries hash: e8b17841cb5ce923aec48a1b0c12042d445d508f
**Environment information
OSDescription: Darwin 19.6.0 Darwin Kernel Version 19.6.0: Sun Jul 5 00:43:10 PDT 2020; root:xnu-6153.141.1~9/RELEASE_X86_64
OSVersion: Unix 19.6.0.0
OSArchitecture: X64
ProcessorCount: 8
```

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<AssemblyName>dotnet-versioninfo</AssemblyName>
<Description>Displays .NET version and environment information.</Description>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RollForward>LatestMajor</RollForward>
<VersionPrefix>1.0.0</VersionPrefix>
<Authors>.NET Team</Authors>
<License>MIT</License>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<DebugType>embedded</DebugType>
<PackAsTool>true</PackAsTool>
</PropertyGroup>
<ItemGroup Condition="'$(ContinuousIntegrationBuild)'=='true'">
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
</ItemGroup>
</Project>