Fix multi-target

Use multi-target instead of reflection
上级 98a1f741
......@@ -80,21 +80,28 @@ protected sealed override string GenerateFullPathToTool()
/// as the implementation of IsManagedTool calls this property. See the comment in
/// <see cref="ManagedCompiler.HasToolBeenOverridden"/>.
/// </remarks>
protected sealed override string ToolName
=> $"{ToolNameWithoutExtension}.{(CoreClrShim.IsRunningOnCoreClr ? "dll" : "exe")}";
protected sealed override string ToolName => $"{ToolNameWithoutExtension}.{ToolExtension}";
private static string ToolExtension =>
#if NETCOREAPP2_1
"dll";
#elif NET472
"exe";
#else
#error Unrecognized framework
#endif
private static bool IsCliHost(out string pathToDotnet)
{
if (CoreClrShim.IsRunningOnCoreClr)
{
pathToDotnet = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
return !string.IsNullOrEmpty(pathToDotnet);
}
else
{
pathToDotnet = null;
return false;
}
#if NETCOREAPP2_1
pathToDotnet = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH");
return !string.IsNullOrEmpty(pathToDotnet);
#elif NET472
pathToDotnet = null;
return false;
#else
#error Unrecognized framework
#endif
}
private static string PrependFileToArgs(string pathToTool, string commandLineArgs)
......
......@@ -374,32 +374,30 @@ internal static bool IsCompilerServerSupported(string tempPath)
internal static bool TryCreateServerCore(string clientDir, string pipeName)
{
bool isRunningOnCoreClr = CoreClrShim.IsRunningOnCoreClr;
string expectedPath;
string processArguments;
if (isRunningOnCoreClr)
{
// The server should be in the same directory as the client
var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr);
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}""";
#if NETCOREAPP2_1
// The server should be in the same directory as the client
var expectedCompilerPath = Path.Combine(clientDir, ServerNameCoreClr);
expectedPath = Environment.GetEnvironmentVariable("DOTNET_HOST_PATH") ?? "dotnet";
processArguments = $@"""{expectedCompilerPath}"" ""-pipename:{pipeName}""";
if (!File.Exists(expectedCompilerPath))
{
return false;
}
}
else
if (!File.Exists(expectedCompilerPath))
{
// The server should be in the same directory as the client
expectedPath = Path.Combine(clientDir, ServerNameDesktop);
processArguments = $@"""-pipename:{pipeName}""";
return false;
}
#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))
{
return false;
}
if (!File.Exists(expectedPath))
{
return false;
}
#else
#error Unrecognized configuration
#endif
if (PlatformInformation.IsWindows)
{
......
......@@ -15,6 +15,18 @@ namespace Microsoft.CodeAnalysis.Test.Utilities
/// </summary>
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)
{
tempDirectory = tempDirectory ?? Path.GetTempPath();
......
......@@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Test.Utilities;
using static TestReferences;
namespace Roslyn.Test.Utilities
......@@ -55,7 +56,7 @@ public enum TargetFramework
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
......@@ -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> 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> 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> StandardAndVBRuntimeReferences => CoreClrShim.IsRunningOnCoreClr ? 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> StandardAndVBRuntimeReferences => RuntimeUtilities.IsCoreClrRuntime ? NetStandard20References.Add(NetStandard20.MicrosoftVisualBasicRef) : Mscorlib46ExtendedReferences.Add(TestBase.MsvbRef_v4_0_30319_17929);
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> GetReferences(TargetFramework tf)
......
......@@ -76,7 +76,7 @@ private static MetadataReference GetOrCreateMetadataReference(ref MetadataRefere
LazyThreadSafetyMode.PublicationOnly);
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("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.
先完成此消息的编辑!
想要评论请 注册