mirror of
https://github.com/zoriya/octokit.net.git
synced 2026-06-05 03:30:34 +00:00
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=<gitversion>` * 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
This commit is contained in:
+51
-16
@@ -4,6 +4,7 @@ using System.Globalization;
|
||||
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 @@ namespace Octokit
|
||||
|
||||
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<AssemblyInformationalVersionAttribute>()
|
||||
.InformationalVersion;
|
||||
}
|
||||
|
||||
return _versionInformation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user