Esempio n. 1
0
        public NuGetDependencyGroup(Xml.NuGet.NuSpec.Group dependencyGroup) : this()
        {
            Group = dependencyGroup;

            _uiTargetFramework.Text = Group.TargetFramework;

            foreach (Xml.NuGet.NuSpec.Dependency dependency in dependencyGroup.Dependencies)
            {
                _uiDependencies.Items.Add(new NuGetDependency(dependency)
                {
                    OnRemoveFromDependencyGroup = OnDependencyRemovedFromGroup
                });
            }

            _uiItemsCount.Text = _uiDependencies.Items.Count.ToString();

            Refresh();
        }
Esempio n. 2
0
        /// <summary>
        /// determines the nuget dependecies form the package.config file if any
        /// </summary>
        /// <param name="activeProject">the project that is to be deployed</param>
        private void DetermineNuSpecDependecies(Project activeProject, PackageInformation packageInfo)
        {
            LoggingManager.Instance.Logger.Debug("determine nuspec dependencies started");

            if (packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.DependencyUsage == Definitions.Enumerations.NuGetDependencyUsage.None)
            {
                LoggingManager.Instance.Logger.Debug("usage of referenced nuget dependencies is disabled");
                return;
            }

            ProjectItem nuGetPackagesConfig = Utils.ExtensionUtil.GetItem(Resources.NuGetPackageFilename, activeProject.ProjectItems);

            if (nuGetPackagesConfig == null)
            {
                LoggingManager.Instance.Logger.Debug(string.Format("no {0} file not found in the solution, no dependencies will be added", Resources.NuGetPackageFilename));
                return;
            }

            LoggingManager.Instance.Logger.Debug(string.Format("{0} file found in the solution, dependencies will be added", Resources.NuGetPackageFilename));

            string fullname = Utils.ExtensionUtil.GetPropertyValue <string>(nuGetPackagesConfig.Properties, Resources.PropertyFullpath, null);

            LoggingManager.Instance.Logger.Debug(string.Format("fullname is {0}", fullname));

            if (!File.Exists(fullname))
            {
                LoggingManager.Instance.Logger.Warn("file does not exist");
                return;
            }

            //-----deserialize the packages file
            Xml.NuGet.Package.Packages packages = null;
            try
            {
                packages = XmlUtil.Deserialize <Xml.NuGet.Package.Packages>(fullname);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException || ex is ThreadInterruptedException)
                {
                    throw;
                }

                LoggingManager.Instance.Logger.Warn("file could not be deserialized", ex);
                return;
            }

            if (packages.Elements == null)
            {
                LoggingManager.Instance.Logger.Warn("file does not provide any package");
                return;
            }

            //-----prepate the nuspec dependencies
            if (packageInfo.NuSpecPackage.Metadata.DependencyGroups == null)
            {
                packageInfo.NuSpecPackage.Metadata.DependencyGroups = new List <Xml.NuGet.NuSpec.Group>();
            }

            packageInfo.NuSpecPackage.Metadata.DependencyGroups.Clear();

            //-----get the packages and add them using the targetframework if any
            foreach (Xml.NuGet.Package.Package package in packages.Elements)
            {
                if (string.IsNullOrEmpty(package.Id) || string.IsNullOrEmpty(package.Version))
                {
                    LoggingManager.Instance.Logger.Warn(string.Format("current package does not provide {0}", string.IsNullOrEmpty(package.Id) ? "an id" : "a version"));
                    continue;
                }

                if (packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.DependencyUsage == Definitions.Enumerations.NuGetDependencyUsage.NonDevelopmentOnly &&
                    package.IsDevelopmentDependency)
                {
                    LoggingManager.Instance.Logger.Warn(string.Format("current package [{0}] is a development dependency but will be ignored due to configuration", package.Id));
                    continue;
                }

                LoggingManager.Instance.Logger.Debug(string.Format("using package [{0} {1} {2}]", package.Id, package.Version, package.TargetFramework));

                string targetFramework = packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.WillCreateTargetSpecificDependencyGroups ? package.TargetFramework : null;

                Xml.NuGet.NuSpec.Group dependencyGroup = packageInfo.NuSpecPackage.Metadata.DependencyGroups.FirstOrDefault(dg => dg.TargetFramework == targetFramework);

                if (dependencyGroup == null)
                {
                    LoggingManager.Instance.Logger.Debug(string.Format("dependency group [{0}] does not exist and will be created", targetFramework));

                    dependencyGroup = new Xml.NuGet.NuSpec.Group()
                    {
                        TargetFramework = targetFramework
                    };

                    packageInfo.NuSpecPackage.Metadata.DependencyGroups.Add(dependencyGroup);
                }

                if (dependencyGroup.Dependencies == null)
                {
                    dependencyGroup.Dependencies = new List <Xml.NuGet.NuSpec.Dependency>();
                }

                dependencyGroup.Dependencies.Add(new Xml.NuGet.NuSpec.Dependency()
                {
                    Id = package.Id, Version = package.Version, OriginalTargetFramework = package.TargetFramework
                });
            }

            LoggingManager.Instance.Logger.Debug("determine dependencies finished");
        }
Esempio n. 3
0
        /// <summary>
        /// determines the nuget dependecies form the package.config file if any
        /// </summary>
        /// <param name="activeProject">the project that is to be deployed</param>
        private void DetermineNuSpecDependecies(Project activeProject, PackageInformation packageInfo)
        {
            LoggingManager.Instance.Logger.Debug("determine nuspec dependencies started");

            if (packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.DependencyUsage == Definitions.Enumerations.NuGetDependencyUsage.None)
            {
                LoggingManager.Instance.Logger.Debug("usage of referenced nuget dependencies is disabled");
                return;
            }

            ProjectItem nuGetPackagesConfig = Utils.ExtensionUtil.GetItem(Resources.NuGetPackageFilename, activeProject.ProjectItems);
            if (nuGetPackagesConfig == null)
            {
                LoggingManager.Instance.Logger.Debug(string.Format("no {0} file not found in the solution, no dependencies will be added", Resources.NuGetPackageFilename));
                return;
            }

            LoggingManager.Instance.Logger.Debug(string.Format("{0} file found in the solution, dependencies will be added", Resources.NuGetPackageFilename));

            string fullname = Utils.ExtensionUtil.GetPropertyValue<string>(nuGetPackagesConfig.Properties, Resources.PropertyFullpath, null);

            LoggingManager.Instance.Logger.Debug(string.Format("fullname is {0}", fullname));

            if (!File.Exists(fullname))
            {
                LoggingManager.Instance.Logger.Warn("file does not exist");
                return;
            }

            //-----deserialize the packages file
            Xml.NuGet.Package.Packages packages = null;
            try
            {
                packages = XmlUtil.Deserialize<Xml.NuGet.Package.Packages>(fullname);
            }
            catch (Exception ex)
            {
                if (ex is ThreadAbortException || ex is ThreadInterruptedException)
                    throw;

                LoggingManager.Instance.Logger.Warn("file could not be deserialized", ex);
                return;
            }

            if (packages.Elements == null)
            {
                LoggingManager.Instance.Logger.Warn("file does not provide any package");
                return;
            }

            //-----prepate the nuspec dependencies
            if (packageInfo.NuSpecPackage.Metadata.DependencyGroups == null)
                packageInfo.NuSpecPackage.Metadata.DependencyGroups = new List<Xml.NuGet.NuSpec.Group>();

            packageInfo.NuSpecPackage.Metadata.DependencyGroups.Clear();

            //-----get the packages and add them using the targetframework if any
            foreach (Xml.NuGet.Package.Package package in packages.Elements)
            {
                if (string.IsNullOrEmpty(package.Id) || string.IsNullOrEmpty(package.Version))
                {
                    LoggingManager.Instance.Logger.Warn(string.Format("current package does not provide {0}", string.IsNullOrEmpty(package.Id) ? "an id" : "a version"));
                    continue;
                }

                if (packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.DependencyUsage == Definitions.Enumerations.NuGetDependencyUsage.NonDevelopmentOnly
                        && package.IsDevelopmentDependency)
                {
                    LoggingManager.Instance.Logger.Warn(string.Format("current package [{0}] is a development dependency but will be ignored due to configuration", package.Id));
                    continue;
                }

                LoggingManager.Instance.Logger.Debug(string.Format("using package [{0} {1} {2}]", package.Id, package.Version, package.TargetFramework));

                string targetFramework = packageInfo.ProjectOptions.NuGetOptions.GeneralOptions.WillCreateTargetSpecificDependencyGroups ? package.TargetFramework : null;

                Xml.NuGet.NuSpec.Group dependencyGroup = packageInfo.NuSpecPackage.Metadata.DependencyGroups.FirstOrDefault(dg => dg.TargetFramework == targetFramework);

                if (dependencyGroup == null)
                {
                    LoggingManager.Instance.Logger.Debug(string.Format("dependency group [{0}] does not exist and will be created", targetFramework));

                    dependencyGroup = new Xml.NuGet.NuSpec.Group() { TargetFramework = targetFramework };

                    packageInfo.NuSpecPackage.Metadata.DependencyGroups.Add(dependencyGroup);
                }

                if (dependencyGroup.Dependencies == null)
                    dependencyGroup.Dependencies = new List<Xml.NuGet.NuSpec.Dependency>();

                dependencyGroup.Dependencies.Add(new Xml.NuGet.NuSpec.Dependency() { Id = package.Id, Version = package.Version, OriginalTargetFramework = package.TargetFramework });
            }

            LoggingManager.Instance.Logger.Debug("determine dependencies finished");
        }
        /// <summary>
        /// will be called when a group of a dependency should be switched
        /// </summary>
        /// <param name="dependency">dependency that needs to be switched</param>
        /// <param name="originalGroup">the original group the dependency was placed in before</param>
        private void OnNuGetDependencyRemoved(NuGetDependency dependency, NuGetDependencyGroup originalGroup)
        {
            //here we check whether the dependency will be placed in its original group or the default group
            string targetFrameworkToLookFor = string.IsNullOrEmpty(originalGroup.Group.TargetFramework) ? dependency.Dependency.OriginalTargetFramework : null;

            //check if the original group has any dependencies left, if not it is not needed anymore
            if (originalGroup.Group.Dependencies.Count == 0)
            {
                _deployInfo.NuSpecPackage.Metadata.DependencyGroups.Remove(originalGroup.Group);

                _uiNuSpecDependencyGroups.Items.Remove(originalGroup);
            }

            //add the dependency to the new group
            foreach (NuGetDependencyGroup group in _uiNuSpecDependencyGroups.Items)
            {
                if (group.Group.TargetFramework == targetFrameworkToLookFor)
                {
                    group.AddDependency(dependency);
                    return;
                }
            }

            //if no group with the needed framework exists, it will be created and added
            Xml.NuGet.NuSpec.Group newGroup = new Xml.NuGet.NuSpec.Group() { TargetFramework = targetFrameworkToLookFor, Dependencies = new List<Xml.NuGet.NuSpec.Dependency>() };

            newGroup.Dependencies.Add(dependency.Dependency);

            _deployInfo.NuSpecPackage.Metadata.DependencyGroups.Add(newGroup);

            _uiNuSpecDependencyGroups.Items.Add(new NuGetDependencyGroup(newGroup) { OnDependencyRemoved = OnNuGetDependencyRemoved });
        }