Skip to content

Commit

Permalink
add .NET Standard 2.0 for diagnostics client library (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored and sywhang committed Dec 16, 2019
1 parent 8d47a6b commit 9536822
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Security.Principal;
using System.Text;
using System.Text.RegularExpressions;

namespace Microsoft.Diagnostics.NETCore.Client
{
Expand Down Expand Up @@ -69,7 +67,7 @@ private static Stream GetTransport(int processId)
throw new ServerNotAvailableException($"Process {processId} not running compatible .NET Core runtime.");
}
string path = Path.Combine(IpcRootPath, ipcPort);
var remoteEP = new UnixDomainSocketEndPoint(path);
var remoteEP = CreateUnixDomainSocketEndPoint(path);

var socket = new Socket(AddressFamily.Unix, SocketType.Stream, ProtocolType.Unspecified);
socket.Connect(remoteEP);
Expand Down Expand Up @@ -122,5 +120,17 @@ private static IpcMessage Read(Stream stream)
{
return IpcMessage.Parse(stream);
}

private static EndPoint CreateUnixDomainSocketEndPoint(string path)
{
#if NETCOREAPP
return new UnixDomainSocketEndPoint(path);
#elif NETSTANDARD2_0
// UnixDomainSocketEndPoint is not part of .NET Standard 2.0
var type = typeof(Socket).Assembly.GetType("System.Net.Sockets.UnixDomainSocketEndPoint");
var ctor = type.GetConstructor(new[] { typeof(string) });
return (EndPoint)ctor.Invoke(new object[] { path });
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFrameworks>netstandard2.0;netcoreapp2.1</TargetFrameworks>
<RootNamespace>Microsoft.Diagnostics.NETCore.Client</RootNamespace>
<Description>.NET Core Diagnostics Client Library</Description>
<VersionPrefix>0.1.0</VersionPrefix>
Expand Down

0 comments on commit 9536822

Please sign in to comment.