示例#1
0
        private IEnumerable <string> MigrateXProjProjectDependencies(MigrationRuleInputs migrationRuleInputs)
        {
            var csprojReferenceItems = _projectDependencyFinder.ResolveXProjProjectDependencies(migrationRuleInputs.ProjectXproj);

            if (!csprojReferenceItems.Any())
            {
                return(Enumerable.Empty <string>());
            }

            var csprojTransformedReferences = new List <ProjectItemElement>();

            foreach (var csprojReferenceItem in csprojReferenceItems)
            {
                var conditionChain = csprojReferenceItem.ConditionChain();
                var condition      = string.Join(" and ", conditionChain);

                var referenceInclude = string.Join(";", csprojReferenceItem.Includes()
                                                   .Where(include =>
                                                          string.Equals(Path.GetExtension(include), ".csproj", StringComparison.OrdinalIgnoreCase)));

                var transformItem = ProjectDependencyStringTransform.Transform(referenceInclude);
                transformItem.Condition = condition;

                csprojTransformedReferences.Add(transformItem);
            }

            MigrationTrace.Instance.WriteLine(String.Format(LocalizableStrings.MigratingCountXprojToCsprojReferences, nameof(MigrateProjectDependenciesRule), csprojTransformedReferences.Count()));

            foreach (var csprojTransformedReference in csprojTransformedReferences)
            {
                _transformApplicator.Execute(csprojTransformedReference, migrationRuleInputs.CommonItemGroup, true);
            }

            return(csprojTransformedReferences.SelectMany(r => r.Includes()));
        }
示例#2
0
        private void PerformPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory,
            ProjectType projectType,
            ProjectRootElement csproj)
        {
            foreach (var transform in _propertyTransforms)
            {
                transformApplicator.Execute(transform.Transform(compilerOptions), propertyGroup, mergeExisting: true);
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var transform = includeContextTransformExecute(compilerOptions, projectDirectory, projectType);

                if (transform != null)
                {
                    transformApplicator.Execute(
                        transform,
                        itemGroup,
                        mergeExisting: true);
                }
            }
        }
示例#3
0
        private void PerformConfigurationPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            CommonCompilerOptions configurationCompilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory,
            ProjectType projectType,
            ProjectRootElement csproj)
        {
            foreach (var transform in _propertyTransforms)
            {
                var nonConfigurationOutput = transform.Transform(compilerOptions);
                var configurationOutput    = transform.Transform(configurationCompilerOptions);

                if (!PropertiesAreEqual(nonConfigurationOutput, configurationOutput))
                {
                    transformApplicator.Execute(configurationOutput, propertyGroup, mergeExisting: true);
                }
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var nonConfigurationOutput = includeContextTransformExecute(compilerOptions, projectDirectory);
                var configurationOutput    =
                    includeContextTransformExecute(configurationCompilerOptions, projectDirectory);

                configurationOutput = RemoveDefaultCompileAndEmbeddedResourceForWebProjects(
                    configurationOutput,
                    projectType,
                    csproj);

                transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
            }
        }
示例#4
0
 private void TransformProperties(PackOptions packOptions, ProjectPropertyGroupElement propertyGroup)
 {
     foreach (var propertyTransfrom in _propertyTransforms)
     {
         _transformApplicator.Execute(propertyTransfrom.Transform(packOptions), propertyGroup, true);
     }
 }
示例#5
0
 private void AddProjectDependenciesToNewItemGroup(ProjectItemGroupElement itemGroup, IEnumerable <ProjectItemElement> projectDependencyTransformResults)
 {
     foreach (var projectDependencyTransformResult in projectDependencyTransformResults)
     {
         _transformApplicator.Execute(projectDependencyTransformResult, itemGroup);
     }
 }
示例#6
0
        private void PerformPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory,
            ProjectType projectType,
            ProjectRootElement csproj)
        {
            foreach (var transform in _propertyTransforms)
            {
                transformApplicator.Execute(transform.Transform(compilerOptions), propertyGroup, mergeExisting: true);
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var transform = includeContextTransformExecute(compilerOptions, projectDirectory);

                transform = RemoveDefaultCompileAndEmbeddedResourceForWebProjects(
                    transform,
                    projectType,
                    csproj);

                transformApplicator.Execute(
                    transform,
                    itemGroup,
                    mergeExisting: true);
            }
        }
示例#7
0
        private void PerformConfigurationPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            CommonCompilerOptions configurationCompilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory)
        {
            foreach (var transform in _propertyTransforms)
            {
                var nonConfigurationOutput = transform.Transform(compilerOptions);
                var configurationOutput    = transform.Transform(configurationCompilerOptions);

                if (!PropertiesAreEqual(nonConfigurationOutput, configurationOutput))
                {
                    transformApplicator.Execute(configurationOutput, propertyGroup);
                }
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var nonConfigurationOutput = includeContextTransformExecute(compilerOptions, projectDirectory);
                var configurationOutput    = includeContextTransformExecute(configurationCompilerOptions, projectDirectory).ToArray();

                transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
            }
        }
示例#8
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj        = migrationRuleInputs.OutputMSBuildProject;
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            CleanExistingProperties(csproj);
            CleanExistingPackageReferences(csproj);

            if (migrationRuleInputs.IsMultiTFM)
            {
                _transformApplicator.Execute(
                    FrameworksTransform.Transform(
                        migrationRuleInputs.ProjectContexts.Select(p => p.TargetFramework)),
                    propertyGroup,
                    mergeExisting: true);
            }
            else
            {
                _transformApplicator.Execute(
                    FrameworkTransform.Transform(
                        migrationRuleInputs.ProjectContexts.Single().TargetFramework),
                    propertyGroup,
                    mergeExisting: true);
            }
        }
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj         = migrationRuleInputs.OutputMSBuildProject;
            var projectContext = migrationRuleInputs.DefaultProjectContext;

            var propertyGroup = _configurationPropertyGroup ?? migrationRuleInputs.CommonPropertyGroup;
            var itemGroup     = _configurationItemGroup ?? migrationRuleInputs.CommonItemGroup;

            var compilerOptions = projectContext.ProjectFile.GetCompilerOptions(null, null);

            var projectDirectoryName = new DirectoryInfo(migrationSettings.ProjectDirectory).Name;

            _propertyTransforms.Add(PackageIdTransformExecute(projectDirectoryName));

            var project     = migrationRuleInputs.DefaultProjectContext.ProjectFile;
            var projectType = project.GetProjectType();

            // If we're in a configuration, we need to be careful not to overwrite values from BuildOptions
            // without a configuration
            if (_configurationBuildOptions == null)
            {
                CleanExistingProperties(csproj);

                PerformPropertyAndItemMappings(
                    compilerOptions,
                    propertyGroup,
                    itemGroup,
                    _transformApplicator,
                    migrationSettings.ProjectDirectory,
                    projectType,
                    csproj);
            }
            else
            {
                PerformConfigurationPropertyAndItemMappings(
                    compilerOptions,
                    _configurationBuildOptions,
                    propertyGroup,
                    itemGroup,
                    _transformApplicator,
                    migrationSettings.ProjectDirectory,
                    projectType,
                    csproj);
            }

            var transformOutput = GenerateRuntimeConfigurationFilesTransform.Transform(
                migrationRuleInputs.DefaultProjectContext.ProjectFile);

            _transformApplicator.Execute(transformOutput, propertyGroup, mergeExisting: true);

            var appConfigTransformOutput = AppConfigTransform.Transform(migrationRuleInputs.DefaultProjectContext);

            _transformApplicator.Execute(appConfigTransformOutput, itemGroup, mergeExisting: true);
        }
示例#10
0
        private void PerformConfigurationPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            CommonCompilerOptions configurationCompilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory,
            ProjectType projectType,
            ProjectRootElement csproj)
        {
            foreach (var transform in _propertyTransforms)
            {
                var nonConfigurationOutput = transform.Transform(compilerOptions);
                var configurationOutput    = transform.Transform(configurationCompilerOptions);

                if (!PropertiesAreEqual(nonConfigurationOutput, configurationOutput))
                {
                    transformApplicator.Execute(configurationOutput, propertyGroup, mergeExisting: true);
                }
            }

            foreach (var removeContextTransformExecutes in _removeContextTransformExecutes)
            {
                var nonConfigurationOutput =
                    removeContextTransformExecutes(compilerOptions, projectDirectory, projectType);
                var configurationOutput =
                    removeContextTransformExecutes(configurationCompilerOptions, projectDirectory, projectType);

                if (configurationOutput != null &&
                    !ItemRemovesAreEqual(nonConfigurationOutput, configurationOutput))
                {
                    transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
                }
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var nonConfigurationOutput =
                    includeContextTransformExecute(compilerOptions, projectDirectory, projectType);
                var configurationOutput =
                    includeContextTransformExecute(configurationCompilerOptions, projectDirectory, projectType);

                if (configurationOutput != null)
                {
                    transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: true);
                }
            }
        }
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            _transformApplicator.Execute(
                RuntimeIdentifiersTransform.Transform(migrationRuleInputs.DefaultProjectContext.ProjectFile.Runtimes),
                propertyGroup,
                mergeExisting: true);
        }
示例#12
0
        private IEnumerable <string> MigrateXProjProjectDependencies(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var xproj = migrationRuleInputs.ProjectXproj;

            if (xproj == null)
            {
                MigrationTrace.Instance.WriteLine($"{nameof(MigrateProjectDependenciesRule)}: No xproj file given.");
                return(Enumerable.Empty <string>());
            }

            var csprojTransformedReferences = new List <ProjectItemElement>();

            var csprojReferenceItems = xproj.Items
                                       .Where(i => i.ItemType == "ProjectReference")
                                       .Where(p =>
                                              p.Includes().Any(
                                                  include => string.Equals(Path.GetExtension(include), ".csproj", StringComparison.OrdinalIgnoreCase)));

            foreach (var csprojReferenceItem in csprojReferenceItems)
            {
                var conditionChain = csprojReferenceItem.ConditionChain();
                var condition      = string.Join(" and ", conditionChain);

                var referenceInclude = string.Join(";", csprojReferenceItem.Includes()
                                                   .Where(include =>
                                                          string.Equals(Path.GetExtension(include), ".csproj", StringComparison.OrdinalIgnoreCase)));

                var transformItem = ProjectDependencyStringTransform.Transform(referenceInclude);
                transformItem.Condition = condition;

                csprojTransformedReferences.Add(transformItem);
            }


            MigrationTrace.Instance.WriteLine($"{nameof(MigrateProjectDependenciesRule)}: Migrating {csprojTransformedReferences.Count()} xproj to csproj references");

            foreach (var csprojTransformedReference in csprojTransformedReferences)
            {
                _transformApplicator.Execute(csprojTransformedReference, migrationRuleInputs.CommonItemGroup);
            }

            return(csprojTransformedReferences.SelectMany(r => r.Includes()));
        }
示例#13
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj        = migrationRuleInputs.OutputMSBuildProject;
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            CleanExistingProperties(csproj);

            if (migrationRuleInputs.ProjectContexts.Count() > 1)
            {
                _transformApplicator.Execute(
                    FrameworksTransform.Transform(migrationRuleInputs.ProjectContexts.Select(p => p.TargetFramework)),
                    propertyGroup);
            }

            foreach (var transform in _transforms)
            {
                _transformApplicator.Execute(
                    transform.Transform(migrationRuleInputs.DefaultProjectContext.TargetFramework),
                    propertyGroup);
            }
        }
示例#14
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj        = migrationRuleInputs.OutputMSBuildProject;
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            CleanExistingProperties(csproj);
            CleanExistingPackageReferences(csproj);

            if (migrationRuleInputs.ProjectContexts.Count() == 1)
            {
                _transformApplicator.Execute(
                    FrameworkTransform.Transform(
                        migrationRuleInputs.ProjectContexts.Single().TargetFramework),
                    propertyGroup,
                    mergeExisting: true);
                _transformApplicator.Execute(
                    FrameworkRuntimeIdentifiersTransform.Transform(
                        migrationRuleInputs.ProjectContexts.Single()),
                    propertyGroup,
                    mergeExisting: true);
            }
            else
            {
                _transformApplicator.Execute(
                    FrameworksTransform.Transform(
                        migrationRuleInputs.ProjectContexts.Select(p => p.TargetFramework)),
                    propertyGroup,
                    mergeExisting: true);


                var runtimes = string.Join(",", migrationRuleInputs.ProjectContexts.Select(p => p.RuntimeIdentifier));
                Console.WriteLine($"Runtimes = {runtimes}");

                _transformApplicator.Execute(
                    FrameworksRuntimeIdentifiersTransform.Transform(
                        migrationRuleInputs.ProjectContexts),
                    propertyGroup,
                    mergeExisting: true);
            }
        }
示例#15
0
        private void PerformConfigurationPropertyAndItemMappings(
            CommonCompilerOptions compilerOptions,
            CommonCompilerOptions configurationCompilerOptions,
            ProjectPropertyGroupElement propertyGroup,
            ProjectItemGroupElement itemGroup,
            ITransformApplicator transformApplicator,
            string projectDirectory)
        {
            foreach (var transform in _propertyTransforms)
            {
                var nonConfigurationOutput = transform.Transform(compilerOptions);
                var configurationOutput    = transform.Transform(configurationCompilerOptions);

                if (!PropertiesAreEqual(nonConfigurationOutput, configurationOutput))
                {
                    transformApplicator.Execute(configurationOutput, propertyGroup);
                }
            }

            foreach (var includeContextTransformExecute in _includeContextTransformExecutes)
            {
                var nonConfigurationOutput = includeContextTransformExecute(compilerOptions, projectDirectory);
                var configurationOutput    = includeContextTransformExecute(configurationCompilerOptions, projectDirectory).ToArray();

                if (configurationOutput != null && nonConfigurationOutput != null)
                {
                    // TODO: HACK: this is leaky, see top comments, the throw at least covers the scenario
                    ThrowIfConfigurationHasAdditionalExcludes(configurationOutput, nonConfigurationOutput);
                    RemoveCommonIncludes(configurationOutput, nonConfigurationOutput);
                    configurationOutput = configurationOutput.Where(i => i != null && !string.IsNullOrEmpty(i.Include)).ToArray();
                }

                // Don't merge with existing items when doing a configuration
                transformApplicator.Execute(configurationOutput, itemGroup, mergeExisting: false);
            }
        }
示例#16
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var projectContext = migrationRuleInputs.DefaultProjectContext;

            var transformResults = _transforms.Select(t => t.Transform(projectContext.ProjectFile)).ToArray();
            if (transformResults.Any())
            {
                var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

                foreach (var transformResult in transformResults)
                {
                    _transformApplicator.Execute(transformResult, propertyGroup);
                }
            }
        }
        private void ExecuteTransformation(
            IncludeContextTransform transform,
            IncludeContext includeContext,
            MigrationRuleInputs migrationRuleInputs)
        {
            var transformResult = transform.Transform(includeContext);

            if (transformResult != null && transformResult.Any())
            {
                var itemGroup = migrationRuleInputs.CommonItemGroup;
                _transformApplicator.Execute(
                    transformResult,
                    itemGroup,
                    mergeExisting: true);
            }
        }
示例#18
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj         = migrationRuleInputs.OutputMSBuildProject;
            var projectContext = migrationRuleInputs.DefaultProjectContext;

            var transformResult = CopyToOutputFilesTransform.Transform(projectContext.ProjectFile.PublishOptions);

            if (transformResult != null && transformResult.Any())
            {
                var itemGroup = migrationRuleInputs.CommonItemGroup;
                _transformApplicator.Execute(
                    transformResult,
                    itemGroup,
                    mergeExisting: true);
            }
        }
示例#19
0
 public void Execute <T, U>(
     T element,
     U destinationElement,
     bool mergeExisting) where T : ProjectElement where U : ProjectElementContainer
 {
     if (typeof(T) == typeof(ProjectItemElement))
     {
         _itemTransformApplicator.Execute(element, destinationElement, mergeExisting);
     }
     else if (typeof(T) == typeof(ProjectPropertyElement))
     {
         _propertyTransformApplicator.Execute(element, destinationElement, mergeExisting);
     }
     else
     {
         throw new ArgumentException(String.Format(LocalizableStrings.UnexpectedTypeError, nameof(T)));
     }
 }
示例#20
0

        
示例#21
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            var projectContext = migrationRuleInputs.DefaultProjectContext;
            var packOptions    = projectContext.ProjectFile.PackOptions;

            if (packOptions.PackInclude != null)
            {
                MigrationErrorCodes
                .MIGRATE20018("Migrating projects with Files specified in PackOptions is not supported.").Throw();
            }

            foreach (var propertyTransfrom in _propertyTransforms)
            {
                _transformApplicator.Execute(propertyTransfrom.Transform(packOptions), propertyGroup);
            }
        }
示例#22
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var projectContext     = migrationRuleInputs.DefaultProjectContext;
            var compilationOptions = ResolveCompilationOptions(projectContext, "Debug");
            var sources            = GetCompilationSources(projectContext, compilationOptions);
            var assemblyInfoList   = GetAssemblyInfo(sources);

            foreach (var assemblyInfo in assemblyInfoList)
            {
                var propertyTransform = new AddPropertyTransform <string>(
                    $"Generate{assemblyInfo}Attribute",
                    a => "false",
                    a => true);

                _transformApplicator.Execute(
                    propertyTransform.Transform(assemblyInfo),
                    migrationRuleInputs.CommonPropertyGroup,
                    true);
            }
        }
示例#23
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var projectContext           = migrationRuleInputs.DefaultProjectContext;
            var raw                      = projectContext.ProjectFile.RawRuntimeOptions;
            var outputRuntimeOptionsFile = Path.Combine(migrationSettings.OutputDirectory, s_runtimeOptionsFileName);

            if (!string.IsNullOrEmpty(raw))
            {
                if (File.Exists(outputRuntimeOptionsFile))
                {
                    MigrationErrorCodes.MIGRATE1015(
                        String.Format(LocalizableStrings.ProjAlreadyExistsError, outputRuntimeOptionsFile)).Throw();
                }

                var runtimeOptions = JObject.Parse(raw);
                if (HasServerGCProperty(runtimeOptions))
                {
                    bool serverGCValue = GetServerGCValue(runtimeOptions);

                    if (!IsServerGCValueInjectedBySdk(serverGCValue, projectContext.ProjectFile.GetProjectType()))
                    {
                        var propertyTransform = new AddPropertyTransform <bool>(
                            "ServerGarbageCollection",
                            gcValue => gcValue.ToString().ToLower(),
                            gcValue => true);

                        _transformApplicator.Execute(
                            propertyTransform.Transform(serverGCValue),
                            migrationRuleInputs.CommonPropertyGroup,
                            true);
                    }

                    RemoveServerGCProperty(runtimeOptions);
                }

                if (runtimeOptions.HasValues)
                {
                    File.WriteAllText(outputRuntimeOptionsFile, runtimeOptions.ToString());
                }
            }
        }
示例#24
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            var projectFile = migrationRuleInputs.DefaultProjectContext.ProjectFile.ProjectFilePath;

            using (var stream = new FileStream(projectFile, FileMode.Open))
                using (var streamReader = new StreamReader(stream))
                    using (var jsonReader = new JsonTextReader(streamReader))
                    {
                        var rawProject = JObject.Load(jsonReader);
                        foreach (var prop in _propertyMappings)
                        {
                            var token = rawProject.GetValue(prop.Key);
                            if (token != null)
                            {
                                _transformApplicator.Execute(prop.Value.Transform(token), propertyGroup, mergeExisting: true);
                            }
                        }
                    }
        }
示例#25
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var csproj         = migrationRuleInputs.OutputMSBuildProject;
            var projectContext = migrationRuleInputs.DefaultProjectContext;

            var project     = migrationRuleInputs.DefaultProjectContext.ProjectFile;
            var projectType = project.GetProjectType();

            var copyToPublishDirectoryTransform =
                projectType == ProjectType.Web ?
                CopyToPublishDirectoryTransformForWeb :
                CopyToPublishDirectoryTransform;

            var transformResult = copyToPublishDirectoryTransform.Transform(projectContext.ProjectFile.PublishOptions);

            if (transformResult != null && transformResult.Any())
            {
                var itemGroup = migrationRuleInputs.CommonItemGroup;
                _transformApplicator.Execute(
                    transformResult,
                    itemGroup,
                    mergeExisting: true);
            }
        }
        private void AddProjectTypeSpecificDependencies(
            MigrationRuleInputs migrationRuleInputs,
            MigrationSettings migrationSettings,
            ProjectItemGroupElement noFrameworkPackageReferenceItemGroup)
        {
            var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;
            var type    = project.GetProjectType();

            switch (type)
            {
            case ProjectType.Test:
                _transformApplicator.Execute(
                    PackageDependencyInfoTransform().Transform(
                        new PackageDependencyInfo
                {
                    Name    = PackageConstants.TestSdkPackageName,
                    Version = ConstantPackageVersions.TestSdkPackageVersion
                }),
                    noFrameworkPackageReferenceItemGroup,
                    mergeExisting: false);

                if (project.TestRunner.Equals("xunit", StringComparison.OrdinalIgnoreCase))
                {
                    _transformApplicator.Execute(
                        PackageDependencyInfoTransform().Transform(
                            new PackageDependencyInfo
                    {
                        Name    = PackageConstants.XUnitPackageName,
                        Version = ConstantPackageVersions.XUnitPackageVersion
                    }),
                        noFrameworkPackageReferenceItemGroup,
                        mergeExisting: false);

                    _transformApplicator.Execute(
                        PackageDependencyInfoTransform().Transform(
                            new PackageDependencyInfo
                    {
                        Name    = PackageConstants.XUnitRunnerPackageName,
                        Version = ConstantPackageVersions.XUnitRunnerPackageVersion
                    }),
                        noFrameworkPackageReferenceItemGroup,
                        mergeExisting: false);
                }
                else if (project.TestRunner.Equals("mstest", StringComparison.OrdinalIgnoreCase))
                {
                    _transformApplicator.Execute(
                        PackageDependencyInfoTransform().Transform(
                            new PackageDependencyInfo
                    {
                        Name    = PackageConstants.MstestTestAdapterName,
                        Version = ConstantPackageVersions.MstestTestAdapterVersion
                    }),
                        noFrameworkPackageReferenceItemGroup,
                        mergeExisting: false);

                    _transformApplicator.Execute(
                        PackageDependencyInfoTransform().Transform(
                            new PackageDependencyInfo
                    {
                        Name    = PackageConstants.MstestTestFrameworkName,
                        Version = ConstantPackageVersions.MstestTestFrameworkVersion
                    }),
                        noFrameworkPackageReferenceItemGroup,
                        mergeExisting: false);
                }
                break;

            case ProjectType.Library:
                if (!project.HasDependency(
                        (dep) => dep.Name.Trim().ToLower() == PackageConstants.NetStandardPackageName.ToLower()))
                {
                    _transformApplicator.Execute(
                        PackageDependencyInfoTransform().Transform(
                            new PackageDependencyInfo
                    {
                        Name    = PackageConstants.NetStandardPackageName,
                        Version = PackageConstants.NetStandardPackageVersion
                    }),
                        noFrameworkPackageReferenceItemGroup,
                        mergeExisting: true);
                }
                break;

            default:
                break;
            }
        }
示例#27
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            var propertyGroup = migrationRuleInputs.CommonPropertyGroup;

            _transformApplicator.Execute(ProjectLockFileTransform.Transform(string.Empty), propertyGroup);
        }
示例#28
0
        public void Apply(MigrationSettings migrationSettings, MigrationRuleInputs migrationRuleInputs)
        {
            CleanExistingPackageReferences(migrationRuleInputs.OutputMSBuildProject);

            _projectDirectory = migrationSettings.ProjectDirectory;
            var project = migrationRuleInputs.DefaultProjectContext.ProjectFile;

            var tfmDependencyMap = new Dictionary <string, IEnumerable <ProjectLibraryDependency> >();
            var targetFrameworks = project.GetTargetFrameworks();

            var noFrameworkPackageReferenceItemGroup = migrationRuleInputs.OutputMSBuildProject.AddItemGroup();

            // Inject Sdk dependency
            _transformApplicator.Execute(
                SdkPackageDependencyTransform.Transform(
                    new PackageDependencyInfo
            {
                Name          = PackageConstants.SdkPackageName,
                Version       = migrationSettings.SdkPackageVersion,
                PrivateAssets = "All"
            }), noFrameworkPackageReferenceItemGroup, mergeExisting: false);

            AddProjectTypeSpecificDependencies(
                migrationRuleInputs,
                migrationSettings,
                noFrameworkPackageReferenceItemGroup);

            // Migrate Direct Deps first
            MigrateDependencies(
                project,
                migrationRuleInputs.OutputMSBuildProject,
                null,
                project.Dependencies,
                migrationRuleInputs.ProjectXproj,
                itemGroup: noFrameworkPackageReferenceItemGroup);

            MigrationTrace.Instance.WriteLine($"Migrating {targetFrameworks.Count()} target frameworks");
            foreach (var targetFramework in targetFrameworks)
            {
                MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}");

                MigrateImports(migrationRuleInputs.CommonPropertyGroup, targetFramework);

                MigrateDependencies(
                    project,
                    migrationRuleInputs.OutputMSBuildProject,
                    targetFramework.FrameworkName,
                    targetFramework.Dependencies,
                    migrationRuleInputs.ProjectXproj);
            }

            MigrateTools(project, migrationRuleInputs.OutputMSBuildProject);
        }