diff --git a/TestAssets/NonRestoredTestProjects/TestLibraryWithProjectFileWithoutFrameworks/project.json b/TestAssets/NonRestoredTestProjects/TestLibraryWithProjectFileWithoutFrameworks/project.json new file mode 100644 index 000000000..d685d1947 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/TestLibraryWithProjectFileWithoutFrameworks/project.json @@ -0,0 +1,8 @@ +{ + "dependencies": { + "Microsoft.VisualStudio.Web.CodeGeneration.Tools" : { + "version": "1.0.0-preview2-final", + "type": "build" + } + } +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationRuleInputs.cs b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationRuleInputs.cs index f08c06c88..5d69da274 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationRuleInputs.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationRuleInputs.cs @@ -24,7 +24,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration { get { - return ProjectContexts.First(); + return ProjectContexts.FirstOrDefault(); } } diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs index f6e4c46ad..155748556 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs @@ -55,7 +55,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration { new ProjectMigrationReport( rootSettings.ProjectDirectory, - rootInputs?.DefaultProjectContext.GetProjectName(), + rootInputs?.DefaultProjectContext?.GetProjectName(), new List {e.Error}, null) }); @@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration { if (!projectContexts.Any()) { - MigrationErrorCodes.MIGRATE1013($"No projects found in {projectDirectory}").Throw(); + MigrationErrorCodes.MIGRATE1013($"The project.json specifies no target frameworks in {projectDirectory}").Throw(); } var defaultProjectContext = projectContexts.First(); diff --git a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs index b6d321f77..d15de0265 100644 --- a/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs +++ b/test/Microsoft.DotNet.ProjectJsonMigration.Tests/GivenAProjectMigrator.cs @@ -16,7 +16,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests public class GivenAProjectMigrator : TestBase { [Fact] - public void It_copies_ProjectDirectory_contents_to_OutputDirectory_when_the_directories_are_different() + public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent() { var testProjectDirectory = TestAssetsManager .CreateTestInstance("PJTestAppSimple", callingMethod: "z") @@ -39,7 +39,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } [Fact] - public void It_has_error_when_migrating_a_deprecated_projectJson() + public void ItHasErrorWhenMigratingADeprecatedProjectJson() { var testProjectDirectory = TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z") @@ -60,7 +60,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests } [Fact] - public void It_has_error_when_migrating_a_non_csharp_app() + public void ItHasErrorWhenMigratingANonCsharpApp() { var testProjectDirectory = TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z") @@ -77,6 +77,33 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project"); } + [Fact] + 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}"); + } + private IEnumerable EnumerateFilesWithRelativePath(string testProjectDirectory) { return