diff --git a/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/.noautobuild b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/.noautobuild b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/.noautobuild new file mode 100644 index 000000000..e69de29bb diff --git a/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/Program.cs b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/Program.cs new file mode 100644 index 000000000..a552b21e7 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/Program.cs @@ -0,0 +1,10 @@ +namespace ConsoleApplication +{ + public class Program + { + public static void Main(string[] args) + { + } + } +} + diff --git a/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/project.json b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/project.json new file mode 100644 index 000000000..e10324be5 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyApp/project.json @@ -0,0 +1,20 @@ +{ + "version": "1.0.0-*", + "buildOptions": { + "emitEntryPoint": true + }, + + "dependencies": { + "Microsoft.NETCore.App": { + "type": "platform", + "version": "1.0.1" + }, + "MyLib": "1.0.0-*" + }, + + "frameworks": { + "netcoreapp1.0": { + "imports": "dnxcore50" + } + } +} diff --git a/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyLib/NotUsedButDoNotRemove.cs b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyLib/NotUsedButDoNotRemove.cs new file mode 100644 index 000000000..d16e6e2d3 --- /dev/null +++ b/TestAssets/NonRestoredTestProjects/MigrateAppWithMissingDep/MyLib/NotUsedButDoNotRemove.cs @@ -0,0 +1,5 @@ +// This file needs to be here as this error does not repro if the MyLib folder doesn't exist +// Since git does not keep track of folders and files only, this folder needs to contain any file. +namespace MyLib +{ +} diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationErrorCodes.cs b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationErrorCodes.cs index 336bd42c0..f7c54e54b 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/MigrationErrorCodes.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/MigrationErrorCodes.cs @@ -28,6 +28,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration public static Func MIGRATE1017 => (message) => new MigrationError(nameof(MIGRATE1017), "Multiple Xproj Files", message); + public static Func MIGRATE1018 + => (message) => new MigrationError(nameof(MIGRATE1018), "Dependency Project not found", message); + // Potentially Temporary (Point in Time) Errors public static Func MIGRATE20011 => (message) => new MigrationError(nameof(MIGRATE20011), "Multi-TFM", message); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index fbfa76838..4b417d389 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -55,6 +55,12 @@ namespace Microsoft.DotNet.ProjectJsonMigration { var project = projects.First(); projects.Remove(project); + if (!File.Exists(project.ProjectFilePath)) + { + MigrationErrorCodes + .MIGRATE1018($"Dependency project not found ({project.ProjectFilePath})").Throw(); + } + var projectContext = ProjectContext.CreateContextForEachFramework(project.ProjectFilePath).FirstOrDefault(); if(projectContext == null) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 9a26e2c93..f12a9d5e4 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -436,6 +436,19 @@ namespace Microsoft.DotNet.Migration.Tests BuildMSBuild(projectDirectory, projectName); } + [Fact] + public void It_fails_gracefully_when_migrating_app_with_missing_dependency() + { + string projectName = "MigrateAppWithMissingDep"; + var projectDirectory = Path.Combine(GetTestGroupTestAssetsManager("NonRestoredTestProjects").CreateTestInstance(projectName).Path, "MyApp"); + + string migrationOutputFile = Path.Combine(projectDirectory, "migration-output.json"); + File.Exists(migrationOutputFile).Should().BeFalse(); + MigrateCommand.Run(new string[] { projectDirectory, "-r", migrationOutputFile, "--format-report-file-json" }).Should().NotBe(0); + File.Exists(migrationOutputFile).Should().BeTrue(); + File.ReadAllText(migrationOutputFile).Should().Contain("MIGRATE1018"); + } + private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent) { if (projectName != null)