Skip to content

Commit

Permalink
Strong name signing of assemblies (#18)
Browse files Browse the repository at this point in the history
* Enabled .Net Standard 2.0 too

* Make .NS 2.0 code cleaner

* Strong name signing

* Fixed CI

* Make string.Contains on NS2.0 the same behavior as NS2.1
  • Loading branch information
gfoidl committed May 18, 2021
1 parent fcf97c3 commit 44d7ed9
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project>

<PropertyGroup>
<MinClientVersion>2.12</MinClientVersion>
<Authors>MyCSharp.de, Benjamin Abt, Günther Foidl and Contributors</Authors>
Expand All @@ -15,9 +16,18 @@
<IsTestProject>$(MSBuildProjectName.Contains('Test'))</IsTestProject>
<IsBenchmarkProject>$(MsBuildProjectName.Contains('Benchmark'))</IsBenchmarkProject>
<IsPackable>false</IsPackable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' != 'true' AND '$(IsBenchmarkProject)' != 'true'">
<GenerateDocumentationFile Condition="'$(Configuration)' == 'Release'">true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(MSBuildThisFileDirectory)MyCSharp.HttpUserAgentParser.snk</AssemblyOriginatorKeyFile>

<PublicKey>00240000048000009400000006020000002400005253413100040000010001003d5c022c088a46d41d5a5bf7591f3a3dcba30f76b0f43a312b6e45bb419d32283175cbd8bfd83134b123da6db83479e50596fb6bbe0e8c6cef50c01c64a0861c963daaf6905920f44ffe1ce44b3cfcb9c23779f34bc90c7b04e74e36a19bb58af3a69456d49b56993969dba9f8e9e935c2757844a11066d1091477f10cd923b7</PublicKey>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion MyCSharp.HttpUserAgentParser.sln
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "_", "_", "{5738CE0D-5E6E-47
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "perf", "perf", "{FAAD18A0-E1B8-448D-B611-AFBDA8A89808}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyCSharp.HttpUserAgentParser.Benchmarks", "perf\MyCSharp.HttpUserAgentParser.Benchmarks\MyCSharp.HttpUserAgentParser.Benchmarks.csproj", "{A0D213E9-6408-46D1-AFAF-5096C2F6E027}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyCSharp.HttpUserAgentParser.Benchmarks", "perf\MyCSharp.HttpUserAgentParser.Benchmarks\MyCSharp.HttpUserAgentParser.Benchmarks.csproj", "{A0D213E9-6408-46D1-AFAF-5096C2F6E027}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
Binary file added MyCSharp.HttpUserAgentParser.snk
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
<DefineConstants>$(DefineConstants);OS_WIN</DefineConstants>
</PropertyGroup>

<PropertyGroup Label="No strong named assembly references">
<NoWarn>$(NoWarn);CS8002</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" Version="0.12.1" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" Version="0.12.1" Condition="'$(OS)' == 'Windows_NT'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public class HttpUserAgentParserMemoryCachedProvider : IHttpUserAgentParserProvi
private readonly IMemoryCache _memoryCache;
private readonly HttpUserAgentParserMemoryCachedProviderOptions _options;

/// <summary>
/// Creates a new instance of <see cref="HttpUserAgentParserMemoryCachedProvider"/>.
/// </summary>
/// <param name="memoryCache">The memory cache instance to use</param>
/// <param name="options">The options used to set expiration and size limit</param>
public HttpUserAgentParserMemoryCachedProvider(IMemoryCache memoryCache, HttpUserAgentParserMemoryCachedProviderOptions options)
{
_memoryCache = memoryCache;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup>
<Product>HTTP User Agent Parser Extensions for IMemoryCache</Product>
<Description>HTTP User Agent Parser Extensions for IMemoryCache</Description>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Compile Include="..\NetStandard2.0-Shim.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="5.0.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
<PropertyGroup>
<Product>HTTP User Agent Parser</Product>
<Description>Parses user agents for Browser, Platform and Bots.</Description>
<TargetFramework>netstandard2.1</TargetFramework>
<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
<IsPackable>true</IsPackable>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<Compile Include="..\NetStandard2.0-Shim.cs" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="5.0.0" />
</ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions src/NetStandard2.0-Shim.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © myCSharp 2020-2021, all rights reserved

namespace System.Diagnostics.CodeAnalysis
{
[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
internal sealed class NotNullWhenAttribute : Attribute
{
public NotNullWhenAttribute(bool returnValue) => this.ReturnValue = returnValue;

public bool ReturnValue { get; }
}
}

namespace MyCSharp.HttpUserAgentParser
{
using System;
using System.Collections.Generic;

internal static class Extensions
{
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kvp, out TKey key, out TValue value)
{
key = kvp.Key;
value = kvp.Value;
}

public static bool Contains(this string instance, string value, StringComparison comparison)
=> instance.IndexOf(value, comparison) >= 0;
}
}

0 comments on commit 44d7ed9

Please sign in to comment.