internal CommonCompilationArguments(CompilerParameters parameters, CommandLineArguments cmdArguments)
        {
            this.cmdArguments       = cmdArguments;
            this.MetadataReferences = new List <MetadataReference>();
            ImmutableArray <CommandLineReference> .Enumerator enumerator = this.CmdArguments.MetadataReferences.GetEnumerator();
            while (enumerator.MoveNext())
            {
                CommandLineReference current = enumerator.Current;
                string reference             = current.Reference;
                string text = this.ResolveReference(this.CmdArguments, reference);
                if (text == null)
                {
                    throw new ArgumentException(string.Format(Res.Cannot_Resolve_Reference, reference));
                }
                var cache = AssemblyMetadataCache.GetInstance();

                var assemblyMetadata = cache.GetOrAdd(text, AssemblyMetadata.CreateFromFile);
                this.MetadataReferences.Add(assemblyMetadata.GetReference());
            }
            this.ParseOutputFile(parameters.OutputAssembly, this.CmdArguments.BaseDirectory, out this.outputFileName, out this.outputFileDirectory);
            this.FinalOutputPath = Path.Combine(this.OutputFileDirectory, this.OutputFileName);
            if (parameters.IncludeDebugInformation)
            {
                this.FinalPdbFilePath = (this.CmdArguments.PdbPath ?? Path.ChangeExtension(this.FinalOutputPath, ".pdb"));
            }
            string win32ResourceFile = this.CmdArguments.Win32ResourceFile;

            if (!string.IsNullOrWhiteSpace(win32ResourceFile))
            {
                this.Win32ResourceFile = Path.Combine(this.CmdArguments.BaseDirectory, win32ResourceFile);
            }
        }
Esempio n. 2
0
            private static PortableExecutableReference GetMetadateReference(CommandLineReference commandLineReference)
            {
                if (referenceCache.TryGetValue(commandLineReference.Reference, out var value))
                {
                    return(value);
                }
                else
                {
                    if (File.Exists(commandLineReference.Reference))
                    {
                        var reference = MetadataReference.CreateFromFile(commandLineReference.Reference);
                        referenceCache.TryAdd(commandLineReference.Reference, reference);
                        return(reference);
                    }

                    return(null);
                }
            }
Esempio n. 3
0
        internal static ImmutableArray<PortableExecutableReference> ResolveMetadataReference(CommandLineReference cmdReference, MetadataReferenceResolver metadataResolver, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(metadataResolver != null);
            Debug.Assert((diagnosticsOpt == null) == (messageProviderOpt == null));

            ImmutableArray<PortableExecutableReference> references;
            try
            {
                references = metadataResolver.ResolveReference(cmdReference.Reference, baseFilePath: null, properties: cmdReference.Properties);
            }
            catch (Exception e) when (diagnosticsOpt != null && (e is BadImageFormatException || e is IOException))
            {
                var diagnostic = PortableExecutableReference.ExceptionToDiagnostic(e, messageProviderOpt, Location.None, cmdReference.Reference, cmdReference.Properties.Kind);
                diagnosticsOpt.Add(((DiagnosticWithInfo)diagnostic).Info);
                return ImmutableArray<PortableExecutableReference>.Empty;
            }

            if (references.IsDefaultOrEmpty && diagnosticsOpt != null)
            {
                diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, cmdReference.Reference));
                return ImmutableArray<PortableExecutableReference>.Empty;
            }

            return references;
        }
Esempio n. 4
0
 static MetadataReference MakeReference(CommandLineReference reference, string path)
 {
     return(MetadataReference.CreateFromFile(path).WithProperties(reference.Properties));
 }
        // TODO: change to private protected when available
        internal static MetadataReference ResolveMetadataReference(CommandLineReference cmdReference, MetadataReferenceResolver metadataResolver, MetadataReferenceProvider metadataProvider, List<DiagnosticInfo> diagnosticsOpt, CommonMessageProvider messageProviderOpt)
        {
            Debug.Assert(metadataResolver != null);
            Debug.Assert(metadataProvider != null);
            Debug.Assert((diagnosticsOpt == null) == (messageProviderOpt == null));

            string resolvedPath = metadataResolver.ResolveReference(cmdReference.Reference, baseFilePath: null);
            if (resolvedPath == null)
            {
                if (diagnosticsOpt != null)
                {
                    diagnosticsOpt.Add(new DiagnosticInfo(messageProviderOpt, messageProviderOpt.ERR_MetadataFileNotFound, cmdReference.Reference));
                }

                return null;
            }

            try
            {
                return metadataProvider.GetReference(resolvedPath, cmdReference.Properties);
            }
            catch (Exception e) if (diagnosticsOpt != null && (e is BadImageFormatException || e is IOException))
            {
                var diagnostic = PortableExecutableReference.ExceptionToDiagnostic(e, messageProviderOpt, Location.None, cmdReference.Reference, cmdReference.Properties.Kind);
                diagnosticsOpt.Add(((DiagnosticWithInfo)diagnostic).Info);
                return null;
            }
        }

        #endregion

        #region Analyzer References

        /// <summary>
        /// Resolves analyzer references stored in <see cref="AnalyzerReferences"/> using given file resolver.
        /// </summary>
        /// <returns>Yields resolved <see cref="AnalyzerFileReference"/> or <see cref="UnresolvedAnalyzerReference"/>.</returns>
        public IEnumerable<AnalyzerReference> ResolveAnalyzerReferences()
        {
            foreach (CommandLineAnalyzerReference cmdLineReference in AnalyzerReferences)
            {
                yield return ResolveAnalyzerReference(cmdLineReference) 
                    ?? (AnalyzerReference)new UnresolvedAnalyzerReference(cmdLineReference.FilePath);
            }
        }