Skip to content

Commit

Permalink
NetCore support (#71)
Browse files Browse the repository at this point in the history
* NetCore support

* Add netcoreapp2.1 dependencies to the tests project

* Magic parameter

* Adjust ApiApproval for multi-framework

* Throw on non-Windows before endpoint even starts

* Inspections

* Restoring original file permissions

* Direct references, drop 2_0

* Reorder ItemGroups to fit conventions
  • Loading branch information
DavidBoike authored Jul 16, 2019
1 parent 7275a7b commit 412e906
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class APIApprovals
[Test]
public void Approve()
{
var publicApi = ApiGenerator.GeneratePublicApi(typeof(PerformanceCountersFeature).Assembly);
var publicApi = ApiGenerator.GeneratePublicApi(typeof(PerformanceCountersFeature).Assembly, excludeAttributes: new[] { "System.Runtime.Versioning.TargetFrameworkAttribute" });
Approver.Verify(publicApi);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[assembly: System.Runtime.CompilerServices.InternalsVisibleToAttribute(@"NServiceBus.Metrics.PerformanceCounters.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100D32BC524DCB1205998C155A4F36BF873587D3602822ECD7B49CD775B2E6A006EE6B9164AB2E3103A6A4D1310C6E5C26818A32FE86710141A2D1F02EB564381CD64C88131BCCA478CDB5072F06DB991DE33DAC1C82BAF40D9F61DD6B40300A4673B693B51CD10A8B9B7D8AB64450431FA422514D6DABCAF70DF785B1E4E6E8AAF")]
[assembly: System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.5.2", FrameworkDisplayName=".NET Framework 4.5.2")]
namespace NServiceBus.Metrics.PerformanceCounters
{
[System.AttributeUsageAttribute(System.AttributeTargets.Assembly | System.AttributeTargets.All)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net452;netcoreapp2.1</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net452</TargetFramework>
<TargetFrameworks>net452;netstandard2.0</TargetFrameworks>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>$(SolutionDir)NServiceBus.snk</AssemblyOriginatorKeyFile>
<Description>Enables access to performance counters</Description>
<!-- Disable NU5111 and NU5110 as CreateNSBPerfCounters.ps1 scripts are intentionally not put into the tools folder. -->
<NoWarn>$(NoWarn);NU5110;NU5111</NoWarn>
</PropertyGroup>

<ItemGroup>
<None Remove="Scripts\*" />
<Content Include="Scripts\*" Pack="true" PackagePath="build" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="NServiceBus.Metrics" Version="[3.0.0, 4.0.0)" />
<PackageReference Include="Fody" Version="2.2.0" PrivateAssets="All" />
Expand All @@ -22,4 +17,14 @@
<PackageReference Include="Particular.Packaging" Version="0.3.0" PrivateAssets="All" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="System.Diagnostics.PerformanceCounter" Version="4.5.0" />
<PackageReference Include="System.Security.Principal.Windows" Version="4.5.1" />
</ItemGroup>

<ItemGroup>
<None Remove="Scripts\*" />
<Content Include="Scripts\*" Pack="true" PackagePath="build" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
namespace NServiceBus
{

/// <summary>
/// Exposes windows performance counters configuration on <see cref="EndpointConfiguration"/>.
/// </summary>
Expand All @@ -12,6 +11,12 @@ public static class PerformanceCountersExtensions
/// <param name="endpointConfiguration">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
public static PerformanceCountersSettings EnableWindowsPerformanceCounters(this EndpointConfiguration endpointConfiguration)
{
#if NETSTANDARD
if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
throw new System.PlatformNotSupportedException("Windows Performance Counters are not supported on this platform.");
}
#endif
Guard.AgainstNull(nameof(endpointConfiguration), endpointConfiguration);

endpointConfiguration.EnableFeature<PerformanceCountersFeature>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ internal PerformanceCountersSettings(EndpointConfiguration endpointConfiguration
/// <param name="sla">The SLA to use. Must be greater than <see cref="TimeSpan.Zero" />.</param>
public void EnableSLAPerformanceCounters(TimeSpan sla)
{
#if NETSTANDARD
if (!System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
throw new PlatformNotSupportedException("Windows Performance Counters are not supported on this platform.");
}
#endif
Guard.AgainstNegativeAndZero(nameof(sla), sla);

endpointConfiguration.GetSettings().Set(SLAMonitoringFeature.EndpointSLAKey, sla);
Expand Down

0 comments on commit 412e906

Please sign in to comment.