private static Eligibility GetInputFileEligibility(ITaskItem file, HashSet <string> exclusionSet) { // Check to see if this is a valid ILOnly image that we can compile using (FileStream fs = new FileStream(file.ItemSpec, FileMode.Open, FileAccess.Read)) { try { using (var pereader = new PEReader(fs)) { if (!pereader.HasMetadata) { return(Eligibility.None); } MetadataReader mdReader = pereader.GetMetadataReader(); if (!mdReader.IsAssembly) { return(Eligibility.None); } if (IsReferenceAssembly(mdReader)) { // crossgen can only take implementation assemblies, even as references return(Eligibility.None); } if ((pereader.PEHeaders.CorHeader.Flags & CorFlags.ILOnly) != CorFlags.ILOnly) { return(Eligibility.ReferenceOnly); } if (file.HasMetadataValue(MetadataKeys.ReferenceOnly, "true")) { return(Eligibility.ReferenceOnly); } if (exclusionSet != null && exclusionSet.Contains(Path.GetFileName(file.ItemSpec))) { return(Eligibility.ReferenceOnly); } // save these most expensive checks for last. We don't want to scan all references for IL code if (ReferencesWinMD(mdReader) || !HasILCode(pereader, mdReader)) { return(Eligibility.ReferenceOnly); } return(Eligibility.CompileAndReference); } } catch (BadImageFormatException) { // Not a valid assembly file return(Eligibility.None); } } }
private static bool IsNuGetReference(ITaskItem reference) { return(reference.HasMetadataValue("NuGetSourceType") && !reference.HasMetadataValue("NuGetIsFrameworkReference", "true")); }
public static bool IsProjectReference(ITaskItem reference) { return(reference.HasMetadataValue(MetadataKeys.ReferenceSourceTarget, "ProjectReference")); }
private static Eligibility GetInputFileEligibility(ITaskItem file, bool compositeCompile, HashSet <string> exclusionSet, HashSet <string> r2rCompositeExclusionSet) { // Check to see if this is a valid ILOnly image that we can compile if (!file.ItemSpec.EndsWith(".dll", StringComparison.OrdinalIgnoreCase) && !file.ItemSpec.EndsWith(".exe", StringComparison.OrdinalIgnoreCase)) { // If it isn't a dll or an exe, it certainly isn't a valid ILOnly image for compilation return(Eligibility.None); } using (FileStream fs = new FileStream(file.ItemSpec, FileMode.Open, FileAccess.Read)) { try { using (var pereader = new PEReader(fs)) { if (!pereader.HasMetadata) { return(Eligibility.None); } MetadataReader mdReader = pereader.GetMetadataReader(); if (!mdReader.IsAssembly) { return(Eligibility.None); } if (IsReferenceAssembly(mdReader)) { // crossgen can only take implementation assemblies, even as references return(Eligibility.None); } bool excludeFromR2R = (exclusionSet != null && exclusionSet.Contains(Path.GetFileName(file.ItemSpec))); bool excludeFromComposite = (r2rCompositeExclusionSet != null && r2rCompositeExclusionSet.Contains(Path.GetFileName(file.ItemSpec))) || excludeFromR2R; if ((pereader.PEHeaders.CorHeader.Flags & CorFlags.ILOnly) != CorFlags.ILOnly) { // This can happen due to C++/CLI binaries or due to previously R2R compiled binaries. if (!IsNonCompositeReadyToRunImage(pereader)) { // For C++/CLI always treat as only a reference return(Eligibility.CreateReferenceEligibility(excludeFromComposite)); } else { // If previously compiled as R2R, treat as reference if this would be compiled separately if (!compositeCompile || excludeFromComposite) { return(Eligibility.CreateReferenceEligibility(excludeFromComposite)); } } } if (file.HasMetadataValue(MetadataKeys.ReferenceOnly, "true")) { return(Eligibility.CreateReferenceEligibility(excludeFromComposite)); } if (excludeFromR2R) { return(Eligibility.CreateReferenceEligibility(excludeFromComposite)); } // save these most expensive checks for last. We don't want to scan all references for IL code if (ReferencesWinMD(mdReader) || !HasILCode(mdReader)) { // Forwarder assemblies are not separately compiled via R2R, but when performing composite compilation, they are included in the bundle if (excludeFromComposite || !compositeCompile) { return(Eligibility.CreateReferenceEligibility(excludeFromComposite)); } } return(Eligibility.CreateCompileEligibility(!compositeCompile || excludeFromComposite)); } } catch (BadImageFormatException) { // Not a valid assembly file return(Eligibility.None); } } }