Esempio n. 1
0
        protected override bool ValidateValues()
        {
            // If nothing is set, default to ShowNonPortableApis
            if ((RequestFlags & (AnalyzeRequestFlags.ShowBreakingChanges | AnalyzeRequestFlags.ShowNonPortableApis)) == AnalyzeRequestFlags.None)
            {
                RequestFlags |= AnalyzeRequestFlags.ShowNonPortableApis;
            }

            return(InputAssemblies.Any());
        }
Esempio n. 2
0
        protected override string GenerateCommandLineCommands()
        {
            List <string> argv = new List <string>();

            argv.Add("-out:" + JarFile.GetMetadata("FullPath"));
            argv.AddRange(Namespaces.Select(x => "-namespace:" + x));
            argv.AddRange(InputAssemblies.Select(x => x.GetMetadata("FullPath")));

            return(string.Join(" ", argv.Select(x => $"\"{x}\"")));
        }
Esempio n. 3
0
        public override bool Execute()
        {
            var keptAssemblyNames = new HashSet <string> (
                KeptAssemblies.Select(i => Path.GetFileName(i.ItemSpec))
                );

            RemovedAssemblies = InputAssemblies.Where(i =>
                                                      !keptAssemblyNames.Contains(Path.GetFileName(i.ItemSpec))
                                                      ).ToArray();
            return(true);
        }
Esempio n. 4
0
        public string ToCommandLine()
        {
            StringBuilder commandLine = new StringBuilder();

            var assembliesArgument = InputAssemblies.Aggregate(
                string.Empty,
                (previous, item) => previous + ' ' + item);

            commandLine.AppendLine("------------- IL Repack Arguments -------------");
            commandLine.Append($"/out:{OutputFile} ");
            commandLine.Append(!string.IsNullOrEmpty(KeyFile) ? $"/keyfile:{KeyFile} " : string.Empty);
            commandLine.Append(Internalize ? "/internalize" : string.Empty);
            commandLine.AppendLine(assembliesArgument);
            commandLine.Append("-----------------------------------------------");

            return(commandLine.ToString());
        }
Esempio n. 5
0
        protected override bool ValidateValues()
        {
            // If nothing is set, default to ShowNonPortableApis
            if ((RequestFlags & (AnalyzeRequestFlags.ShowBreakingChanges | AnalyzeRequestFlags.ShowNonPortableApis)) == AnalyzeRequestFlags.None)
            {
                RequestFlags |= AnalyzeRequestFlags.ShowNonPortableApis;
            }

            // If no output formats have been supplied, default to Excel
            // TODO: Should probably get this from the service, not hard-coded
            if (!OutputFormats.Any())
            {
                UpdateOutputFormats("Excel");
            }

            return(InputAssemblies.Any());
        }
Esempio n. 6
0
 public IList <string> ResolveFiles()
 {
     return(InputAssemblies.SelectMany(ResolveFile).Distinct().ToList());
 }
        public override bool RunTask()
        {
            var output  = new List <ITaskItem> ();
            var symbols = new Dictionary <string, ITaskItem> ();

            if (ResolvedSymbols != null)
            {
                foreach (var symbol in ResolvedSymbols)
                {
                    symbols [symbol.ItemSpec] = symbol;
                }
            }

            // Group by assembly file name
            foreach (var group in InputAssemblies.Where(Filter).GroupBy(a => Path.GetFileName(a.ItemSpec)))
            {
                // Get the unique list of MVIDs
                var  mvids = new HashSet <Guid> ();
                bool?frameworkAssembly = null, hasMonoAndroidReference = null;
                foreach (var assembly in group)
                {
                    using (var pe = new PEReader(File.OpenRead(assembly.ItemSpec))) {
                        var reader = pe.GetMetadataReader();
                        var module = reader.GetModuleDefinition();
                        var mvid   = reader.GetGuid(module.Mvid);
                        mvids.Add(mvid);

                        // Calculate %(FrameworkAssembly) and %(HasMonoAndroidReference) for the first
                        if (frameworkAssembly == null)
                        {
                            string packageId = assembly.GetMetadata("NuGetPackageId") ?? "";
                            frameworkAssembly = packageId.StartsWith("Microsoft.NETCore.App.Runtime.") ||
                                                packageId.StartsWith("Microsoft.Android.Runtime.");
                        }
                        if (hasMonoAndroidReference == null)
                        {
                            hasMonoAndroidReference = MonoAndroidHelper.HasMonoAndroidReference(reader);
                        }
                        assembly.SetMetadata("FrameworkAssembly", frameworkAssembly.ToString());
                        assembly.SetMetadata("HasMonoAndroidReference", hasMonoAndroidReference.ToString());
                    }
                }
                // If we end up with more than 1 unique mvid, we need *all* assemblies
                if (mvids.Count > 1)
                {
                    foreach (var assembly in group)
                    {
                        symbols.TryGetValue(Path.ChangeExtension(assembly.ItemSpec, ".pdb"), out var symbol);
                        SetDestinationSubDirectory(assembly, group.Key, symbol);
                        output.Add(assembly);
                    }
                }
                else
                {
                    // Otherwise only include the first assembly
                    bool first = true;
                    foreach (var assembly in group)
                    {
                        var symbolPath = Path.ChangeExtension(assembly.ItemSpec, ".pdb");
                        if (first)
                        {
                            first = false;
                            if (symbols.TryGetValue(symbolPath, out var symbol))
                            {
                                symbol.SetDestinationSubPath();
                            }
                            assembly.SetDestinationSubPath();
                            output.Add(assembly);
                        }
                        else
                        {
                            symbols.Remove(symbolPath);
                        }
                    }
                }
            }

            OutputAssemblies = output.ToArray();
            ResolvedSymbols  = symbols.Values.ToArray();

            // Set ShrunkAssemblies for _RemoveRegisterAttribute and <BuildApk/>
            if (PublishTrimmed)
            {
                ShrunkAssemblies = OutputAssemblies.Select(a => {
                    var dir  = Path.GetDirectoryName(a.ItemSpec);
                    var file = Path.GetFileName(a.ItemSpec);
                    return(new TaskItem(a)
                    {
                        ItemSpec = Path.Combine(dir, "shrunk", file),
                    });
                }).ToArray();
            }

            return(!Log.HasLoggedErrors);
        }
Esempio n. 8
0
        public override bool Execute()
        {
            if (string.IsNullOrEmpty(OutputFileName))
            {
                OutputFileName = InputAssemblies[0];
            }

            if (!Directory.Exists(Path.GetDirectoryName(OutputFileName)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(OutputFileName));
            }

            var cleanupExcludeFile = false;

            if (InternalizeExclude != null && InternalizeExclude.Length > 0)
            {
                InternalizeExcludeFile = Path.GetTempFileName();
                File.WriteAllLines(InternalizeExcludeFile, InternalizeExclude);
                cleanupExcludeFile = true;
            }

            var ilmSearchPath = Path.GetFullPath(Path.Combine(Assembly.GetExecutingAssembly().Location, "..", ".."));
            var ilMergePath   = Directory.GetFiles(ilmSearchPath, "ilmerge.exe", SearchOption.AllDirectories).Max();

            var args = new StringBuilder();

            if (SearchDirectories != null && SearchDirectories.Length > 0)
            {
                args.Append(string.Join("", SearchDirectories.Select(x => string.Format(@" /lib:""{0}""", x.TrimEnd('\\')))));
            }

            if (Log)
            {
                args.Append(" /log");
            }

            if (!string.IsNullOrWhiteSpace(InternalizeExcludeFile))
            {
                args.AppendFormat(@" /internalize:""{0}""", InternalizeExcludeFile);
            }
            else if (Internalize)
            {
                args.Append(" /internalize");
            }

            if (!string.IsNullOrWhiteSpace(TargetPlatform))
            {
                args.AppendFormat(@" /targetplatform:{0}", TargetPlatform);
            }
            if (!string.IsNullOrWhiteSpace(TargetPlatformDir))
            {
                args.AppendFormat(@",""{0}""", TargetPlatformDir);
            }

            if (WildCards)
            {
                args.Append(" /wildcards");
            }

            args.AppendFormat(@" /out:""{0}""", OutputFileName);

            args.Append(string.Join("", InputAssemblies.Select(x => @" """ + x + @"""")));

            var ilMergeProc = new ProcessHostRedirect()
            {
                FileName = ilMergePath, Arguments = args.ToString().Trim()
            };

            ilMergeProc.CommandLinePrefix = "";
            ilMergeProc.OutputDataHandler = (dataType, line) => { LogLine(line); };
            ilMergeProc.Execute();

            if (cleanupExcludeFile)
            {
                File.Delete(InternalizeExcludeFile);
            }

            return(true);
        }