Merge pull request #5095 from dotnet/versioninfo
Add tool for printing version and environment information
This commit is contained in:
commit
2c9506ca26
|
@ -1,12 +1,12 @@
|
|||
# dotnetsay .NET Core Global Tools Sample
|
||||
# dotnetsay .NET Tool Sample
|
||||
|
||||
This sample demonstrates how to use and create .NET Core Global Tools. It works on Windows, macOS and Linux.
|
||||
This sample demonstrates how to use and create .NET Tools. It works on Windows, macOS and Linux.
|
||||
|
||||
You must have [.NET Core 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1) or higher installed.
|
||||
You must have the .NET SDK installed, [.NET Core 2.1](https://dotnet.microsoft.com/download/dotnet-core/2.1) or higher.
|
||||
|
||||
## Try the pre-built `dotnetsay` Global Tool
|
||||
## Installation
|
||||
|
||||
You can quickly install and try the [dotnetsay global tool from nuget.org](https://www.nuget.org/packages/dotnetsay/) using the following commands.
|
||||
You can quickly install and try the [dotnetsay](https://www.nuget.org/packages/dotnetsay/):
|
||||
|
||||
```console
|
||||
dotnet tool install -g dotnetsay
|
||||
|
@ -21,16 +21,6 @@ You can uninstall the tool using the following command.
|
|||
dotnet tool uninstall -g dotnetsay
|
||||
```
|
||||
|
||||
## Getting the sample
|
||||
|
||||
The easiest way to get the sample is by cloning the samples repository with [git](https://git-scm.com/downloads), using the following instructions.
|
||||
|
||||
```console
|
||||
git clone https://github.com/dotnet/core/
|
||||
```
|
||||
|
||||
You can also [download the repository as a zip](https://github.com/dotnet/core/archive/master.zip).
|
||||
|
||||
## Build the Tool from source
|
||||
|
||||
You can build and package the tool using the following commands. The instructions assume that you are in the root of the repository.
|
||||
|
|
|
@ -1,25 +1,17 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>A simple .NET Core tool called "dotnetsay".</Description>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.1</TargetFramework>
|
||||
<Description>A simple .NET Core global tool called "dotnetsay".</Description>
|
||||
<RollForward>LatestMajor</RollForward>
|
||||
<VersionPrefix>2.1.5</VersionPrefix>
|
||||
<Authors>.NET Team</Authors>
|
||||
<Product>dotnetsay</Product>
|
||||
<Copyright>MIT</Copyright>
|
||||
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
|
||||
<PackageLicenseUrl>https://github.com/dotnet/core/blob/master/LICENSE.TXT</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/dotnet/core/blob/master/samples/dotnetsay/README.md</PackageProjectUrl>
|
||||
<License>MIT</License>
|
||||
<PublishRepositoryUrl>true</PublishRepositoryUrl>
|
||||
<DebugType>embedded</DebugType>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
<!--
|
||||
Enables tool to run on any runtime version.
|
||||
Will run on .NET Core 2.1 if available. Otherwise, the latest.
|
||||
-->
|
||||
<RollForward>LatestMajor</RollForward>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(ContinuousIntegrationBuild)'=='true'">
|
||||
|
|
36
samples/versioninfo/Program.cs
Normal file
36
samples/versioninfo/Program.cs
Normal 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]}");
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
41
samples/versioninfo/README.md
Normal file
41
samples/versioninfo/README.md
Normal file
|
@ -0,0 +1,41 @@
|
|||
# dotnet-versioninfo tool
|
||||
|
||||
`dotnet-versioninfo` prints 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
|
||||
|
||||
You can quickly install and try the [dotnet-versioninfo](https://www.nuget.org/packages/dotnet-versioninfo/):
|
||||
|
||||
```console
|
||||
dotnet tool install -g dotnet-versioninfo
|
||||
dotnet-versioninfo
|
||||
```
|
||||
|
||||
> Note: You may need to open a new command/terminal window the first time you install a tool.
|
||||
|
||||
You can uninstall the tool using the following command.
|
||||
|
||||
```console
|
||||
dotnet tool uninstall -g dotnet-versioninfo
|
||||
```
|
||||
|
||||
## 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
|
||||
```
|
||||
|
||||
## More information
|
||||
|
||||
The [dotnetsay tool sample](../dotnetsay/README.md) includes more information on .NET tools.
|
22
samples/versioninfo/versioninfo.csproj
Normal file
22
samples/versioninfo/versioninfo.csproj
Normal file
|
@ -0,0 +1,22 @@
|
|||
<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>
|
||||
<EmbedUntrackedSources>true</EmbedUntrackedSources>
|
||||
<PackAsTool>true</PackAsTool>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(ContinuousIntegrationBuild)'=='true'">
|
||||
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
Loading…
Reference in a new issue