public static TempFile CreateCSharpAnalyzerAssemblyWithTestAnalyzer(TempDirectory dir, string assemblyName) { var analyzerSource = @" using System; using System.Collections.Immutable; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; [DiagnosticAnalyzer(LanguageNames.CSharp)] public class TestAnalyzer : DiagnosticAnalyzer { public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get { throw new NotImplementedException(); } } public override void Initialize(AnalysisContext context) { throw new NotImplementedException(); } }"; dir.CopyFile(typeof(System.Reflection.Metadata.MetadataReader).Assembly.Location); var immutable = dir.CopyFile(typeof(ImmutableArray).Assembly.Location); var analyzer = dir.CopyFile(typeof(DiagnosticAnalyzer).Assembly.Location); dir.CopyFile(Path.Combine(Path.GetDirectoryName(typeof(CSharpCompilation).Assembly.Location), "System.IO.FileSystem.dll")); var analyzerCompilation = CSharpCompilation.Create( assemblyName, new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(analyzerSource) }, new MetadataReference[] { TestReferences.NetStandard13.SystemRuntime, MetadataReference.CreateFromFile(immutable.Path), MetadataReference.CreateFromFile(analyzer.Path) }, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); return(dir.CreateFile(assemblyName + ".dll").WriteAllBytes(analyzerCompilation.EmitToArray())); }
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir) { foreach (var file in Directory.EnumerateFiles(projectDir)) { tempDir.CopyFile(file); } }
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir) { // copy all the files to temp dir foreach (var file in Directory.EnumerateFiles(projectDir)) { // never copy project.lock.json. All the tests are expected to call 'dotnet restore' if (file.ToLower().EndsWith("project.lock.json")) { continue; } tempDir.CopyFile(file); } }