Created
September 22, 2015 18:14
-
-
Save tugberkugurlu/3184a06ff084d808d4dd to your computer and use it in GitHub Desktop.
beta8 effort but it doesn't work :s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Immutable; | |
using System.IO; | |
using System.Reflection; | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.Diagnostics; | |
using Microsoft.Dnx.Compilation.CSharp; | |
using Microsoft.Dnx.Runtime; | |
public class AnalyzersCompilationModule : ICompileModule | |
{ | |
private readonly string _basePath; | |
public AnalyzersCompilationModule(IApplicationEnvironment appEnv) | |
{ | |
_basePath = appEnv.ApplicationBasePath; | |
} | |
public void BeforeCompile(BeforeCompileContext context) | |
{ | |
string analyzerAssemblyPath = Path.Combine(_basePath, @"../../lib/DotNetDoodle.Analyzers.dll"); | |
Console.WriteLine("msg:" + _basePath); | |
ImmutableArray<DiagnosticAnalyzer> diagnosticAnalyzers = new AnalyzerFileReference(analyzerAssemblyPath, FromFileLoader.Instance).GetAnalyzers(LanguageNames.CSharp); | |
var compilation = context.Compilation.WithAnalyzers(diagnosticAnalyzers); | |
ImmutableArray<Diagnostic> diagsnostics = compilation.GetAnalyzerDiagnosticsAsync().Result; | |
foreach (var diagsnostic in diagsnostics) | |
{ | |
context.Diagnostics.Add(diagsnostic); | |
} | |
} | |
public void AfterCompile(AfterCompileContext context) | |
{ | |
} | |
private class FromFileLoader : IAnalyzerAssemblyLoader | |
{ | |
public static FromFileLoader Instance = new FromFileLoader(); | |
public void AddDependencyLocation(string fullPath) | |
{ | |
} | |
public Assembly LoadFromPath(string fullPath) | |
{ | |
return Assembly.LoadFrom(fullPath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment