Beispiel #1
0
        // Generate the combines dependencies from the projectjson jObject and from AdditionalDependencies
        private JObject GenerateDependencies(JObject projectJsonRoot, string framework = null)
        {
            var originalDependenciesList = new List <JToken>();
            var returnDependenciesList   = new List <JToken>();
            var frameworkDependencies    = GetFrameworkDependenciesSection(projectJsonRoot, framework);

            if (frameworkDependencies != null)
            {
                originalDependenciesList = frameworkDependencies.Children().ToList();

                // Update versions in dependencies
                foreach (JProperty property in originalDependenciesList.Select(od => od))
                {
                    NuGetVersion nuGetVersion;
                    if (NuGetVersion.TryParse(property.Value.ToString(), out nuGetVersion))
                    {
                        Match m = _versionStructureRegex.Match(nuGetVersion.ToString());

                        if (m.Success)
                        {
                            NuGetVersion dependencyVersion = nuGetVersion;
                            nuGetVersion = NuGetVersion.Parse(string.Join(".", dependencyVersion.Major, dependencyVersion.Minor, dependencyVersion.Patch) + "-" + PackageBuildNumberOverride);
                        }
                    }
                    // Only add the original dependency if it wasn't passed as an AdditionalDependency, ie. AdditionalDependencies may override dependencies in project.json
                    if (AdditionalDependencies.FirstOrDefault(d => d.GetMetadata("Name").Equals(property.Name, StringComparison.OrdinalIgnoreCase)) == null)
                    {
                        JProperty addProperty;
                        if (nuGetVersion != null)
                        {
                            addProperty = new JProperty(property.Name, nuGetVersion.ToString());
                        }
                        else
                        {
                            addProperty = property;
                        }
                        returnDependenciesList.Add(addProperty);
                    }
                }
            }

            foreach (var dependency in AdditionalDependencies)
            {
                string name = dependency.GetMetadata("Name");
                // Don't add a new dependency if one already exists.
                if (returnDependenciesList.FirstOrDefault(rd => ((JProperty)rd).Name.Equals(name)) == null)
                {
                    NuGetVersion dependencyVersion = NuGetVersion.Parse(dependency.GetMetadata("Version"));

                    string version = string.Join(".", dependencyVersion.Major, dependencyVersion.Minor, dependencyVersion.Patch);
                    if (!string.IsNullOrWhiteSpace(PackageBuildNumberOverride))
                    {
                        version += "-" + PackageBuildNumberOverride;
                    }
                    JProperty property = new JProperty(name, version);
                    returnDependenciesList.Add(property);
                }
                else
                {
                    Log.LogMessage("Ignoring AdditionalDependency '{0}', dependency is already present in {1}", name, ProjectJson);
                }
            }

            return(new JObject(returnDependenciesList.ToArray()));
        }
        // Generate the combines dependencies from the projectjson jObject and from AdditionalDependencies
        private JObject GenerateDependencies(JObject projectJsonRoot, ITaskItem[] externalPackageVersions, IEnumerable <ITaskItem> packageInformation, string framework = null)
        {
            var originalDependenciesList = new List <JToken>();
            var returnDependenciesList   = new List <JToken>();
            var frameworkDependencies    = GetFrameworkDependenciesSection(projectJsonRoot, framework);

            if (frameworkDependencies != null)
            {
                originalDependenciesList = frameworkDependencies.Children().ToList();

                // Update versions in dependencies
                foreach (JProperty property in originalDependenciesList.Select(od => od))
                {
                    ITaskItem package = GetPackageInformation(property.Name, packageInformation);

                    if (package != null)
                    {
                        NuGetVersion nuGetVersion;
                        if (NuGetVersion.TryParse(property.Value.ToString(), out nuGetVersion))
                        {
                            NuGetVersion dependencyVersion = nuGetVersion;
                            string       ver = null;

                            // a package version was provided, use its version information.
                            ver = package.GetMetadata("Version");

                            string prereleaseVersion = package.GetMetadata("Prerelease");
                            // we have package information, so use that.
                            if (!string.IsNullOrWhiteSpace(prereleaseVersion))
                            {
                                ver += "-" + prereleaseVersion;
                            }
                            nuGetVersion = NuGetVersion.Parse(ver);
                        }

                        // Only add the original dependency if it wasn't passed as an AdditionalDependency, ie. AdditionalDependencies may override dependencies in project.json
                        if (AdditionalDependencies.FirstOrDefault(d => d.GetMetadata("Name").Equals(property.Name, StringComparison.OrdinalIgnoreCase)) == null)
                        {
                            JProperty addProperty;
                            if (nuGetVersion != null)
                            {
                                addProperty = new JProperty(property.Name, nuGetVersion.ToString());
                            }
                            else
                            {
                                addProperty = property;
                            }
                            returnDependenciesList.Add(addProperty);
                        }
                    }
                    else
                    {
                        returnDependenciesList.Add(property);
                    }
                }
            }

            foreach (var dependency in AdditionalDependencies)
            {
                string name = dependency.GetMetadata("Name");
                // Don't add a new dependency if one already exists.
                if (returnDependenciesList.FirstOrDefault(rd => ((JProperty)rd).Name.Equals(name)) == null)
                {
                    ITaskItem package = GetPackageInformation(name, packageInformation);
                    string    version = null;

                    NuGetVersion dependencyVersion = NuGetVersion.Parse(dependency.GetMetadata("Version"));
                    version = string.Join(".", dependencyVersion.Major, dependencyVersion.Minor, dependencyVersion.Patch);

                    // a package version was provided, use its version information.
                    if (package != null)
                    {
                        version = package.GetMetadata("Version");
                        string prereleaseVersion = package.GetMetadata("Prerelease");
                        if (!string.IsNullOrWhiteSpace(prereleaseVersion))
                        {
                            version += "-" + prereleaseVersion;
                        }
                    }
                    JProperty property = new JProperty(name, version);
                    returnDependenciesList.Add(property);
                }
                else
                {
                    Log.LogMessage("Ignoring AdditionalDependency '{0}', dependency is already present in {1}", name, ProjectJson);
                }
            }

            return(new JObject(returnDependenciesList.ToArray()));
        }