protected override void OnEvaluateCompilation(Project project, ICompilationDiagnosticFilter diagnosticFilter)
        {
            string GetProjectOutputFilePath() => string.IsNullOrEmpty(project.OutputFilePath) ? null : project.OutputFilePath;

            // TODO: TBD: I am kind of surprised that the Roslyn API does not do more to help with this issue?
            string GetOutputExtension(OutputKind kind) => OutputExtensions.TryGetValue(kind, out var ext) ? ext : $"{dot}{dll}";

            // TODO: TBD: ditto Compilation... CompilationWithAnalyzers...
            var compilation = diagnosticFilter.GetCompilation <Compilation>();

            // TODO: TBD: possibly involving Compilation.Emit? pdb path? xml path? comprehension of `target framework´?

            string GetDesiredProjectOutputPath()
            {
                var outputDirectory = Combine($"{project.AssemblyName}", "bin");

                if (!Directory.Exists(outputDirectory))
                {
                    Directory.CreateDirectory(outputDirectory);
                }

                var outputFileName = $"{project.AssemblyName}{GetOutputExtension(compilation.Options.OutputKind)}";

                return(Combine(outputDirectory, outputFileName));
            }

            // TODO: TBD: may further report Emit diagnostics ...
            var outputPath = GetProjectOutputFilePath() ?? GetDesiredProjectOutputPath();
            var pdbPath    = Combine(GetDirectoryName(outputPath), $"{GetFileNameWithoutExtension(outputPath)}.pdb");

            diagnosticFilter.Result = compilation.Emit(outputPath, pdbPath);

            base.OnEvaluateCompilation(project, diagnosticFilter);
        }
Beispiel #2
0
 /// <summary>
 /// Protected Constructor.
 /// </summary>
 /// <param name="project"></param>
 /// <param name="diagnosticFilter"></param>
 /// <inheritdoc />
 internal CompilationDiagnosticEventArgs(Project project, ICompilationDiagnosticFilter diagnosticFilter)
 {
     Project          = project;
     DiagnosticFilter = diagnosticFilter;
 }
 /// <summary>
 /// Internal Constructor.
 /// </summary>
 /// <param name="filter"></param>
 /// <inheritdoc />
 internal CompilationDiagnosticEventArgs(ICompilationDiagnosticFilter filter)
 {
     Filter = filter;
 }
Beispiel #4
0
        // TODO: TBD: may furnish Generic type derived from Compilation...
        // TODO: TBD: i.e. CSharpCompilation, but this must also align with the Language, etc...
        /// <summary>
        /// Event handler occurs when <see cref="EvaluateCompilation"/> is requested.
        /// </summary>
        /// <param name="project"></param>
        /// <param name="diagnosticFilter"></param>
        protected virtual void OnEvaluateCompilation(Project project, ICompilationDiagnosticFilter diagnosticFilter)
        {
            var e = new CompilationDiagnosticEventArgs(project, diagnosticFilter);

            EvaluateCompilation?.Invoke(this, e);
        }