Exemplo n.º 1
0
        public VsTargetFrameworkInfo(
            string targetFrameworkMoniker,
            IEnumerable <IVsReferenceItem> packageReferences,
            IEnumerable <IVsReferenceItem> projectReferences,
            IEnumerable <IVsProjectProperty> projectProperties)
        {
            if (string.IsNullOrEmpty(targetFrameworkMoniker))
            {
                throw new ArgumentException("Argument cannot be null or empty", nameof(targetFrameworkMoniker));
            }

            if (packageReferences == null)
            {
                throw new ArgumentNullException(nameof(packageReferences));
            }

            if (projectReferences == null)
            {
                throw new ArgumentNullException(nameof(projectReferences));
            }

            if (projectProperties == null)
            {
                throw new ArgumentNullException(nameof(projectProperties));
            }

            TargetFrameworkMoniker = targetFrameworkMoniker;
            PackageReferences      = new VsReferenceItems(packageReferences);
            ProjectReferences      = new VsReferenceItems(projectReferences);
            Properties             = new VsProjectProperties(projectProperties);
        }
Exemplo n.º 2
0
        public VsTargetFrameworkInfo(
            string targetFrameworkMoniker,
            IEnumerable <IVsReferenceItem> packageReferences,
            IEnumerable <IVsReferenceItem> projectReferences,
            IEnumerable <IVsProjectProperty> projectProperties)
        {
            if (string.IsNullOrEmpty(targetFrameworkMoniker))
            {
                throw new ArgumentException(ProjectManagement.Strings.Argument_Cannot_Be_Null_Or_Empty, nameof(targetFrameworkMoniker));
            }

            if (packageReferences == null)
            {
                throw new ArgumentNullException(nameof(packageReferences));
            }

            if (projectReferences == null)
            {
                throw new ArgumentNullException(nameof(projectReferences));
            }

            if (projectProperties == null)
            {
                throw new ArgumentNullException(nameof(projectProperties));
            }

            TargetFrameworkMoniker = targetFrameworkMoniker;
            PackageReferences      = new VsReferenceItems(packageReferences);
            ProjectReferences      = new VsReferenceItems(projectReferences);
            Properties             = new VsProjectProperties(projectProperties);
        }
Exemplo n.º 3
0
        private static VsTargetFrameworkInfo ToTargetFrameworkInfo(
            TargetFrameworkInformation tfm,
            IEnumerable <IVsProjectProperty> globalProperties)
        {
            var packageReferences = tfm
                                    .Dependencies
                                    .Where(d => d.LibraryRange.TypeConstraint == LibraryDependencyTarget.Package)
                                    .Select(ToPackageReference);

            var projectReferences = tfm
                                    .Dependencies
                                    .Where(d => d.LibraryRange.TypeConstraint == LibraryDependencyTarget.ExternalProject)
                                    .Select(ToProjectReference);

            var projectProperties = new VsProjectProperties
            {
                {
                    "PackageTargetFallback",
                    string.Join(";", tfm.Imports.Select(x => x.GetShortFolderName()))
                },
            };

            return(new VsTargetFrameworkInfo(
                       tfm.FrameworkName.ToString(),
                       packageReferences,
                       projectReferences,
                       projectProperties.Concat(globalProperties),
                       originalTargetFramework: tfm.TargetAlias));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates project restore info object to be consumed by <see cref="IVsSolutionRestoreService"/>.
        /// </summary>
        /// <param name="packageSpec">Source project restore object</param>
        /// <returns>Desired project restore object</returns>
        public static ProjectRestoreInfoBuilder FromPackageSpec(
            PackageSpec packageSpec,
            string baseIntermediatePath,
            bool crossTargeting)
        {
            if (packageSpec == null)
            {
                throw new ArgumentNullException(nameof(packageSpec));
            }

            if (packageSpec.TargetFrameworks == null)
            {
                return(null);
            }

            var projectProperties = new VsProjectProperties {
            };

            if (packageSpec.Version != null)
            {
                projectProperties = new VsProjectProperties
                {
                    { "PackageVersion", packageSpec.Version.ToString() }
                };
            }

            var targetFrameworks = new VsTargetFrameworks(
                packageSpec
                .TargetFrameworks
                .Select(tfm => ToTargetFrameworkInfo(tfm, projectProperties)));

            var targetFrameworks2 = new VsTargetFrameworks2(
                packageSpec
                .TargetFrameworks
                .Select(tfm => ToTargetFrameworkInfo2(tfm, projectProperties)));

            var pri = new VsProjectRestoreInfo(
                baseIntermediatePath,
                targetFrameworks);

            var pri2 = new VsProjectRestoreInfo2(
                baseIntermediatePath,
                targetFrameworks2);

            if (crossTargeting)
            {
                pri.OriginalTargetFrameworks = string.Join(";",
                                                           packageSpec
                                                           .TargetFrameworks
                                                           .Select(tfm => tfm.FrameworkName.GetShortFolderName()));
            }

            return(new ProjectRestoreInfoBuilder(pri, pri2));
        }
        private static VsTargetFrameworkInfo2 ToTargetFrameworkInfo2(
            TargetFrameworkInformation tfm,
            IEnumerable <IVsProjectProperty> globalProperties)
        {
            var packageReferences = tfm
                                    .Dependencies
                                    .Where(d => d.LibraryRange.TypeConstraint == LibraryDependencyTarget.Package)
                                    .Select(ToPackageReference);

            var projectReferences = tfm
                                    .Dependencies
                                    .Where(d => d.LibraryRange.TypeConstraint == LibraryDependencyTarget.ExternalProject)
                                    .Select(ToProjectReference);

            var packageDownloads = tfm
                                   .DownloadDependencies
                                   .Select(ToPackageDownload);

            var frameworkReferences = tfm.FrameworkReferences.Select(e => new VsReferenceItem(e, new VsReferenceProperties()));

            var projectProperties = new VsProjectProperties
            {
                {
                    "PackageTargetFallback",
                    string.Join(";", tfm.Imports.Select(x => x.GetShortFolderName()))
                }
            };

            return(new VsTargetFrameworkInfo2(
                       tfm.FrameworkName.ToString(),
                       packageReferences,
                       projectReferences,
                       packageDownloads,
                       frameworkReferences,
                       projectProperties.Concat(globalProperties)));
        }