Skip to content

Instantly share code, notes, and snippets.

@tugberkugurlu
Created September 22, 2015 18:14
Show Gist options
  • Save tugberkugurlu/3184a06ff084d808d4dd to your computer and use it in GitHub Desktop.
Save tugberkugurlu/3184a06ff084d808d4dd to your computer and use it in GitHub Desktop.
beta8 effort but it doesn't work :s
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