Skip to content

Commit

Permalink
Fix assembly versioning/properties and handle platform exception (#1660)
Browse files Browse the repository at this point in the history
* 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 NuGet/Home#4337
  • Loading branch information
ryangribble authored Sep 3, 2017
1 parent 1e474f8 commit 366ac26
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 58 deletions.
15 changes: 8 additions & 7 deletions Octokit.Reactive/Octokit.Reactive.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>An IObservable based GitHub API client library for .NET using Reactive Extensions</Description>
<Description>An IObservable based GitHub API client library for .NET and .NET Core using Reactive Extensions</Description>
<AssemblyTitle>Octokit.Reactive</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>0.0.0-dev</Version>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<AssemblyName>Octokit.Reactive</AssemblyName>
<PackageId>Octokit.Reactive</PackageId>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<DebugType>embedded</DebugType>
<RepositoryUrl>https://github.com/octokit/octokit.net</RepositoryUrl>
<PackageProjectUrl>https://github.com/octokit/octokit.net</PackageProjectUrl>
<PackageIconUrl>https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png</PackageIconUrl>
<PackageTags>GitHub API Octokit linqpad-samples dotnetcore</PackageTags>
<Copyright>Copyright GitHub 2017</Copyright>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\SolutionInfo.cs;..\Octokit\Helpers\Ensure.cs;..\Octokit\Helpers\Pagination.cs" />
<Compile Include="..\Octokit\Helpers\Ensure.cs;..\Octokit\Helpers\Pagination.cs" />
<None Include="app.config" />
</ItemGroup>

Expand Down
4 changes: 0 additions & 4 deletions Octokit.Reactive/Properties/AssemblyInfo.cs

This file was deleted.

67 changes: 51 additions & 16 deletions Octokit/Http/Connection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AssemblyInformationalVersionAttribute>()
.InformationalVersion;
}

return _versionInformation;
}
}
}
17 changes: 7 additions & 10 deletions Octokit/Octokit.csproj
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>An async-based GitHub API client library for .NET</Description>
<Description>An async-based GitHub API client library for .NET and .NET Core</Description>
<AssemblyTitle>Octokit</AssemblyTitle>
<Authors>GitHub</Authors>
<Version>0.0.0-dev</Version>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<AssemblyName>Octokit</AssemblyName>
<PackageId>Octokit</PackageId>
<GenerateAssemblyTitleAttribute>false</GenerateAssemblyTitleAttribute>
<GenerateAssemblyDescriptionAttribute>false</GenerateAssemblyDescriptionAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<DebugType>embedded</DebugType>
<RepositoryUrl>https://github.com/octokit/octokit.net</RepositoryUrl>
<PackageProjectUrl>https://github.com/octokit/octokit.net</PackageProjectUrl>
<PackageIconUrl>https://f.cloud.github.com/assets/19977/1510987/64af2b26-4a9d-11e3-89fc-96a185171c75.png</PackageIconUrl>
<PackageTags>GitHub API Octokit linqpad-samples dotnetcore</PackageTags>
<Copyright>Copyright GitHub 2017</Copyright>
</PropertyGroup>

<ItemGroup>
<Compile Include="..\SolutionInfo.cs" />
</ItemGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.1' ">
<DefineConstants>$(DefineConstants);HAS_TYPEINFO;SIMPLE_JSON_INTERNAL;SIMPLE_JSON_OBJARRAYINTERNAL;SIMPLE_JSON_READONLY_COLLECTIONS;SIMPLE_JSON_TYPEINFO;NO_SERIALIZABLE</DefineConstants>
</PropertyGroup>
Expand Down
5 changes: 1 addition & 4 deletions Octokit/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
16 changes: 0 additions & 16 deletions SolutionInfo.cs

This file was deleted.

7 changes: 6 additions & 1 deletion build/Tasks/Restore.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using Cake.Common.Tools.DotNetCore;
using Cake.Common.Tools.DotNetCore.Restore;
using Cake.Core;
using Cake.Frosting;

[Dependency(typeof(Clean))]
public sealed class Restore : FrostingTask<Context>
{
public override void Run(Context context)
{
context.DotNetCoreRestore(".");
context.DotNetCoreRestore(".", new DotNetCoreRestoreSettings
{
ArgumentCustomization = args => args
.Append("/p:Version={0}", context.Version.GetSemanticVersion())
});
}
}

0 comments on commit 366ac26

Please sign in to comment.