private ProjectRootElement MigrateProject(
            string solution,
            string project,
            NuGetFramework targetFramework)
        {
            var solutionDirectory = TestAssets.Get(solution)
                                    .CreateInstance(callingMethod: "p")
                                    .WithSourceFiles()
                                    .Root.FullName;

            var appDirectory = Path.Combine(solutionDirectory, project);

            var projectContext = ProjectContext.Create(appDirectory, targetFramework);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var s = mockProj.Items.Select(p => $"ItemType = {p.ItemType}, Include = {p.Include}");

            Console.WriteLine(string.Join(Environment.NewLine, s));

            return(mockProj);
        }
        public void SpecifiedDefaultPropertiesAreRemovedWhenTheyExistInTheCsprojTemplate()
        {
            // Setup project with default properties
            var defaultPropertiesExpectedToBeRemoved = new string[]
            {
                "OutputType",
                "TargetExt"
            };

            var defaultValue = "defaultValue";

            var templateProj         = ProjectRootElement.Create();
            var defaultPropertyGroup = templateProj.AddPropertyGroup();

            foreach (var defaultPropertyName in defaultPropertiesExpectedToBeRemoved)
            {
                defaultPropertyGroup.AddProperty(defaultPropertyName, defaultValue);
            }

            // Setup projectcontext
            var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithRuntimeOptions").Path;
            var projectContext       = ProjectContext.Create(testProjectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, templateProj);
            var testInputs   = new MigrationRuleInputs(new[] { projectContext }, templateProj, templateProj.AddItemGroup(),
                                                       templateProj.AddPropertyGroup());

            new MigrateBuildOptionsRule().Apply(testSettings, testInputs);

            defaultPropertyGroup.Properties.Count.Should().Be(0);
        }
        public void RuntimeOptionsAreCopiedFromProjectJsonToRuntimeConfigTemplateJsonFile()
        {
            var testInstance = TestAssets.Get("TestAppWithRuntimeOptions")
                               .CreateInstance()
                               .WithSourceFiles()
                               .Root;

            var projectDir  = testInstance.FullName;
            var projectPath = Path.Combine(projectDir, "project.json");

            var project           = JObject.Parse(File.ReadAllText(projectPath));
            var rawRuntimeOptions = (JObject)project.GetValue("runtimeOptions");

            var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(projectDir, projectDir, default(ProjectRootElement));
            var testInputs   = new MigrationRuleInputs(new[] { projectContext }, null, null, null);

            new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);

            var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);

            File.Exists(migratedRuntimeOptionsPath).Should().BeTrue();

            var migratedRuntimeOptionsContent = JObject.Parse(File.ReadAllText(migratedRuntimeOptionsPath));

            JToken.DeepEquals(rawRuntimeOptions, migratedRuntimeOptionsContent).Should().BeTrue();
        }
Пример #4
0
        public void MigratingNetcoreappProjectDoesNotPopulateTargetFrameworkIdentifierAndTargetFrameworkVersion()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("TestAppWithRuntimeOptions")
                                .WithCustomProperty("buildOptions", new Dictionary <string, string>
            {
                { "emitEntryPoint", "false" }
            })
                                .SaveToDisk(testDirectory);

            var projectContext = ProjectContext.Create(testDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();

            var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs   = new MigrationRuleInputs(
                new[] { projectContext },
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "TargetFrameworkIdentifier").Should().Be(0);
            mockProj.Properties.Count(p => p.Name == "TargetFrameworkVersion").Should().Be(0);
        }
Пример #5
0
        public void ItHasWarningWhenMigratingADeprecatedProjectJson()
        {
            var testProjectDirectory = TestAssets
                                       .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedCompile")
                                       .CreateInstance()
                                       .WithSourceFiles()
                                       .Root
                                       .GetDirectory("project")
                                       .FullName;

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
                testProjectDirectory,
                testProjectDirectory,
                mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
            var report          = projectMigrator.Migrate(testSettings);

            var projectReport  = report.ProjectMigrationReports.First();
            var warningMessage = projectReport.Warnings.First();

            warningMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
            warningMessage.Should().Contain("The 'compile' option is deprecated. Use 'compile' in 'buildOptions' instead. (line: 3, file:");
        }
Пример #6
0
        public void MigratingLibWithMultipleTFMsDoesNotAddRuntimes()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("PJLibWithMultipleFrameworks")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings =
                MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            var reason = "Should not add runtime identifiers for libraries";

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0, reason);
            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(0, reason);
        }
Пример #7
0
        public void MigratingCoreAndDesktopTFMsAddsRuntimeIdentifierWithWin7x86ConditionOnAllFullFrameworksWhenNoRuntimesExistAlready()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("PJAppWithMultipleFrameworks")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs   = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifier").Should().Be(1);
            var runtimeIdentifier = mockProj.Properties.First(p => p.Name == "RuntimeIdentifier");

            runtimeIdentifier.Value.Should().Be("win7-x86");
            runtimeIdentifier.Condition.Should().Be(" '$(TargetFramework)' == 'net20' OR '$(TargetFramework)' == 'net35' OR '$(TargetFramework)' == 'net40' OR '$(TargetFramework)' == 'net461' ");
        }
Пример #8
0
        public void ItHasErrorWhenMigratingAProjectJsonWithoutAFrameworks()
        {
            var testInstance = TestAssets.Get(
                "NonRestoredTestProjects",
                "TestLibraryWithProjectFileWithoutFrameworks")
                               .CreateInstance()
                               .WithSourceFiles();

            var testProjectDirectory = testInstance.Root.FullName;

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
                testProjectDirectory,
                testProjectDirectory,
                mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
            var report          = projectMigrator.Migrate(testSettings);

            var projectReport = report.ProjectMigrationReports.First();

            projectReport.Errors.First().GetFormattedErrorMessage()
            .Should().Contain("MIGRATE1013::No Project:")
            .And.Contain($"The project.json specifies no target frameworks in {testProjectDirectory}");
        }
        public void TFMSpecificProjectDependenciesAreMigratedToProjectReferenceUnderConditionItemGroup()
        {
            var solutionDirectory = TestAssets.Get("TestAppWithLibraryUnderTFM")
                                    .CreateInstance(callingMethod: "p")
                                    .WithSourceFiles()
                                    .Root.FullName;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp11);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Count().Should().Be(1);

            var projectReference = projectReferences.First();

            projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
            projectReference.Parent.Condition.Should().Be(" '$(TargetFramework)' == 'netcoreapp1.1' ");
        }
Пример #10
0
        public void MigratingSingleTFMProjectPopulatesTargetFramework()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("TestAppWithRuntimeOptions")
                                .WithCustomProperty("buildOptions", new Dictionary <string, string>
            {
                { "emitEntryPoint", "false" }
            })
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            // Run BuildOptionsRule
            var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs   = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);
            Console.WriteLine(mockProj.RawXml);

            mockProj.Properties.Count(p => p.Name == "TargetFramework").Should().Be(1);
        }
        public void MigratingProjectJsonWithNoRuntimeOptionsProducesNoRuntimeConfigTemplateJsonFile()
        {
            var testInstance = TestAssetsManager.CreateTestInstance("PJTestAppSimple");
            var projectDir   = testInstance.Path;

            var projectContext = ProjectContext.Create(projectDir, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(projectDir, projectDir, default(ProjectRootElement));
            var testInputs   = new MigrationRuleInputs(new[] { projectContext }, null, null, null);

            new MigrateRuntimeOptionsRule().Apply(testSettings, testInputs);

            var migratedRuntimeOptionsPath = Path.Combine(projectDir, s_runtimeConfigFileName);

            File.Exists(migratedRuntimeOptionsPath).Should().BeFalse();
        }
        public GivenThatIWantToMigrateAssemblyInfo()
        {
            var projectDirectory =
                TestAssetsManager.CreateTestInstance("AppWithAssemblyInfo").Path;
            var projectContext =
                ProjectContext.Create(projectDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);

            _mockProject = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(projectDirectory, projectDirectory, _mockProject, null);
            var testInputs   = new MigrationRuleInputs(
                new[] { projectContext },
                _mockProject,
                _mockProject.AddItemGroup(),
                _mockProject.AddPropertyGroup());

            new MigrateAssemblyInfoRule().Apply(testSettings, testInputs);
        }
Пример #13
0
        public void ItHasErrorWhenMigratingANonCsharpApp()
        {
            var testProjectDirectory =
                TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
                .Path;

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
            var report          = projectMigrator.Migrate(testSettings);
            var projectReport   = report.ProjectMigrationReports.First();

            var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();

            errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project");
        }
        private static ProjectRootElement RunMigrationRulesOnGeneratedProject(IEnumerable <IMigrationRule> rules,
                                                                              ProjectContext projectContext, string testDirectory, ProjectRootElement xproj)
        {
            var project      = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, project);
            var testInputs   = new MigrationRuleInputs(new[] { projectContext }, project,
                                                       project.AddItemGroup(),
                                                       project.AddPropertyGroup(),
                                                       xproj);

            foreach (var rule in rules)
            {
                rule.Apply(testSettings, testInputs);
            }

            return(project);
        }
Пример #15
0
        public void ItHasErrorWhenMigratingADeprecatedProjectJson()
        {
            var testProjectDirectory =
                TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
                .Path;

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, testProjectDirectory, mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
            var report          = projectMigrator.Migrate(testSettings);

            var projectReport = report.ProjectMigrationReports.First();

            var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();

            errorMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
            errorMessage.Should().Contain("The 'packInclude' option is deprecated. Use 'files' in 'packOptions' instead. (line: 6, file:");
            errorMessage.Should().Contain("The 'compilationOptions' option is deprecated. Use 'buildOptions' instead. (line: 3, file:");
        }
Пример #16
0
        public void It_does_not_migrate_a_dependency_with_target_package_that_has_a_matching_project_as_a_ProjectReference()
        {
            var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
            var solutionDirectory =
                testAssetsManager.CreateTestInstance("AppWithProjectDependencyAsTarget", callingMethod: "p").Path;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(
                item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Should().BeEmpty();
        }
Пример #17
0
        public void It_throws_when_project_dependency_is_unresolved()
        {
            // No Lock file => unresolved
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance("TestAppWithLibrary").Path;

            var appDirectory     = Path.Combine(solutionDirectory, "TestApp");
            var libraryDirectory = Path.Combine(solutionDirectory, "TestLibrary");

            Directory.Delete(libraryDirectory, true);

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(), mockProj.AddPropertyGroup());

            Action action = () => new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            action.ShouldThrow <Exception>()
            .Where(e => e.Message.Contains("MIGRATE1014::Unresolved Dependency: Unresolved project dependency (TestLibrary)"));
        }
        public void ItDoesNotReferenceTheProjectUnderBackupWhenMigratingAPartiallyMigratedStructure()
        {
            var testAssetsManager = GetTestGroupTestAssetsManager("NonRestoredTestProjects");
            var solutionDirectory = testAssetsManager.CreateTestInstance("PJHalfMigrated").Path;

            var appDirectory = Path.Combine(solutionDirectory, "ProjectB");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(
                item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Should().ContainSingle();
            projectReferences.Single().Include.Should().Be(Path.Combine("..", "src", "ProjectA", "ProjectA.csproj"));
        }
Пример #19
0
        public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent()
        {
            var testProjectDirectory = TestAssetsManager
                                       .CreateTestInstance("PJTestAppSimple", callingMethod: "z")
                                       .Path;

            var outputDirectory = Temp.CreateDirectory().Path;

            var projectDirectoryRelativeFilePaths = EnumerateFilesWithRelativePath(testProjectDirectory);

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(testProjectDirectory, outputDirectory, mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());

            projectMigrator.Migrate(testSettings);

            foreach (var projectDirectoryRelativeFilePath in projectDirectoryRelativeFilePaths)
            {
                File.Exists(Path.Combine(outputDirectory, projectDirectoryRelativeFilePath)).Should().BeTrue();
            }
        }
Пример #20
0
        public void MigrateTFMRuleDoesNotAddRuntimesWhenMigratingDesktopTFMsWithRuntimesAlready()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("TestAppWithMultipleFrameworksAndRuntimes")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings =
                MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
        }
        public void ItDoesNotMigrateADependencyWithTargetPackageThatHasAMatchingProjectAsAProjectReference()
        {
            var solutionDirectory = TestAssets.Get("NonRestoredTestProjects", "AppWithProjectDependencyAsTarget")
                                    .CreateInstance(callingMethod: "p")
                                    .WithSourceFiles()
                                    .Root.FullName;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp11);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(
                item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Should().BeEmpty();
        }
Пример #22
0
        public void MigratingMultiTFMProjectPopulatesTargetFrameworksWithShortTfms()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("TestLibraryWithMultipleFrameworks")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs   = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "TargetFrameworks").Should().Be(1);
            mockProj.Properties.First(p => p.Name == "TargetFrameworks")
            .Value.Should().Be("net20;net35;net40;net461;netstandard1.5");
        }
Пример #23
0
        public void MigratingCoreAndDesktopTFMsAddsAllRuntimeIdentifiersIfTheProjectDoesNothaveAnyAlready()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("PJAppWithMultipleFrameworks")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings = MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs   = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(1);
            mockProj.Properties.First(p => p.Name == "RuntimeIdentifiers")
            .Value.Should().Be("win7-x64;win7-x86;osx.10.10-x64;osx.10.11-x64;ubuntu.14.04-x64;ubuntu.16.04-x64;centos.7-x64;rhel.7.2-x64;debian.8-x64;fedora.23-x64;opensuse.13.2-x64");
        }
Пример #24
0
        public void It_promotes_FrameworkAssemblies_from_P2P_references_up_in_the_dependency_chain()
        {
            var solutionDirectory = TestAssets.Get(TestAssetKinds.DesktopTestProjects, "TestAppWithFrameworkAssemblies")
                                    .CreateInstance()
                                    .WithSourceFiles().Root;

            var appDirectory = Path.Combine(solutionDirectory.FullName, "ProjectA");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.Net451);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var frameworkAssemblyReferences = mockProj.Items.Where(
                item => item.ItemType == "Reference" &&
                item.Include == "System.ComponentModel.DataAnnotations" &&
                item.Parent.Condition == " '$(TargetFramework)' == 'net451' ");

            frameworkAssemblyReferences.Count().Should().Be(1);
        }
Пример #25
0
        public void MigratingProjectWithFullFrameworkTFMsDoesNotAddRuntimeIdentifiersOrRuntimeIdentiferWhenNoRuntimesExistAlready()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssets)
                                .FromTestAssetBase("AppWith4netTfm0Rid")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings =
                MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
            mockProj.Properties.Where(p => p.Name == "RuntimeIdentifier").Should().HaveCount(0);
        }
Пример #26
0
        public void MigratingProjectWithFullFrameworkTFMsOnlyAddsARuntimeIdentifierWin7x86WhenNoRuntimesExistAlready()
        {
            var testDirectory = Temp.CreateDirectory().Path;
            var testPJ        = new ProjectJsonBuilder(TestAssetsManager)
                                .FromTestAssetBase("TestAppWithMultipleFullFrameworksOnly")
                                .SaveToDisk(testDirectory);

            var projectContexts = ProjectContext.CreateContextForEachFramework(testDirectory);
            var mockProj        = ProjectRootElement.Create();

            var migrationSettings =
                MigrationSettings.CreateMigrationSettingsTestHook(testDirectory, testDirectory, mockProj);
            var migrationInputs = new MigrationRuleInputs(
                projectContexts,
                mockProj,
                mockProj.AddItemGroup(),
                mockProj.AddPropertyGroup());

            new MigrateTFMRule().Apply(migrationSettings, migrationInputs);

            mockProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
            mockProj.Properties.Where(p => p.Name == "RuntimeIdentifier").Should().HaveCount(1);
            mockProj.Properties.Single(p => p.Name == "RuntimeIdentifier").Value.Should().Be("win7-x86");
        }
Пример #27
0
        public void Project_dependencies_are_migrated_to_ProjectReference()
        {
            var solutionDirectory =
                TestAssetsManager.CreateTestInstance("TestAppWithLibrary", callingMethod: "p").Path;

            var appDirectory = Path.Combine(solutionDirectory, "TestApp");

            var projectContext = ProjectContext.Create(appDirectory, FrameworkConstants.CommonFrameworks.NetCoreApp10);
            var mockProj       = ProjectRootElement.Create();
            var testSettings   = MigrationSettings.CreateMigrationSettingsTestHook(appDirectory, appDirectory, mockProj, null);
            var testInputs     = new MigrationRuleInputs(new[] { projectContext }, mockProj, mockProj.AddItemGroup(),
                                                         mockProj.AddPropertyGroup());

            new MigrateProjectDependenciesRule().Apply(testSettings, testInputs);

            var projectReferences = mockProj.Items.Where(item => item.ItemType.Equals("ProjectReference", StringComparison.Ordinal));

            projectReferences.Count().Should().Be(1);

            var projectReference = projectReferences.First();

            projectReference.Include.Should().Be(Path.Combine("..", "TestLibrary", "TestLibrary.csproj"));
            projectReference.Parent.Condition.Should().BeEmpty();
        }
Пример #28
0
        public void ItHasErrorWhenMigratingADeprecatedNamedResourceOptionProjectJson()
        {
            var testProjectDirectory = TestAssets
                                       .GetProjectJson(TestAssetKinds.NonRestoredTestProjects, "PJDeprecatedNamedResource")
                                       .CreateInstance()
                                       .WithSourceFiles()
                                       .Root
                                       .FullName;

            var mockProj     = ProjectRootElement.Create();
            var testSettings = MigrationSettings.CreateMigrationSettingsTestHook(
                testProjectDirectory,
                testProjectDirectory,
                mockProj);

            var projectMigrator = new ProjectMigrator(new FakeEmptyMigrationRule());
            var report          = projectMigrator.Migrate(testSettings);

            var projectReport = report.ProjectMigrationReports.First();
            var errorMessage  = projectReport.Errors.First().GetFormattedErrorMessage();

            errorMessage.Should().Contain("MIGRATE1011::Deprecated Project:");
            errorMessage.Should().Contain("The 'namedResource' option is deprecated. Use 'embed' in 'buildOptions' instead. (line: 3, file:");
        }