示例#1
0
        private static BuildInfo CreateBuildInfo(ITaskItem item, string cacheDir)
        {
            string rawUrl = item.GetMetadata(RawUrlMetadataName);

            if (!string.IsNullOrEmpty(rawUrl))
            {
                return(BuildInfo.Get(item.ItemSpec, rawUrl));
            }

            string rawVersionsBaseUrl = item.GetMetadata(RawVersionsBaseUrlMetadataName);
            string buildInfoPath      = item.GetMetadata(BuildInfoPathMetadataName);
            string currentRef         = item.GetMetadata(CurrentRefMetadataName);

            // Optional: override base url with a local directory.
            string versionsRepoDir = item.GetMetadata(VersionsRepoDirMetadataName);

            if (!string.IsNullOrEmpty(versionsRepoDir) &&
                !string.IsNullOrEmpty(buildInfoPath))
            {
                return(BuildInfo.LocalFileGetAsync(
                           item.ItemSpec,
                           versionsRepoDir,
                           buildInfoPath,
                           // Don't fetch latest release file: it may not be present in build from source.
                           fetchLatestReleaseFile: false).Result);
            }

            if (!string.IsNullOrEmpty(rawVersionsBaseUrl) &&
                !string.IsNullOrEmpty(buildInfoPath) &&
                !string.IsNullOrEmpty(currentRef))
            {
                return(BuildInfo.CachedGet(
                           item.ItemSpec,
                           rawVersionsBaseUrl,
                           currentRef,
                           buildInfoPath,
                           cacheDir));
            }

            string packageId = item.GetMetadata(PackageIdMetadataName);
            string version   = item.GetMetadata(VersionMetadataName);

            if (!string.IsNullOrEmpty(packageId) &&
                !string.IsNullOrEmpty(version))
            {
                return(new BuildInfo
                {
                    Name = item.ItemSpec,
                    LatestPackages = new Dictionary <string, string>
                    {
                        [packageId] = version
                    }
                });
            }

            throw new Exception($"Unable to create build info with '{item}'.");
        }
        private static BuildInfo CreateBuildInfo(ITaskItem item, string cacheDir)
        {
            string rawUrl = item.GetMetadata(RawUrlMetadataName);

            if (!string.IsNullOrEmpty(rawUrl))
            {
                return(BuildInfo.Get(item.ItemSpec, rawUrl));
            }

            string rawVersionsBaseUrl = item.GetMetadata(RawVersionsBaseUrlMetadataName);
            string buildInfoPath      = item.GetMetadata(BuildInfoPathMetadataName);
            string currentRef         = item.GetMetadata(CurrentRefMetadataName);
            // Optional
            string currentBranch = item.GetMetadata(CurrentBranchMetadataName);

            if (!string.IsNullOrEmpty(rawVersionsBaseUrl) &&
                !string.IsNullOrEmpty(buildInfoPath) &&
                !string.IsNullOrEmpty(currentRef))
            {
                if (!string.IsNullOrEmpty(currentBranch))
                {
                    buildInfoPath = $"{buildInfoPath}/{currentBranch}";
                }

                return(BuildInfo.CachedGet(
                           item.ItemSpec,
                           rawVersionsBaseUrl,
                           currentRef,
                           buildInfoPath,
                           cacheDir));
            }

            string packageId = item.GetMetadata(PackageIdMetadataName);
            string version   = item.GetMetadata(VersionMetadataName);

            if (!string.IsNullOrEmpty(packageId) &&
                !string.IsNullOrEmpty(version))
            {
                return(new BuildInfo
                {
                    Name = item.ItemSpec,
                    LatestPackages = new Dictionary <string, string>
                    {
                        [packageId] = version
                    }
                });
            }

            throw new Exception($"Unable to create build info with '{item}'.");
        }