예제 #1
0
        private static void SetRestoreProjectInformation(ReferenceSwitcherConfiguration configuration, ProjectItem item,
                                                         string projectFullPath, bool isPackageReference, string packageName, string packageVersion)
        {
            var projectName = Path.GetFileNameWithoutExtension(projectFullPath);

            var restoreProjectInformation =
                (from r in configuration.Restore
                 where string.Equals(r.Name, projectName, StringComparison.OrdinalIgnoreCase)
                 select r).FirstOrDefault();

            if (restoreProjectInformation is null)
            {
                restoreProjectInformation = new RestoreProjectInformation()
                {
                    Name = projectName
                };
                configuration.Restore.Add(restoreProjectInformation);
            }

            SwitchedPackage switchedPackage = null;

            if (restoreProjectInformation.Packages != null)
            {
                switchedPackage = (
                    from p in restoreProjectInformation.Packages
                    where string.Equals(p.PackageName, packageName, StringComparison.OrdinalIgnoreCase)
                    select p).FirstOrDefault();
            }
            else
            {
                restoreProjectInformation.Packages = new List <SwitchedPackage>();
            }

            if (switchedPackage is null)
            {
                switchedPackage = new SwitchedPackage();
                restoreProjectInformation.Packages.Add(switchedPackage);
            }

            if (!isPackageReference)
            {
                switchedPackage.Include = item.EvaluatedInclude;

                if (item.Metadata.Any())
                {
                    switchedPackage.Metadata = new List <KeyValuePair <string, string> >();
                    foreach (var metadata in item.Metadata)
                    {
                        switchedPackage.Metadata.Add(
                            new KeyValuePair <string, string>(metadata.Name, metadata.EvaluatedValue));
                    }
                }
            }

            switchedPackage.PackageName    = packageName;
            switchedPackage.PackageVersion = packageVersion;
        }
예제 #2
0
        private static string GetPackageVersion(RestoreProjectInformation restoreProjectInformation, string packageName)
        {
            string result = null;

            if (restoreProjectInformation != null)
            {
                result = (
                    from r in restoreProjectInformation.Packages
                    where string.Equals(r.PackageName, packageName, StringComparison.OrdinalIgnoreCase)
                    select r.PackageVersion
                    ).FirstOrDefault();
            }

            return(result);
        }