diff --git a/src/Compilers/CSharp/csc/csc.csproj b/src/Compilers/CSharp/csc/csc.csproj
index 89d71b57adc9a..b1611248057a6 100644
--- a/src/Compilers/CSharp/csc/csc.csproj
+++ b/src/Compilers/CSharp/csc/csc.csproj
@@ -36,6 +36,9 @@
CoreClrAnalyzerAssemblyLoader.cs
+
+ CoreClrShim.cs
+
DesktopBuildClient.cs
diff --git a/src/Compilers/Server/VBCSCompiler/DesktopBuildServerController.cs b/src/Compilers/Server/VBCSCompiler/DesktopBuildServerController.cs
index ae4acf6844061..b55a10cfb81e9 100644
--- a/src/Compilers/Server/VBCSCompiler/DesktopBuildServerController.cs
+++ b/src/Compilers/Server/VBCSCompiler/DesktopBuildServerController.cs
@@ -36,11 +36,8 @@ internal static ICompilerServerHost CreateCompilerServerHost()
// VBCSCompiler is installed in the same directory as csc.exe and vbc.exe which is also the
// location of the response files.
var clientDirectory = AppDomain.CurrentDomain.BaseDirectory;
-#if NET46
- var sdkDirectory = RuntimeEnvironment.GetRuntimeDirectory();
-#else
- var sdkDirectory = (string)null;
-#endif
+ var sdkDirectory = BuildClient.GetSystemSdkDirectory();
+
return new DesktopCompilerServerHost(clientDirectory, sdkDirectory);
}
diff --git a/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj b/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj
index 9004ce2237a90..c8df8456f7ea1 100644
--- a/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj
+++ b/src/Compilers/Server/VBCSCompiler/VBCSCompiler.csproj
@@ -23,7 +23,7 @@
-
+
@@ -37,6 +37,9 @@
CoreClrAnalyzerAssemblyLoader.cs
+
+ CoreClrShim.cs
+
DesktopAnalyzerAssemblyLoader.cs
diff --git a/src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs b/src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
index 6ca17bf26c159..e6a667808a4a6 100644
--- a/src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
+++ b/src/Compilers/Server/VBCSCompilerTests/CompilerServerTests.cs
@@ -198,11 +198,7 @@ internal static (int ExitCode, string Output) RunCommandLineCompiler(
var client = ServerUtil.CreateBuildClient(language);
client.TimeoutOverride = Timeout.Infinite;
-#if NET461
- var sdkDir = RuntimeEnvironment.GetRuntimeDirectory();
-#else
- string sdkDir = null;
-#endif
+ var sdkDir = ServerUtil.DefaultSdkDirectory;
var buildPaths = new BuildPaths(
clientDir: Path.GetDirectoryName(typeof(CommonCompiler).Assembly.Location),
@@ -222,10 +218,11 @@ private static DisposableFile GetResultFile(TempDirectory directory, string resu
private static void RunCompilerOutput(TempFile file, string expectedOutput)
{
-#if NET461
- var result = ProcessUtilities.Run(file.Path, "", Path.GetDirectoryName(file.Path));
- Assert.Equal(expectedOutput.Trim(), result.Output.Trim());
-#endif
+ if (!CoreClrShim.IsRunningOnCoreClr)
+ {
+ var result = ProcessUtilities.Run(file.Path, "", Path.GetDirectoryName(file.Path));
+ Assert.Equal(expectedOutput.Trim(), result.Output.Trim());
+ }
}
private static void VerifyResult((int ExitCode, string Output) result)
diff --git a/src/Compilers/Server/VBCSCompilerTests/ServerUtil.cs b/src/Compilers/Server/VBCSCompilerTests/ServerUtil.cs
index 8f008e94660d3..789a73cada4f9 100644
--- a/src/Compilers/Server/VBCSCompilerTests/ServerUtil.cs
+++ b/src/Compilers/Server/VBCSCompilerTests/ServerUtil.cs
@@ -69,11 +69,7 @@ public void Dispose()
internal static class ServerUtil
{
internal static string DefaultClientDirectory { get; } = Path.GetDirectoryName(typeof(DesktopBuildClientTests).Assembly.Location);
-#if NET461
- internal static string DefaultSdkDirectory { get; } = RuntimeEnvironment.GetRuntimeDirectory();
-#else
- internal static string DefaultSdkDirectory { get; } = null;
-#endif
+ internal static string DefaultSdkDirectory { get; } = BuildClient.GetSystemSdkDirectory();
internal static BuildPaths CreateBuildPaths(string workingDir, string tempDir)
{
diff --git a/src/Compilers/Shared/BuildClient.cs b/src/Compilers/Shared/BuildClient.cs
index 963f0aef80055..439f93a38cb6b 100644
--- a/src/Compilers/Shared/BuildClient.cs
+++ b/src/Compilers/Shared/BuildClient.cs
@@ -40,6 +40,18 @@ internal abstract class BuildClient
{
protected static bool IsRunningOnWindows => Path.DirectorySeparatorChar == '\\';
+ public static string GetSystemSdkDirectory()
+ {
+ if (CoreClrShim.IsRunningOnCoreClr)
+ {
+ return null;
+ }
+ else
+ {
+ return RuntimeEnvironment.GetRuntimeDirectory();
+ }
+ }
+
///
/// Run a compilation through the compiler server and print the output
/// to the console. If the compiler server fails, run the fallback
@@ -191,15 +203,16 @@ private static bool UseNativeArguments()
return false;
}
-#if NET46
+ if (CoreClrShim.IsRunningOnCoreClr)
+ {
+ // The native invoke ends up giving us both CoreRun and the exe file.
+ // We've decided to ignore backcompat for CoreCLR,
+ // and use the Main()-provided arguments
+ // https://github.com/dotnet/roslyn/issues/6677
+ return false;
+ }
+
return true;
-#else
- // (Not NET46 -> on CoreCLR)
- // The native invoke ends up giving us both CoreRun and the exe file.
- // Need to find a good way to remove the host as well as the EXE argument.
- // https://github.com/dotnet/roslyn/issues/6677
- return false;
-#endif
}
///
diff --git a/src/Compilers/Shared/BuildServerConnection.cs b/src/Compilers/Shared/BuildServerConnection.cs
index a5d1c15ce8b21..7e4b25923d2b9 100644
--- a/src/Compilers/Shared/BuildServerConnection.cs
+++ b/src/Compilers/Shared/BuildServerConnection.cs
@@ -341,13 +341,7 @@ internal static async Task TryConnectToServerAsync(
internal static bool TryCreateServerCore(string clientDir, string pipeName)
{
-#if NETSTANDARD1_3
bool isRunningOnCoreClr = CoreClrShim.IsRunningOnCoreClr;
-#elif NET46
- bool isRunningOnCoreClr = false;
-#elif NETCOREAPP2_0
- bool isRunningOnCoreClr = true;
-#endif
string expectedPath;
string processArguments;
if (isRunningOnCoreClr)
diff --git a/src/Compilers/Shared/DesktopBuildClient.cs b/src/Compilers/Shared/DesktopBuildClient.cs
index 36edd64acad27..091a936b42832 100644
--- a/src/Compilers/Shared/DesktopBuildClient.cs
+++ b/src/Compilers/Shared/DesktopBuildClient.cs
@@ -3,11 +3,8 @@
using System;
using System.Collections.Generic;
using System.IO;
-using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using System.Reflection;
-using System.Runtime.InteropServices;
namespace Microsoft.CodeAnalysis.CommandLine
{
@@ -31,15 +28,14 @@ internal DesktopBuildClient(RequestLanguage language, CompileFunc compileFunc, I
internal static int Run(IEnumerable arguments, RequestLanguage language, CompileFunc compileFunc, IAnalyzerAssemblyLoader analyzerAssemblyLoader)
{
-#if NET46
- var sdkDir = RuntimeEnvironment.GetRuntimeDirectory();
-#else
- string sdkDir = null;
+ var sdkDir = GetSystemSdkDirectory();
+ if (CoreClrShim.IsRunningOnCoreClr)
+ {
+ // Register encodings for console
+ // https://github.com/dotnet/roslyn/issues/10785
+ System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
+ }
- // Register encodings for console
- // https://github.com/dotnet/roslyn/issues/10785
- System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance);
-#endif
var client = new DesktopBuildClient(language, compileFunc, analyzerAssemblyLoader);
var clientDir = AppContext.BaseDirectory;
var workingDir = Directory.GetCurrentDirectory();
diff --git a/src/Compilers/VisualBasic/vbc/vbc.csproj b/src/Compilers/VisualBasic/vbc/vbc.csproj
index 55efeb4f99b23..1f146e4a1279c 100644
--- a/src/Compilers/VisualBasic/vbc/vbc.csproj
+++ b/src/Compilers/VisualBasic/vbc/vbc.csproj
@@ -35,6 +35,9 @@
CoreClrAnalyzerAssemblyLoader.cs
+
+ CoreClrShim.cs
+
DesktopBuildClient.cs