From 366ac261bf20b9e30d438b9cbd1a9a06aa6a3f25 Mon Sep 17 00:00:00 2001 From: Ryan Gribble Date: Sun, 3 Sep 2017 11:50:20 +1000 Subject: [PATCH] Fix assembly versioning/properties and handle platform exception (#1660) * Use assembly version instead of hard-coded ones Builds happening on AppVeyor specify the assembly version with `dotnet build /p:Version=` * Set default version for dev time This is to avoid that the default 1.0.0 version be assigned to the assemblies * Move various package/assembly properties from AssemblyInfo into csproj files so dotnet build can set them all * Get rid of SolutionInfo and move assembly version function into Connection class * Rework FormatUserAgent to use InformationalVersion and guard against exceptions determining platform OS/arch (fixes #1617) * Update assembly descriptions * Reword dotnetcore to .NET Core * Attempted workaround for package version dependency issue by specifying version on dotnet restore see https://github.com/NuGet/Home/issues/4337 --- Octokit.Reactive/Octokit.Reactive.csproj | 15 ++--- Octokit.Reactive/Properties/AssemblyInfo.cs | 4 -- Octokit/Http/Connection.cs | 67 ++++++++++++++++----- Octokit/Octokit.csproj | 17 +++--- Octokit/Properties/AssemblyInfo.cs | 5 +- SolutionInfo.cs | 16 ----- build/Tasks/Restore.cs | 7 ++- 7 files changed, 73 insertions(+), 58 deletions(-) delete mode 100644 Octokit.Reactive/Properties/AssemblyInfo.cs delete mode 100644 SolutionInfo.cs diff --git a/Octokit.Reactive/Octokit.Reactive.csproj b/Octokit.Reactive/Octokit.Reactive.csproj index 5a8c0938ec..13c4897567 100644 --- a/Octokit.Reactive/Octokit.Reactive.csproj +++ b/Octokit.Reactive/Octokit.Reactive.csproj @@ -1,22 +1,23 @@  - An IObservable based GitHub API client library for .NET using Reactive Extensions + An IObservable based GitHub API client library for .NET and .NET Core using Reactive Extensions Octokit.Reactive GitHub + 0.0.0-dev netstandard1.1;net45 Octokit.Reactive Octokit.Reactive - false - false - false - false - false embedded + https://github.com/octokit/octokit.net + https://github.com/octokit/octokit.net + https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png + GitHub API Octokit linqpad-samples dotnetcore + Copyright GitHub 2017 - + diff --git a/Octokit.Reactive/Properties/AssemblyInfo.cs b/Octokit.Reactive/Properties/AssemblyInfo.cs deleted file mode 100644 index f9d22c6370..0000000000 --- a/Octokit.Reactive/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,4 +0,0 @@ -using System.Reflection; - -[assembly: AssemblyTitle("Octokit.Reactive")] -[assembly: AssemblyDescription("An IObservable based GitHub API client library for .NET using Reactive Extensions")] diff --git a/Octokit/Http/Connection.cs b/Octokit/Http/Connection.cs index f5aecfa95b..7ca86ff77a 100644 --- a/Octokit/Http/Connection.cs +++ b/Octokit/Http/Connection.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Net; using System.Net.Http; +using System.Reflection; using System.Threading; using System.Threading.Tasks; using Octokit.Internal; @@ -696,26 +697,60 @@ internal static TwoFactorType ParseTwoFactorType(IResponse restResponse) static string FormatUserAgent(ProductHeaderValue productInformation) { - var format = -#if !HAS_ENVIRONMENT - "{0} ({1}; {2}; {3}; Octokit {4})"; -#else - "{0} ({1} {2}; {3}; {4}; Octokit {5})"; -#endif - - return string.Format(CultureInfo.InvariantCulture, - format, + return string.Format(CultureInfo.InvariantCulture, "{0} ({1}; {2}; Octokit {3})", productInformation, + GetPlatformInformation(), + GetCultureInformation(), + GetVersionInformation()); + } + + private static string _platformInformation; + static string GetPlatformInformation() + { + if (string.IsNullOrEmpty(_platformInformation)) + { + try + { + _platformInformation = string.Format(CultureInfo.InvariantCulture, #if !HAS_ENVIRONMENT - RuntimeInformation.OSDescription, - RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant(), + "{0}; {1}", + RuntimeInformation.OSDescription.Trim(), + RuntimeInformation.OSArchitecture.ToString().ToLowerInvariant().Trim() #else - Environment.OSVersion.Platform, - Environment.OSVersion.Version.ToString(3), - Environment.Is64BitOperatingSystem ? "amd64" : "x86", + "{0} {1}; {2}", + Environment.OSVersion.Platform, + Environment.OSVersion.Version.ToString(3), + Environment.Is64BitOperatingSystem ? "amd64" : "x86" #endif - CultureInfo.CurrentCulture.Name, - AssemblyVersionInformation.Version); + ); + } + catch + { + _platformInformation = "Unknown Platform"; + } + } + + return _platformInformation; + } + + static string GetCultureInformation() + { + return CultureInfo.CurrentCulture.Name; + } + + private static string _versionInformation; + static string GetVersionInformation() + { + if (string.IsNullOrEmpty(_versionInformation)) + { + _versionInformation = typeof(IGitHubClient) + .GetTypeInfo() + .Assembly + .GetCustomAttribute() + .InformationalVersion; + } + + return _versionInformation; } } } diff --git a/Octokit/Octokit.csproj b/Octokit/Octokit.csproj index 8ed1ac46b7..a0e90012bd 100644 --- a/Octokit/Octokit.csproj +++ b/Octokit/Octokit.csproj @@ -1,24 +1,21 @@  - An async-based GitHub API client library for .NET + An async-based GitHub API client library for .NET and .NET Core Octokit GitHub + 0.0.0-dev netstandard1.1;net45 Octokit Octokit - false - false - false - false - false embedded + https://github.com/octokit/octokit.net + https://github.com/octokit/octokit.net + https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png + GitHub API Octokit linqpad-samples dotnetcore + Copyright GitHub 2017 - - - - $(DefineConstants);HAS_TYPEINFO;SIMPLE_JSON_INTERNAL;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_READONLY_COLLECTIONS;SIMPLE_JSON_TYPEINFO;NO_SERIALIZABLE diff --git a/Octokit/Properties/AssemblyInfo.cs b/Octokit/Properties/AssemblyInfo.cs index ac5c9f1a9a..e783bcb861 100644 --- a/Octokit/Properties/AssemblyInfo.cs +++ b/Octokit/Properties/AssemblyInfo.cs @@ -1,6 +1,3 @@ -using System.Reflection; -using System.Runtime.CompilerServices; +using System.Runtime.CompilerServices; -[assembly: AssemblyTitle("Octokit")] -[assembly: AssemblyDescription("An async-based GitHub API client library for .NET")] [assembly: InternalsVisibleTo("Octokit.Tests")] \ No newline at end of file diff --git a/SolutionInfo.cs b/SolutionInfo.cs deleted file mode 100644 index 294c355837..0000000000 --- a/SolutionInfo.cs +++ /dev/null @@ -1,16 +0,0 @@ -// -using System.Reflection; -using System.Runtime.InteropServices; - -[assembly: AssemblyProductAttribute("Octokit")] -[assembly: AssemblyVersionAttribute("0.24.0")] -[assembly: AssemblyFileVersionAttribute("0.24.0")] -[assembly: ComVisibleAttribute(false)] -namespace System -{ - internal static class AssemblyVersionInformation - { - internal const string Version = "0.24.0"; - internal const string InformationalVersion = "0.24.0"; - } -} diff --git a/build/Tasks/Restore.cs b/build/Tasks/Restore.cs index c20481f59f..e7cdb7850a 100644 --- a/build/Tasks/Restore.cs +++ b/build/Tasks/Restore.cs @@ -1,5 +1,6 @@ using Cake.Common.Tools.DotNetCore; using Cake.Common.Tools.DotNetCore.Restore; +using Cake.Core; using Cake.Frosting; [Dependency(typeof(Clean))] @@ -7,6 +8,10 @@ public sealed class Restore : FrostingTask { public override void Run(Context context) { - context.DotNetCoreRestore("."); + context.DotNetCoreRestore(".", new DotNetCoreRestoreSettings + { + ArgumentCustomization = args => args + .Append("/p:Version={0}", context.Version.GetSemanticVersion()) + }); } } \ No newline at end of file