From d56eb8b55a821e636e367ab5fd6805beffdafa76 Mon Sep 17 00:00:00 2001 From: Jinhuafei Date: Fri, 9 Mar 2018 15:23:44 -0800 Subject: [PATCH 1/3] Revert "add support for non web proj (#32)" This reverts commit b9e11273d870fd25b38e22453d6910eeea52d5fd. From 73eb6a47e1d55f210440a0a0c9d19994dad02423 Mon Sep 17 00:00:00 2001 From: Jinhuafei Date: Fri, 9 Mar 2018 15:23:44 -0800 Subject: [PATCH 2/3] Revert "include commit link (#31)" This reverts commit 30f97fb1e4e8867295fcce8ffbde86b515bac182. From 8437e9aa7e4914078cfe81d1f011786882be1837 Mon Sep 17 00:00:00 2001 From: Jinhuafei Date: Fri, 9 Mar 2018 15:23:44 -0800 Subject: [PATCH 3/3] Revert "Adding the ability to define a custom (local) path to Roslyn (#25) (#26)" This reverts commit e79aa12821414f33f88acde5532e1ee5afde2489. --- .../Compiler.cs | 61 +++++-------------- .../Constants.cs | 16 ----- ...om.Providers.DotNetCompilerPlatform.csproj | 1 - .../Util/CompilationSettings.cs | 36 ++++++++--- 4 files changed, 43 insertions(+), 71 deletions(-) delete mode 100644 src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Constants.cs diff --git a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs index 3b95858..deefa2f 100644 --- a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs +++ b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Compiler.cs @@ -1,7 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -using System; +using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections.Generic; @@ -12,21 +12,18 @@ using System.Security.Permissions; using System.Security.Principal; using System.Text; -using static Microsoft.CodeDom.Providers.DotNetCompilerPlatform.Constants.CustomCompilerParameters; namespace Microsoft.CodeDom.Providers.DotNetCompilerPlatform { internal abstract class Compiler : ICodeCompiler { private readonly CodeDomProvider _codeDomProvider; private readonly ICompilerSettings _compilerSettings; + private string _compilerFullPath = null; private const string CLR_PROFILING_SETTING = "COR_ENABLE_PROFILING"; private const string DISABLE_PROFILING = "0"; - // Needs to be initialized using InitializeCompilerFullPath where the CompilerParameters are available. - private string _compilerFullPath = null; - public Compiler(CodeDomProvider codeDomProvider, ICompilerSettings compilerSettings) { - _codeDomProvider = codeDomProvider; - _compilerSettings = compilerSettings; + this._codeDomProvider = codeDomProvider; + this._compilerSettings = compilerSettings; } public CompilerResults CompileAssemblyFromDom(CompilerParameters options, CodeCompileUnit compilationUnit) { @@ -50,8 +47,6 @@ public CompilerResults CompileAssemblyFromDomBatch(CompilerParameters options, C throw new ArgumentNullException("compilationUnits"); } - InitializeCompilerFullPath(options); - try { var sources = compilationUnits.Select(c => { var writer = new StringWriter(); @@ -87,8 +82,6 @@ public CompilerResults CompileAssemblyFromFileBatch(CompilerParameters options, throw new ArgumentNullException("fileNames"); } - InitializeCompilerFullPath(options); - try { // Try opening the files to make sure they exists. This will throw an exception // if it doesn't @@ -124,8 +117,6 @@ public CompilerResults CompileAssemblyFromSourceBatch(CompilerParameters options throw new ArgumentNullException("sources"); } - InitializeCompilerFullPath(options); - try { return FromSourceBatch(options, sources); } @@ -138,41 +129,17 @@ protected abstract string FileExtension { get; } - protected void InitializeCompilerFullPath(CompilerParameters options = null) { - if (string.IsNullOrEmpty(_compilerFullPath)) { - if (options != null) { - // Determining whether the custom compiler path parameter is provided. - var customCompilerPathParameter = options.CompilerOptions.Split('/').FirstOrDefault(p => p.StartsWith(CustomCompilerPath)); - if (!string.IsNullOrEmpty(customCompilerPathParameter)) { - if (!customCompilerPathParameter.Contains(":")) { - throw new ArgumentException($"There's no value defined for the \"{CustomCompilerPath}\" compiler parameter!"); - } + protected virtual string CompilerName { + get { + if (null == _compilerFullPath) { + _compilerFullPath = _compilerSettings.CompilerFullPath; - // Removing trailing space (when this is not the last parameter) and extracting value. - var customCompilerPath = customCompilerPathParameter.TrimEnd(' ').Split(':')[1]; - - if (string.IsNullOrEmpty(customCompilerPath)) { - throw new ArgumentException($"The value of the \"{CustomCompilerPath}\" compiler parameter can't be empty!"); - } - - // Extracting the name of the compiler executable from the default path. - var compilerExecutable = _compilerSettings.CompilerFullPath.Substring(_compilerSettings.CompilerFullPath.LastIndexOf('\\')); - - // And finally, we're able to construct the complete custom path to the compiler executable. - // If the custom path contains spaces, then it has to be surrounded by quotes, which we don't need now. - _compilerFullPath = CompilationSettingsHelper.CompilerFullPath($"{customCompilerPath.Trim('"')}\\{compilerExecutable}"); - - // Removing the custom parameter, as the compiler can't process it. - options.CompilerOptions = options.CompilerOptions.Replace($"/{CustomCompilerPath}:{customCompilerPath}", ""); - } - // Falling back to the default behavior. - else _compilerFullPath = _compilerSettings.CompilerFullPath; + // Try opening the file to make sure the compiler exist. This will throw an exception + // if it doesn't + using (var str = File.OpenRead(_compilerFullPath)) { } } - else _compilerFullPath = _compilerSettings.CompilerFullPath; - // Try opening the file to make sure that the compiler exists. - // This will throw an exception if it doesn't. - using (var str = File.OpenRead(_compilerFullPath)) { } + return _compilerFullPath; } } @@ -315,7 +282,7 @@ private CompilerResults FromFileBatch(CompilerParameters options, string[] fileN } Compile(options, - _compilerFullPath, + CompilerName, args, ref outputFile, ref retValue); @@ -333,7 +300,7 @@ private CompilerResults FromFileBatch(CompilerParameters options, string[] fileN replacedArgs = true; var outputLine = string.Format("{0}>{1} {2}", Environment.CurrentDirectory, - _compilerFullPath, + CompilerName, trueArgs); results.Output.Add(outputLine); } diff --git a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Constants.cs b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Constants.cs deleted file mode 100644 index 6349c3d..0000000 --- a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Constants.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace Microsoft.CodeDom.Providers.DotNetCompilerPlatform { - /// - /// Common, reusable constant values. - /// - public static class Constants { - /// - /// Custom compiler parameters used to modify the behavior of the compiler service. - /// - public static class CustomCompilerParameters { - /// - /// Roslyn path override. - /// - public const string CustomCompilerPath = "compilerPath"; - } - } -} \ No newline at end of file diff --git a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj index 717dfef..0cb3836 100644 --- a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj +++ b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Microsoft.CodeDom.Providers.DotNetCompilerPlatform.csproj @@ -54,7 +54,6 @@ - Component diff --git a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationSettings.cs b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationSettings.cs index 4f79fa3..f3add69 100644 --- a/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationSettings.cs +++ b/src/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/Util/CompilationSettings.cs @@ -21,9 +21,17 @@ public CompilerSettings(string compilerFullPath, int compilerServerTimeToLive) { _compilerServerTimeToLive = compilerServerTimeToLive; } - string ICompilerSettings.CompilerFullPath => _compilerFullPath; + string ICompilerSettings.CompilerFullPath { + get { + return _compilerFullPath; + } + } - int ICompilerSettings.CompilerServerTimeToLive => _compilerServerTimeToLive; + int ICompilerSettings.CompilerServerTimeToLive { + get{ + return _compilerServerTimeToLive; + } + } } internal static class CompilationSettingsHelper { @@ -80,14 +88,28 @@ static CompilationSettingsHelper() { } } - public static ICompilerSettings CSC2 => _csc; + public static ICompilerSettings CSC2 { + get { + return _csc; + } + } - public static ICompilerSettings VBC2 => _vb; + public static ICompilerSettings VBC2 { + get { + return _vb; + } + } - public static string CompilerFullPath(string relativePath) => - Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath); + private static string CompilerFullPath(string relativePath) { + string compilerFullPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, relativePath); + return compilerFullPath; + } - private static bool IsDebuggerAttached => IsDebuggerPresent() || Debugger.IsAttached; + private static bool IsDebuggerAttached { + get { + return IsDebuggerPresent() || Debugger.IsAttached; + } + } [DllImport("kernel32.dll")] private extern static bool IsDebuggerPresent();