コード例 #1
0
        public override bool Execute()
        {
            var configFilePath = new FileInfo(Path.Combine(ProjectDirectory, FileName));

            if (!configFilePath.Exists)
            {
                Log.LogWarning(configFilePath.Name + " does not exist");
                return(true);
            }

            var sw = new Stopwatch();

            sw.Start();

            BuildEngine3.Yield();
            CancellationToken token = CancellationToken.None;

            Log.LogMessage(MessageImportance.High, Environment.NewLine + Resources.Text.RestoringLibraries);

            var      dependencies = Dependencies.FromTask(this);
            Manifest manifest     = Manifest.FromFileAsync(configFilePath.FullName, dependencies, token).Result;

            IEnumerable <ILibraryInstallationResult> results = manifest.RestoreAsync(token).Result;

            BuildEngine3.Reacquire();

            sw.Stop();

            PopulateFilesWritten(results, dependencies.GetHostInteractions());
            LogResults(sw, results);

            return(!Log.HasLoggedErrors);
        }
コード例 #2
0
        public override bool Execute()
        {
            if (YieldDuringToolExecution)
            {
                BuildEngine3.Yield();
            }

            Initialize();

            var result = true;

            try
            {
                Exception executionErrors = null;
                result = new ParallelExecutor(OutdatedTasks, EndToken).Execute(out executionErrors);
                if (executionErrors is object)
                {
                    throw executionErrors;
                }
            }
            catch (AggregateException e)
            {
                var origin = e.InnerException as OperationCanceledException;

                if (origin is object && result)
                {
                    Log.LogWarning("The build task has been canceled.");
                }
                else
                {
                    var errors = e.InnerExceptions.Where(a => a as OperationCanceledException == null);
                    if (errors.Any())
                    {
                        foreach (var error in errors)
                        {
                            Log.LogErrorFromException(error, true);
                        }
                    }
                    else
                    {
                        Log.LogErrorFromException(e, false);
                    }

                    result = false;
                }
            }
            finally
            {
                result = FinishBuild(0) == 0 && result;
            }

            if (YieldDuringToolExecution)
            {
                BuildEngine3.Reacquire();
            }

            return(result);
        }
コード例 #3
0
 private bool ExecuteCore()
 {
     var assemblyNameToProjectFile =
         JsonConvert.DeserializeObject<Dictionary<string, LiveReferenceData>>(File.ReadAllText(LiveReferenceCacheFile));
     var referencePaths = new List<ITaskItem>();
     var referencedProjects = new List<LiveReferenceData>();
     foreach (var reference in References)
     {
         var assemblyName = reference.GetMetadata("FileName");
         LiveReferenceData referenceData;
         if (assemblyNameToProjectFile.TryGetValue(assemblyName, out referenceData))
         {
             referencedProjects.Add(referenceData);
         }
         else
         {
             referencePaths.Add(reference);
         }
     }
     var additionalAssemblyReferences =
         AdditionalAssemblyReferences.Split(';').Where(s => !string.IsNullOrEmpty(s)).ToList();
     foreach (var assemblyName in additionalAssemblyReferences)
     {
         referencedProjects.Add(assemblyNameToProjectFile[assemblyName]);
     }
     var projectsToBuild = new List<string>();
     foreach (var liveReference in referencedProjects)
     {
         if (!File.Exists(liveReference.TargetPath))
         {
             Log.LogMessage(MessageImportance.Normal, "Reference '{0}' doesn't exist. It will be built.", liveReference.TargetPath);
             projectsToBuild.Add(liveReference.Project);
         }
         else
         {
             Log.LogMessage(MessageImportance.Normal, "Reference '{0}' exists", liveReference.TargetPath);
         }
     }
     BuildEngineResult result = BuildEngine3.BuildProjectFilesInParallel(
         projectsToBuild.ToArray(),
         "Build",
         new Dictionary<string, string>(),
         new[] {"CustomAfterBuildCommonTargets"},
         null,
         false
     );
     if (!result.Result)
     {
         Log.LogError("Failed to resolve references.");
         return false;
     }
     referencePaths.AddRange(referencedProjects.Select(p => new TaskItem(p.TargetPath)));
     ReferencePaths = referencePaths.ToArray();
     return true;
 }
コード例 #4
0
ファイル: ZipDirectory.cs プロジェクト: 3F/IeXod
        public override bool Execute()
        {
            DirectoryInfo sourceDirectory = new DirectoryInfo(SourceDirectory.ItemSpec);

            if (!sourceDirectory.Exists)
            {
                Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorDirectoryDoesNotExist", sourceDirectory.FullName);
                return(false);
            }

            FileInfo destinationFile = new FileInfo(DestinationFile.ItemSpec);

            BuildEngine3.Yield();

            try
            {
                if (destinationFile.Exists)
                {
                    if (!Overwrite)
                    {
                        Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFileExists", destinationFile.FullName);

                        return(false);
                    }

                    try
                    {
                        File.Delete(destinationFile.FullName);
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFailed", sourceDirectory.FullName, destinationFile.FullName, e.Message);

                        return(false);
                    }
                }

                try
                {
                    Log.LogMessageFromResources(MessageImportance.High, "ZipDirectory.Comment", sourceDirectory.FullName, destinationFile.FullName);
                    ZipFile.CreateFromDirectory(sourceDirectory.FullName, destinationFile.FullName);
                }
                catch (Exception e)
                {
                    Log.LogErrorWithCodeFromResources("ZipDirectory.ErrorFailed", sourceDirectory.FullName, destinationFile.FullName, e.Message);
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!Log.HasLoggedErrors);
        }
コード例 #5
0
        private bool ExecuteCore()
        {
            var properties = new Dictionary <string, string>();

            foreach (var prop in SetProperties.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries))
            {
                var key   = prop.Substring(0, prop.IndexOf('=')).Trim();
                var value = prop.Substring(prop.IndexOf('=') + 1).Trim();
                if (!string.IsNullOrEmpty(key))
                {
                    properties[key] = value;
                }
            }
            var projectFiles = CandidateReferenceProjects
                               .Select(p => p.GetMetadata("FullPath"))
                               .ToArray();
            var propertyArray = new IDictionary[projectFiles.Length];

            for (int i = 0; i < projectFiles.Length; i++)
            {
                propertyArray[i] = properties;
            }
            var removePropertiesArray = Enumerable.Repeat((IList <string>)UndefineProperties.Split(new[] { ';' }).Select(p => p.Trim()).Where(s => !string.IsNullOrEmpty(s)).ToArray(), propertyArray.Length).ToArray();
            BuildEngineResult result  = BuildEngine3.BuildProjectFilesInParallel(
                projectFiles,
                Enumerable.Repeat("GetTargetPath", projectFiles.Length).ToArray(),
                propertyArray,
                removePropertiesArray,
                new string[projectFiles.Length],
                true
                );

            if (!result.Result)
            {
                Log.LogError("Building 'GetTargetPath' Failed.");
                return(false);
            }
            var assemblyNameToProject = new Dictionary <string, LiveReferenceData>();

            for (int i = 0; i < projectFiles.Length; i++)
            {
                string projectFile = projectFiles[i];
                IDictionary <string, ITaskItem[]> targetOutputs = result.TargetOutputsPerProject[i];
                ITaskItem targetPath   = targetOutputs["GetTargetPath"].First();
                string    assemblyName = targetPath.GetMetadata("FileName");
                assemblyNameToProject[assemblyName] = new LiveReferenceData
                {
                    Project    = projectFile,
                    TargetPath = targetPath.GetMetadata("FullPath")
                };
            }
            File.WriteAllText(LiveReferenceCacheFile, JsonConvert.SerializeObject(assemblyNameToProject, Formatting.Indented));
            return(true);
        }
コード例 #6
0
        public override bool Execute()
        {
            DirectoryInfo sourceDirectory = new DirectoryInfo(SourceDirectory.ItemSpec);

            if (!sourceDirectory.Exists)
            {
                Log.LogError($"Directory doesn't exist: {sourceDirectory.FullName}");
                return(false);
            }

            FileInfo destinationFile = new FileInfo(DestinationFile.ItemSpec);

            BuildEngine3.Yield();

            try
            {
                if (destinationFile.Exists)
                {
                    if (!Overwrite)
                    {
                        Log.LogError($"File exists: {destinationFile.FullName}");
                        return(false);
                    }

                    try
                    {
                        File.Delete(destinationFile.FullName);
                    }
                    catch (Exception e)
                    {
                        Log.LogErrorFromException(e, showStackTrace: true);
                        return(false);
                    }
                }

                try
                {
                    ZipFile.CreateFromDirectory(sourceDirectory.FullName, destinationFile.FullName);
                }
                catch (Exception e)
                {
                    Log.LogErrorFromException(e, showStackTrace: true);
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!Log.HasLoggedErrors);
        }
コード例 #7
0
        /// <inheritdoc cref="Task.Execute"/>
        public override bool Execute()
        {
            DirectoryInfo destinationDirectory;

            try {
                destinationDirectory = Directory.CreateDirectory(DestinationFolder.ItemSpec);
            } catch (Exception e) {
                Log.LogError("MSB3931: Failed to unzip to directory \"{0}\" because it could not be created.  {1}", DestinationFolder.ItemSpec, e.Message);

                return(false);
            }

            BuildEngine3.Yield();

            try {
                foreach (ITaskItem sourceFile in SourceFiles.TakeWhile(i => !_cancellationToken.IsCancellationRequested))
                {
                    if (!File.Exists(sourceFile.ItemSpec))
                    {
                        Log.LogError("MSB3932: Failed to unzip file \"{0}\" because the file does not exist or is inaccessible.", sourceFile.ItemSpec);
                        continue;
                    }

                    try {
                        using (FileStream stream = new FileStream(sourceFile.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 0x1000, useAsync: false)) {
                            using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false)) {
                                try {
                                    Extract(zipArchive, destinationDirectory);
                                } catch (Exception e) {
                                    // Unhandled exception in Extract() is a bug!
                                    Log.LogErrorFromException(e, showStackTrace: true);
                                    return(false);
                                }
                            }
                        }
                    } catch (OperationCanceledException) {
                        break;
                    } catch (Exception e) {
                        // Should only be thrown if the archive could not be opened (Access denied, corrupt file, etc)
                        Log.LogError("MSB3933: Failed to open zip file \"{0}\".  {1}", sourceFile.ItemSpec, e.Message);
                    }
                }
            } finally {
                BuildEngine3.Reacquire();
            }

            return(!_cancellationToken.IsCancellationRequested && !Log.HasLoggedErrors);
        }
コード例 #8
0
        protected int ProcessTasks()
        {
            int errCode = -1;

            if (taskScheduler.Count > 0)
            {
                string readTLogFName  = TaskName + ".read.1.tlog";
                string writeTLogFName = TaskName + ".write.1.tlog";
                string readTLog       = Path.Combine(TrackerIntermediateDirectory, readTLogFName);
                string writeTLog      = Path.Combine(TrackerIntermediateDirectory, writeTLogFName);
                if (!File.Exists(readTLog))
                {
                    using (File.Create(readTLog)) { }
                }
                if (!File.Exists(writeTLog))
                {
                    using (File.Create(writeTLog)) { }
                }

                try
                {
                    BuildEngine3.Yield();
                    if (taskScheduler.Run(cts, Log, SchedulerVerbose))
                    {
                        errCode = 0;
                    }
                }
                finally
                {
                    BuildEngine3.Reacquire();
                }
                if (!cts.IsCancellationRequested)
                {
                    _FinishBuild(0);
                }
            }
            else
            {
                errCode = 0;
            }
            return(errCode);
        }
コード例 #9
0
        public override bool Execute()
        {
            DirectoryInfo destinationDirectory;

            try
            {
                destinationDirectory = Directory.CreateDirectory(DestinationFolder.ItemSpec);
            }
            catch (Exception e)
            {
                Log.LogErrorWithCodeFromResources("Unzip.ErrorCouldNotCreateDestinationDirectory", DestinationFolder.ItemSpec, e.Message);

                return(false);
            }

            BuildEngine3.Yield();

            try
            {
                ParseIncludeExclude();

                if (!Log.HasLoggedErrors)
                {
                    foreach (ITaskItem sourceFile in SourceFiles.TakeWhile(i => !_cancellationToken.IsCancellationRequested))
                    {
                        if (!FileSystems.Default.FileExists(sourceFile.ItemSpec))
                        {
                            Log.LogErrorWithCodeFromResources("Unzip.ErrorFileDoesNotExist", sourceFile.ItemSpec);
                            continue;
                        }

                        try
                        {
                            using (FileStream stream = new FileStream(sourceFile.ItemSpec, FileMode.Open, FileAccess.Read, FileShare.Read, bufferSize: 0x1000, useAsync: false))
                            {
                                using (ZipArchive zipArchive = new ZipArchive(stream, ZipArchiveMode.Read, leaveOpen: false))
                                {
                                    try
                                    {
                                        Extract(zipArchive, destinationDirectory);
                                    }
                                    catch (Exception e)
                                    {
                                        // Unhandled exception in Extract() is a bug!
                                        Log.LogErrorFromException(e, showStackTrace: true);
                                        return(false);
                                    }
                                }
                            }
                        }
                        catch (OperationCanceledException)
                        {
                            break;
                        }
                        catch (Exception e)
                        {
                            // Should only be thrown if the archive could not be opened (Access denied, corrupt file, etc)
                            Log.LogErrorWithCodeFromResources("Unzip.ErrorCouldNotOpenFile", sourceFile.ItemSpec, e.Message);
                        }
                    }
                }
            }
            finally
            {
                BuildEngine3.Reacquire();
            }

            return(!_cancellationToken.IsCancellationRequested && !Log.HasLoggedErrors);
        }