private void MigrateDependencies(
            Project project,
            ProjectRootElement output,
            NuGetFramework framework,
            IEnumerable <ProjectLibraryDependency> dependencies,
            ProjectRootElement xproj,
            SlnFile solutionFile,
            ProjectItemGroupElement itemGroup = null)
        {
            var projectDependencies = new HashSet <string>(GetAllProjectReferenceNames(project, framework, xproj, solutionFile));
            var packageDependencies = dependencies.Where(d => !projectDependencies.Contains(d.Name)).ToList();

            string condition = framework?.GetMSBuildCondition() ?? "";

            itemGroup = itemGroup
                        ?? output.ItemGroups.FirstOrDefault(i => i.Condition == condition)
                        ?? output.AddItemGroup();
            itemGroup.Condition = condition;

            AutoInjectImplicitProjectJsonAssemblyReferences(framework, packageDependencies);

            foreach (var packageDependency in packageDependencies)
            {
                MigrationTrace.Instance.WriteLine(packageDependency.Name);
                AddItemTransform <PackageDependencyInfo> transform;

                if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference)
                {
                    transform = FrameworkDependencyTransform;
                }
                else
                {
                    transform = PackageDependencyInfoTransform();
                    if (packageDependency.Type.Equals(LibraryDependencyType.Build))
                    {
                        transform = transform.WithMetadata("PrivateAssets", "All");
                    }
                    else if (packageDependency.SuppressParent != LibraryIncludeFlagUtils.DefaultSuppressParent)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.SuppressParent);
                        transform = transform.WithMetadata("PrivateAssets", metadataValue);
                    }

                    if (packageDependency.IncludeType != LibraryIncludeFlags.All)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType);
                        transform = transform.WithMetadata("IncludeAssets", metadataValue);
                    }
                }

                _transformApplicator.Execute(
                    transform.Transform(ToPackageDependencyInfo(
                                            packageDependency,
                                            PackageConstants.ProjectDependencyPackages)),
                    itemGroup,
                    mergeExisting: true);
            }
        }
Ejemplo n.º 2
0
        private void MigrateConfiguration(
            Project project,
            NuGetFramework framework,
            MigrationSettings migrationSettings,
            MigrationRuleInputs migrationRuleInputs)
        {
            var buildOptions           = project.GetRawCompilerOptions(framework);
            var configurationCondition = framework.GetMSBuildCondition();

            MigrateConfiguration(buildOptions, configurationCondition, migrationSettings, migrationRuleInputs);
        }
Ejemplo n.º 3
0
        private void AddProjectDependenciesToNewItemGroup(
            ProjectItemGroupElement itemGroup,
            IEnumerable <ProjectItemElement> projectDependencyTransformResults,
            NuGetFramework targetFramework)
        {
            if (targetFramework != null)
            {
                itemGroup.Condition = targetFramework.GetMSBuildCondition();
            }

            foreach (var projectDependencyTransformResult in projectDependencyTransformResults)
            {
                _transformApplicator.Execute(projectDependencyTransformResult, itemGroup, true);
            }
        }
Ejemplo n.º 4
0
        private void MigrateDependencies(
            Project project,
            ProjectRootElement output,
            NuGetFramework framework,
            IEnumerable <ProjectLibraryDependency> dependencies,
            ProjectRootElement xproj)
        {
            var projectDependencies = new HashSet <string>(GetAllProjectReferenceNames(project, framework, xproj));
            var packageDependencies = dependencies.Where(d => !projectDependencies.Contains(d.Name));

            string condition = framework?.GetMSBuildCondition() ?? "";
            var    itemGroup = output.ItemGroups.FirstOrDefault(i => i.Condition == condition)
                               ?? output.AddItemGroup();

            itemGroup.Condition = condition;

            foreach (var packageDependency in packageDependencies)
            {
                MigrationTrace.Instance.WriteLine(packageDependency.Name);
                AddItemTransform <ProjectLibraryDependency> transform;

                if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference)
                {
                    transform = FrameworkDependencyTransform;
                }
                else
                {
                    transform = PackageDependencyTransform();
                    if (packageDependency.Type == LibraryDependencyType.Build)
                    {
                        transform = transform.WithMetadata("PrivateAssets", "all");
                    }
                    else if (packageDependency.SuppressParent != LibraryIncludeFlagUtils.DefaultSuppressParent)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.SuppressParent);
                        transform = transform.WithMetadata("PrivateAssets", metadataValue);
                    }

                    if (packageDependency.IncludeType != LibraryIncludeFlags.All)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType);
                        transform = transform.WithMetadata("IncludeAssets", metadataValue);
                    }
                }

                _transformApplicator.Execute(transform.Transform(packageDependency), itemGroup);
            }
        }
Ejemplo n.º 5
0
        private void MigrateDependencies(
            Project project,
            MigrationRuleInputs migrationRuleInputs,
            NuGetFramework framework,
            IEnumerable <ProjectLibraryDependency> dependencies,
            SlnFile solutionFile,
            ProjectItemGroupElement itemGroup = null)
        {
            var projectDependencies = new HashSet <string>(GetAllProjectReferenceNames(
                                                               project,
                                                               framework,
                                                               migrationRuleInputs.ProjectXproj,
                                                               solutionFile));
            var packageDependencies = dependencies.Where(d => !projectDependencies.Contains(d.Name)).ToList();

            string condition = framework?.GetMSBuildCondition() ?? "";

            itemGroup = itemGroup
                        ?? migrationRuleInputs.OutputMSBuildProject.ItemGroups.FirstOrDefault(i => i.Condition == condition)
                        ?? migrationRuleInputs.OutputMSBuildProject.AddItemGroup();
            itemGroup.Condition = condition;

            AutoInjectImplicitProjectJsonAssemblyReferences(framework, packageDependencies);

            foreach (var packageDependency in packageDependencies)
            {
                MigrationTrace.Instance.WriteLine(packageDependency.Name);
                AddItemTransform <PackageDependencyInfo> transform;

                if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference)
                {
                    transform = FrameworkDependencyTransform;
                }
                else
                {
                    transform = PackageDependencyInfoTransform();
                    if (packageDependency.Type.Equals(LibraryDependencyType.Build))
                    {
                        transform = transform.WithMetadata("PrivateAssets", "All");
                    }
                    else if (packageDependency.SuppressParent != LibraryIncludeFlagUtils.DefaultSuppressParent)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.SuppressParent);
                        transform = transform.WithMetadata("PrivateAssets", metadataValue);
                    }

                    if (packageDependency.IncludeType != LibraryIncludeFlags.All)
                    {
                        var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType);
                        transform = transform.WithMetadata("IncludeAssets", metadataValue);
                    }
                }

                var packageDependencyInfo = ToPackageDependencyInfo(
                    packageDependency,
                    _supportedPackageVersions.ProjectDependencyPackages);

                if (packageDependencyInfo != null && packageDependencyInfo.IsMetaPackage)
                {
                    var metaPackageTransform = RuntimeFrameworkVersionTransformation.Transform(packageDependencyInfo);
                    if (metaPackageTransform == null)
                    {
                        metaPackageTransform =
                            NetStandardImplicitPackageVersionTransformation.Transform(packageDependencyInfo);
                    }

                    if (migrationRuleInputs.IsMultiTFM)
                    {
                        metaPackageTransform.Condition = condition;
                    }

                    _transformApplicator.Execute(
                        metaPackageTransform,
                        migrationRuleInputs.CommonPropertyGroup,
                        mergeExisting: true);
                }
                else
                {
                    _transformApplicator.Execute(
                        transform.Transform(packageDependencyInfo),
                        itemGroup,
                        mergeExisting: true);
                }
            }
        }