A DNX compile module that post-processes the project using PostSharp.
Inheritance: ICompileModule
コード例 #1
0
        public IMetadataProjectReference CompileProject(
            CompilationProjectContext projectContext,
            Func <LibraryExport> referenceResolver,
            Func <IList <ResourceDescriptor> > resourcesResolver)
        {
            List <DiagnosticResult> diagnosticResults = new List <DiagnosticResult>();

            var module = new PostSharpCompilerModule(_services, _workingDirectory);

            var export = referenceResolver();

            if (export == null)
            {
                return(null);
            }

            var incomingReferences       = export.MetadataReferences;
            var incomingSourceReferences = export.SourceReferences;

            var processedIncomingReferences = new List <IMetadataReference>(incomingReferences.Count);

            foreach (var reference in incomingReferences)
            {
                var projectReference = reference as IMetadataProjectReference;
                if (projectReference != null)
                {
                    // If we have a PostSharpProjectReference, we have to compile it using EmitAssembly and replace the reference by a MetadataFileReference.
                    string referencePath = Path.Combine(_workingDirectory, projectReference.Name + ".dll");
                    if (!File.Exists(referencePath))
                    {
                        DiagnosticResult diagnostics = projectReference.EmitAssembly(_workingDirectory);
                        diagnosticResults.Add(diagnostics);
                    }

                    processedIncomingReferences.Add(new MetadataFileReference(projectReference.Name, referencePath));
                }
                else
                {
                    processedIncomingReferences.Add(reference);
                }
            }

            var compilationContext = _compiler.CompileProject(
                projectContext,
                processedIncomingReferences,
                incomingSourceReferences,
                resourcesResolver);

            if (compilationContext == null)
            {
                return(null);
            }

            compilationContext.Modules.Add(module);

            // Project reference
            return(new PostSharpProjectReference(new RoslynProjectReference(compilationContext), diagnosticResults, _workingDirectory));
        }
コード例 #2
0
        public IMetadataProjectReference CompileProject(
            CompilationProjectContext projectContext,
            Func<LibraryExport> referenceResolver,
            Func<IList<ResourceDescriptor>> resourcesResolver)
        {
            List<DiagnosticResult> diagnosticResults = new List<DiagnosticResult>();

            var module = new PostSharpCompilerModule(_services, _workingDirectory);

            var export = referenceResolver();
            if (export == null)
            {
                return null;
            }

            var incomingReferences = export.MetadataReferences;
            var incomingSourceReferences = export.SourceReferences;

            var processedIncomingReferences = new List<IMetadataReference>(incomingReferences.Count);

            foreach ( var reference in incomingReferences )
            {
                
                var projectReference = reference as IMetadataProjectReference;
                if ( projectReference != null )
                {
                    // If we have a PostSharpProjectReference, we have to compile it using EmitAssembly and replace the reference by a MetadataFileReference.
                    string referencePath = Path.Combine(_workingDirectory, projectReference.Name + ".dll");
                    if (!File.Exists(referencePath))
                    {
                        DiagnosticResult diagnostics = projectReference.EmitAssembly(_workingDirectory);
                        diagnosticResults.Add(diagnostics);
                    }

                    processedIncomingReferences.Add(new MetadataFileReference(projectReference.Name, referencePath));

                }
                else
                {
                    processedIncomingReferences.Add(reference);
                }

                
            }

            var compilationContext = _compiler.CompileProject(
                projectContext,
                processedIncomingReferences,
                incomingSourceReferences,
                resourcesResolver);

            if (compilationContext == null)
            {
                return null;
            }

            compilationContext.Modules.Add(module);

            // Project reference
            return new PostSharpProjectReference( new RoslynProjectReference(compilationContext), diagnosticResults, _workingDirectory );
        }