public void CloneTargets()
        {
            var hostServices = new HostServices();

            ProjectInstance first  = GetSampleProjectInstance(hostServices);
            ProjectInstance second = first.DeepCopy();

            // Targets, tasks are immutable so we can expect the same objects
            Assert.True(Object.ReferenceEquals(first.Targets, second.Targets));
            Assert.True(Object.ReferenceEquals(first.Targets["t"], second.Targets["t"]));

            var firstTasks  = first.Targets["t"];
            var secondTasks = second.Targets["t"];

            Assert.True(Object.ReferenceEquals(firstTasks.Children[0], secondTasks.Children[0]));
        }
        public ProjectInstance GetProjectInstanceById(int projectInstanceId)
        {
            ProjectInstance result = null;

            // the ProjectInstance.DeepCopy() can throw InvalidOperationException sporadically
            int numRetries = 0;

            while (numRetries < 10)
            {
                numRetries++;
                try {
                    // TODO: how to know if we have the correct project here?
                    result = projInst.DeepCopy();
                    // if we get to this point no need to loop any more
                    break;
                }
                catch (InvalidOperationException) { }
            }



            return(result);
        }