private async Task SetBuildConfigurationIdFromName()
        {
            this.Logger.LogDebug("Attempting to resolve build configuration ID from project and name...");
            using (var client = new TeamCityWebClient(this.ConnectionInfo))
            {
                this.Logger.LogDebug("Downloading build types...");
                string result = await client.DownloadStringTaskAsync("app/rest/buildTypes").ConfigureAwait(false);

                var doc = XDocument.Parse(result);
                var buildConfigurations = from e in doc.Element("buildTypes").Elements("buildType")
                                          let buildType = new BuildType(e)
                                                          where string.Equals(buildType.BuildConfigurationName, this.BuildConfigurationName, StringComparison.OrdinalIgnoreCase)
                                                          let match = new
                {
                    BuildType = buildType,
                    Index     = Array.FindIndex(buildType.ProjectNameParts, p => string.Equals(p, this.ProjectName, StringComparison.OrdinalIgnoreCase))
                }
                where match.Index > -1 || string.Equals(match.BuildType.ProjectName, this.ProjectName, StringComparison.OrdinalIgnoreCase)
                orderby match.Index
                select match.BuildType.BuildConfigurationId;

                this.BuildConfigurationId = buildConfigurations.FirstOrDefault();
                if (this.BuildConfigurationId == null)
                {
                    throw new ExecutionFailureException($"Build configuration ID could not be found for project \"{this.ProjectName}\" and build configuration \"{this.BuildConfigurationName}\".");
                }

                this.Logger.LogDebug("Build configuration ID resolved to: " + this.BuildConfigurationId);
            }
        }
        private async Task <string> GetActualBuildNumber()
        {
            this.Logger.LogDebug("Resolving actual build number...");

            string apiUrl = this.TryGetPredefinedConstantBuildNumberApiUrl(this.BuildNumber);

            if (apiUrl == null)
            {
                this.Logger.LogDebug("Using explicit build number: {0}", this.BuildNumber);
                return(this.BuildNumber);
            }

            this.Logger.LogDebug("Build number is the predefined constant \"{0}\", resolving...", this.BuildNumber);

            try
            {
                if (this.BranchName != null)
                {
                    apiUrl += ",branch:" + Uri.EscapeDataString(this.BranchName);
                }

                using (var client = new TeamCityWebClient(this.ConnectionInfo))
                {
                    string xml = await client.DownloadStringTaskAsync(apiUrl).ConfigureAwait(false);

                    var doc = XDocument.Parse(xml);
                    return(doc.Element("builds").Element("build").Attribute("number").Value);
                }
            }
            catch (Exception ex)
            {
                this.Logger.LogError("Could not parse actual build number from TeamCity. Exception details: " + ex);
                return(null);
            }
        }