add .NET Standard 2.0 for diagnostics client library (#700)
authorAdam Sitnik <adam.sitnik@gmail.com>
Mon, 16 Dec 2019 23:59:19 +0000 (00:59 +0100)
committerSung Yoon Whang <suwhang@microsoft.com>
Mon, 16 Dec 2019 23:59:19 +0000 (15:59 -0800)
src/Microsoft.Diagnostics.NETCore.Client/DiagnosticsIpc/IpcClient.cs
src/Microsoft.Diagnostics.NETCore.Client/Microsoft.Diagnostics.NETCore.Client.csproj

index 7d309b670de117d2e3d06931e3b860a15ea30a81..1ab6409ea6a50025bb46a35dc430bf3690027a60 100644 (file)
@@ -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
 {
@@ -69,7 +67,7 @@ namespace Microsoft.Diagnostics.NETCore.Client
                     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);
@@ -122,5 +120,17 @@ namespace Microsoft.Diagnostics.NETCore.Client
         {
             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
+        }
     }
 }
index dcb33ec0f811c5f8fe81a621fb2773dad9cb6b44..b30d9e8f60874f9a5371eaf059625a8963f48999 100644 (file)
@@ -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>