Beispiel #1
0
        public Task <bool> ExecuteAsync(CancellationToken token = default)
        {
            // parse
            var(pluginType, excludedMethods, pluginClass, pluginAssemblyName) = AnalyzeAssembly(AssemblyFile);

            _log.LogMessage($"PluginAssembly: {pluginAssemblyName.FullName}");
            _log.LogMessage($"Type:           {pluginType}");
            _log.LogMessage($"Class:          {pluginClass}");
            _log.LogInfo($"ExcludedMethods:");
            foreach (var method in excludedMethods)
            {
                _log.LogInfo($"    {method}");
            }

            var outDir  = IntermediateDirectory.CreateSubdirectory("out");
            var workDir = IntermediateDirectory.CreateSubdirectory(nameof(TcBuild));

            var outFile   = new FileInfo(Path.Combine(outDir.FullName, GetOutputFileName(pluginType, x64: false)));
            var outFile64 = new FileInfo(Path.Combine(outDir.FullName, GetOutputFileName(pluginType, x64: true)));

            // .config
            var config = new FileInfo(AssemblyFile.FullName + ".config");

            try {
                token.ThrowIfCancellationRequested();

                // process
                var wrapperSource = ProcessSource(pluginType, excludedMethods, pluginClass, pluginAssemblyName);
                _log.LogInfo($"{wrapperSource.FullName}");

                token.ThrowIfCancellationRequested();

                // ico resource
                FileInfo resFile = new FileInfo(Path.Combine(workDir.FullName, $"{AssemblyFile.Name}.res"));
                _tools.TryCreateResFile(AssemblyFile, resFile);

                // create: x86
                _tools.Assemble(wrapperSource, outFile, resFile, false, IsRelease);
                _log.LogInfo($"{outFile.FullName}");

                token.ThrowIfCancellationRequested();

                // create: x64
                _tools.Assemble(wrapperSource, outFile64, resFile, true, IsRelease);
                _log.LogInfo($"{outFile64.FullName}");

                token.ThrowIfCancellationRequested();

                // Zip
                if (pluginType != PluginType.QuickSearch)
                {
                    var zipFile = new FileInfo(Path.Combine(outDir.FullName, Path.ChangeExtension(AssemblyFile.Name, ".zip")));
                    var iniFile = new FileInfo(Path.Combine(workDir.FullName, "pluginst.inf"));

                    _log.LogInfo(zipFile.FullName);

                    CreatePluginstFile(iniFile, outFile, pluginType);

                    var success = _tools.CreateZip(zipFile,
                                                   new[] {
                        iniFile,
                        outFile,
                        outFile64,
                        config,
                        AssemblyFile,
                        new FileInfo(Path.ChangeExtension(AssemblyFile.FullName, ".pdb")),
                    }.Concat(ReferenceFiles.Where(_ => _.Extension != ".xml" && _.Name != "TcPluginBase.dll")
                             // Hotfix until my pull request gets merged: https://github.com/peters/ILRepack.MSBuild.Task/pull/42
                             //.Where(_ => _.Name != "Microsoft.Build.Framework.dll")
                             //.Where(_ => _.Name != "Microsoft.Build.Utilities.Core.dll")
                             //.Where(_ => _.Name != "System.Collections.Immutable.dll")
                             ),
                                                   GetSatelliteAssemblyFiles()
                                                   );
                    if (!success)
                    {
                        _log.LogWarning("ZIP Archiver is not found - Installation Archive is not created.");
                    }
                }

                token.ThrowIfCancellationRequested();

                return(Task.FromResult(true));
            }
            finally {
                // Cleanup
                //AssemblyFile.Delete();
                workDir.Delete(true);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Performs a C# build analysis.
        /// </summary>
        /// <param name="options">Analysis options from the command line.</param>
        /// <param name="progress">Display of analysis progress.</param>
        public BuildAnalysis(Options options, IProgressMonitor progress)
        {
            var startTime = DateTime.Now;

            progressMonitor = progress;
            var sourceDir = new DirectoryInfo(options.SrcDir);

            progressMonitor.FindingFiles(options.SrcDir);

            allSources = sourceDir.GetFiles("*.cs", SearchOption.AllDirectories)
                         .Select(d => d.FullName)
                         .Where(d => !options.ExcludesFile(d))
                         .ToArray();

            var dllDirNames = options.DllDirs.Select(Path.GetFullPath).ToList();

            packageDirectory = new TemporaryDirectory(ComputeTempDirectory(sourceDir.FullName));

            if (options.UseNuGet)
            {
                try
                {
                    var nuget = new NugetPackages(sourceDir.FullName, packageDirectory);
                    nuget.InstallPackages(progressMonitor);
                }
                catch (FileNotFoundException)
                {
                    progressMonitor.MissingNuGet();
                }
            }

            // Find DLLs in the .Net Framework
            if (options.ScanNetFrameworkDlls)
            {
                var runtimeLocation = Runtime.GetRuntime(options.UseSelfContainedDotnet);
                progressMonitor.Log(Util.Logging.Severity.Debug, $"Runtime location selected: {runtimeLocation}");
                dllDirNames.Add(runtimeLocation);
            }

            // These files can sometimes prevent `dotnet restore` from working correctly.
            using (new FileRenamer(sourceDir.GetFiles("global.json", SearchOption.AllDirectories)))
                using (new FileRenamer(sourceDir.GetFiles("Directory.Build.props", SearchOption.AllDirectories)))
                {
                    var solutions = options.SolutionFile is not null ?
                                    new[] { options.SolutionFile } :
                    sourceDir.GetFiles("*.sln", SearchOption.AllDirectories).Select(d => d.FullName);

                    if (options.UseNuGet)
                    {
                        RestoreSolutions(solutions);
                    }
                    dllDirNames.Add(packageDirectory.DirInfo.FullName);
                    assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress);
                    AnalyseSolutions(solutions);

                    foreach (var filename in assemblyCache.AllAssemblies.Select(a => a.Filename))
                    {
                        UseReference(filename);
                    }
                }

            ResolveConflicts();

            if (options.UseMscorlib)
            {
                UseReference(typeof(object).Assembly.Location);
            }

            // Output the findings
            foreach (var r in usedReferences.Keys)
            {
                progressMonitor.ResolvedReference(r);
            }

            foreach (var r in unresolvedReferences)
            {
                progressMonitor.UnresolvedReference(r.Key, r.Value);
            }

            progressMonitor.Summary(
                AllSourceFiles.Count(),
                ProjectSourceFiles.Count(),
                MissingSourceFiles.Count(),
                ReferenceFiles.Count(),
                UnresolvedReferences.Count(),
                conflictedReferences,
                succeededProjects + failedProjects,
                failedProjects,
                DateTime.Now - startTime);
        }
Beispiel #3
0
        /// <summary>
        /// Performs a C# build analysis.
        /// </summary>
        /// <param name="options">Analysis options from the command line.</param>
        /// <param name="progress">Display of analysis progress.</param>
        public BuildAnalysis(Options options, IProgressMonitor progress)
        {
            progressMonitor = progress;
            sourceDir       = new DirectoryInfo(options.SrcDir);

            progressMonitor.FindingFiles(options.SrcDir);

            allSources = sourceDir.GetFiles("*.cs", SearchOption.AllDirectories).
                         Select(d => d.FullName).
                         Where(d => !options.ExcludesFile(d)).
                         ToArray();

            var dllDirNames = options.DllDirs.Select(Path.GetFullPath);

            if (options.UseNuGet)
            {
                nuget = new NugetPackages(sourceDir.FullName);
                ReadNugetFiles();
                dllDirNames = dllDirNames.Concat(Enumerators.Singleton(nuget.PackageDirectory));
            }

            // Find DLLs in the .Net Framework
            if (options.ScanNetFrameworkDlls)
            {
                dllDirNames = dllDirNames.Concat(Runtime.Runtimes.Take(1));
            }

            assemblyCache = new BuildAnalyser.AssemblyCache(dllDirNames, progress);

            // Analyse all .csproj files in the source tree.
            if (options.SolutionFile != null)
            {
                AnalyseSolution(options.SolutionFile);
            }
            else if (options.AnalyseCsProjFiles)
            {
                AnalyseProjectFiles();
            }

            if (!options.AnalyseCsProjFiles)
            {
                usedReferences = new HashSet <string>(assemblyCache.AllAssemblies.Select(a => a.Filename));
            }

            ResolveConflicts();

            if (options.UseMscorlib)
            {
                UseReference(typeof(object).Assembly.Location);
            }

            // Output the findings
            foreach (var r in usedReferences)
            {
                progressMonitor.ResolvedReference(r);
            }

            foreach (var r in unresolvedReferences)
            {
                progressMonitor.UnresolvedReference(r.Key, r.Value);
            }

            progressMonitor.Summary(
                AllSourceFiles.Count(),
                ProjectSourceFiles.Count(),
                MissingSourceFiles.Count(),
                ReferenceFiles.Count(),
                UnresolvedReferences.Count(),
                conflictedReferences,
                succeededProjects + failedProjects,
                failedProjects);
        }