Fix 4655: Migrate errors are not getting put in formatted output (#4718)

* Fix 4655: Migrate errors are not getting put in formatted output

* Move test asset to NonRestoredTestProjects

* use group test asset manager: NonRestoredTestProjects
This commit is contained in:
Krzysztof Wicher 2016-11-15 09:39:58 -08:00 committed by GitHub
parent bf425a6f0a
commit 43df9a170d
8 changed files with 57 additions and 0 deletions

View file

@ -0,0 +1,10 @@
namespace ConsoleApplication
{
public class Program
{
public static void Main(string[] args)
{
}
}
}

View file

@ -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"
}
}
}

View file

@ -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
{
}

View file

@ -28,6 +28,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public static Func<string, MigrationError> MIGRATE1017
=> (message) => new MigrationError(nameof(MIGRATE1017), "Multiple Xproj Files", message);
public static Func<string, MigrationError> MIGRATE1018
=> (message) => new MigrationError(nameof(MIGRATE1018), "Dependency Project not found", message);
// Potentially Temporary (Point in Time) Errors
public static Func<string, MigrationError> MIGRATE20011
=> (message) => new MigrationError(nameof(MIGRATE20011), "Multi-TFM", message);

View file

@ -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)

View file

@ -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)