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;
 }
예제 #2
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);
        }