Fix multi-target

Use multi-target instead of reflection
上级 98a1f741
...@@ -80,21 +80,28 @@ protected sealed override string GenerateFullPathToTool() ...@@ -80,21 +80,28 @@ protected sealed override string GenerateFullPathToTool()
/// as the implementation of IsManagedTool calls this property. See the comment in /// as the implementation of IsManagedTool calls this property. See the comment in
/// <see cref="ManagedCompiler.HasToolBeenOverridden"/>. /// <see cref="ManagedCompiler.HasToolBeenOverridden"/>.
/// </remarks> /// </remarks>
protected sealed override string ToolName protected sealed override string ToolName => $"{ToolNameWithoutExtension}.{ToolExtension}";
=> $"{ToolNameWithoutExtension}.{(CoreClrShim.IsRunningOnCoreClr ? "dll" : "exe")}";
private static string ToolExtension =>
#if NETCOREAPP2_1
"dll";
#elif NET472
"exe";
#else
#error Unrecognized framework
#endif
private static bool IsCliHost(out string pathToDotnet) private static bool IsCliHost(out string pathToDotnet)
{ {
if (CoreClrShim.IsRunningOnCoreClr) #if NETCOREAPP2_1
{ pathToDotnet = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
pathToDotnet = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH"); return !string.IsNullOrEmpty(pathToDotnet);
return !string.IsNullOrEmpty(pathToDotnet); #elif NET472
} pathToDotnet = null;
else return false;
{ #else
pathToDotnet = null; #error Unrecognized framework
return false; #endif
}
} }
private static string PrependFileToArgs(string pathToTool, string commandLineArgs) private static string PrependFileToArgs(string pathToTool, string commandLineArgs)
......
...@@ -374,32 +374,30 @@ internal static bool IsCompilerServerSupported(string tempPath) ...@@ -374,32 +374,30 @@ internal static bool IsCompilerServerSupported(string tempPath)
internal static bool TryCreateServerCore(string clientDir, string pipeName) internal static bool TryCreateServerCore(string clientDir, string pipeName)
{ {
bool isRunningOnCoreClr = CoreClrShim.IsRunningOnCoreClr;
string expectedPath; string expectedPath;
string processArguments; string processArguments;
if (isRunningOnCoreClr) #if NETCOREAPP2_1
{ // The server should be in the same directory as the client
// The server should be in the same directory as the client var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr);
var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr); expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet"; processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}""";
processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}""";
if (!File.Exists(expectedCompilerPath)) if (!File.Exists(expectedCompilerPath))
{
return false;
}
}
else
{ {
// The server should be in the same directory as the client return false;
expectedPath = Path.Combine(clientDir, ServerNameDesktop); }
processArguments = $@"""-pipename:{pipeName}"""; #elif NET472
// The server should be in the same directory as the client
expectedPath = Path.Combine(clientDir, ServerNameDesktop);
processArguments = $@"""-pipename:{pipeName}""";
if (!File.Exists(expectedPath)) if (!File.Exists(expectedPath))
{ {
return false; return false;
}
} }
#else
#error Unrecognized configuration
#endif
if (PlatformInformation.IsWindows) if (PlatformInformation.IsWindows)
{ {
......
...@@ -15,6 +15,18 @@ namespace Microsoft.CodeAnalysis.Test.Utilities ...@@ -15,6 +15,18 @@ namespace Microsoft.CodeAnalysis.Test.Utilities
/// </summary> /// </summary>
public static partial class RuntimeUtilities public static partial class RuntimeUtilities
{ {
internal static bool IsDesktopRuntime =>
#if NET472
true;
#elif NETCOREAPP2_1
false;
#elif NETSTANDARD2_0
throw new PlatformNotSupportedException();
#else
#error Unsupported configuration
#endif
internal static bool IsCoreClrRuntime => !IsDesktopRuntime;
internal static BuildPaths CreateBuildPaths(string workingDirectory, string sdkDirectory = null, string tempDirectory = null) internal static BuildPaths CreateBuildPaths(string workingDirectory, string sdkDirectory = null, string tempDirectory = null)
{ {
tempDirectory = tempDirectory ?? Path.GetTempPath(); tempDirectory = tempDirectory ?? Path.GetTempPath();
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Text; using System.Text;
using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using static TestReferences; using static TestReferences;
namespace Roslyn.Test.Utilities namespace Roslyn.Test.Utilities
...@@ -55,7 +56,7 @@ public enum TargetFramework ...@@ -55,7 +56,7 @@ public enum TargetFramework
public static class TargetFrameworkUtil public static class TargetFrameworkUtil
{ {
public static MetadataReference StandardCSharpReference => CoreClrShim.IsRunningOnCoreClr ? NetStandard20.MicrosoftCSharpRef : TestBase.CSharpDesktopRef; public static MetadataReference StandardCSharpReference => RuntimeUtilities.IsCoreClrRuntime ? NetStandard20.MicrosoftCSharpRef : TestBase.CSharpDesktopRef;
/* /*
* ⚠ Dev note ⚠: properties in TestBase are backed by Lazy<T>. Avoid changes to the following properties * ⚠ Dev note ⚠: properties in TestBase are backed by Lazy<T>. Avoid changes to the following properties
...@@ -78,10 +79,10 @@ public static class TargetFrameworkUtil ...@@ -78,10 +79,10 @@ public static class TargetFrameworkUtil
public static ImmutableArray<MetadataReference> Mscorlib461ExtendedReferences => ImmutableArray.Create<MetadataReference>(Net461.mscorlibRef, Net461.SystemRef, Net461.SystemCoreRef, Net461.SystemValueTupleRef, Net461.SystemRuntimeRef); public static ImmutableArray<MetadataReference> Mscorlib461ExtendedReferences => ImmutableArray.Create<MetadataReference>(Net461.mscorlibRef, Net461.SystemRef, Net461.SystemCoreRef, Net461.SystemValueTupleRef, Net461.SystemRuntimeRef);
public static ImmutableArray<MetadataReference> NetStandard20References => ImmutableArray.Create<MetadataReference>(NetStandard20.NetStandard, NetStandard20.MscorlibRef, NetStandard20.SystemRuntimeRef, NetStandard20.SystemCoreRef, NetStandard20.SystemDynamicRuntimeRef); public static ImmutableArray<MetadataReference> NetStandard20References => ImmutableArray.Create<MetadataReference>(NetStandard20.NetStandard, NetStandard20.MscorlibRef, NetStandard20.SystemRuntimeRef, NetStandard20.SystemCoreRef, NetStandard20.SystemDynamicRuntimeRef);
public static ImmutableArray<MetadataReference> WinRTReferences => ImmutableArray.Create(TestBase.WinRtRefs); public static ImmutableArray<MetadataReference> WinRTReferences => ImmutableArray.Create(TestBase.WinRtRefs);
public static ImmutableArray<MetadataReference> StandardReferences => CoreClrShim.IsRunningOnCoreClr ? NetStandard20References : Mscorlib46ExtendedReferences; public static ImmutableArray<MetadataReference> StandardReferences => RuntimeUtilities.IsCoreClrRuntime ? NetStandard20References : Mscorlib46ExtendedReferences;
public static ImmutableArray<MetadataReference> StandardAndCSharpReferences => StandardReferences.Add(StandardCSharpReference); public static ImmutableArray<MetadataReference> StandardAndCSharpReferences => StandardReferences.Add(StandardCSharpReference);
public static ImmutableArray<MetadataReference> StandardAndVBRuntimeReferences => CoreClrShim.IsRunningOnCoreClr ? NetStandard20References.Add(NetStandard20.MicrosoftVisualBasicRef) : Mscorlib46ExtendedReferences.Add(TestBase.MsvbRef_v4_0_30319_17929); public static ImmutableArray<MetadataReference> StandardAndVBRuntimeReferences => RuntimeUtilities.IsCoreClrRuntime ? NetStandard20References.Add(NetStandard20.MicrosoftVisualBasicRef) : Mscorlib46ExtendedReferences.Add(TestBase.MsvbRef_v4_0_30319_17929);
public static ImmutableArray<MetadataReference> StandardCompatReferences => CoreClrShim.IsRunningOnCoreClr ? NetStandard20References : Mscorlib40References; public static ImmutableArray<MetadataReference> StandardCompatReferences => RuntimeUtilities.IsCoreClrRuntime ? NetStandard20References : Mscorlib40References;
public static ImmutableArray<MetadataReference> DefaultVbReferencs => ImmutableArray.Create(TestBase.MscorlibRef, TestBase.SystemRef, TestBase.SystemCoreRef, TestBase.MsvbRef); public static ImmutableArray<MetadataReference> DefaultVbReferencs => ImmutableArray.Create(TestBase.MscorlibRef, TestBase.SystemRef, TestBase.SystemCoreRef, TestBase.MsvbRef);
public static ImmutableArray<MetadataReference> GetReferences(TargetFramework tf) public static ImmutableArray<MetadataReference> GetReferences(TargetFramework tf)
......
...@@ -76,7 +76,7 @@ private static MetadataReference GetOrCreateMetadataReference(ref MetadataRefere ...@@ -76,7 +76,7 @@ private static MetadataReference GetOrCreateMetadataReference(ref MetadataRefere
LazyThreadSafetyMode.PublicationOnly); LazyThreadSafetyMode.PublicationOnly);
public static MetadataReference[] LatestVbReferences => s_lazyLatestVbReferences.Value; public static MetadataReference[] LatestVbReferences => s_lazyLatestVbReferences.Value;
public static readonly AssemblyName RuntimeCorLibName = CoreClrShim.IsRunningOnCoreClr public static readonly AssemblyName RuntimeCorLibName = RuntimeUtilities.IsCoreClrRuntime
? new AssemblyName("netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51") ? new AssemblyName("netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51")
: new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); : new AssemblyName("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册