When we had a project.json without frameworks, we were failing to show the appropriate error message because when we were generating the error message itself we tried to access the project context (which requires a framework in the PJ). This fix makes the ProjectContext optional to add the migration error.
This commit is contained in:
parent
355b6233cb
commit
bb1bceb8bb
4 changed files with 40 additions and 6 deletions
|
@ -0,0 +1,8 @@
|
||||||
|
{
|
||||||
|
"dependencies": {
|
||||||
|
"Microsoft.VisualStudio.Web.CodeGeneration.Tools" : {
|
||||||
|
"version": "1.0.0-preview2-final",
|
||||||
|
"type": "build"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,7 +24,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return ProjectContexts.First();
|
return ProjectContexts.FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
new ProjectMigrationReport(
|
new ProjectMigrationReport(
|
||||||
rootSettings.ProjectDirectory,
|
rootSettings.ProjectDirectory,
|
||||||
rootInputs?.DefaultProjectContext.GetProjectName(),
|
rootInputs?.DefaultProjectContext?.GetProjectName(),
|
||||||
new List<MigrationError> {e.Error},
|
new List<MigrationError> {e.Error},
|
||||||
null)
|
null)
|
||||||
});
|
});
|
||||||
|
@ -193,7 +193,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
||||||
{
|
{
|
||||||
if (!projectContexts.Any())
|
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();
|
var defaultProjectContext = projectContexts.First();
|
||||||
|
|
|
@ -16,7 +16,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
public class GivenAProjectMigrator : TestBase
|
public class GivenAProjectMigrator : TestBase
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_copies_ProjectDirectory_contents_to_OutputDirectory_when_the_directories_are_different()
|
public void ItCopiesProjectDirectoryContentsToOutputDirectoryWhenTheDirectoriesAreDifferent()
|
||||||
{
|
{
|
||||||
var testProjectDirectory = TestAssetsManager
|
var testProjectDirectory = TestAssetsManager
|
||||||
.CreateTestInstance("PJTestAppSimple", callingMethod: "z")
|
.CreateTestInstance("PJTestAppSimple", callingMethod: "z")
|
||||||
|
@ -39,7 +39,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_has_error_when_migrating_a_deprecated_projectJson()
|
public void ItHasErrorWhenMigratingADeprecatedProjectJson()
|
||||||
{
|
{
|
||||||
var testProjectDirectory =
|
var testProjectDirectory =
|
||||||
TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
|
TestAssetsManager.CreateTestInstance("TestLibraryWithDeprecatedProjectFile", callingMethod: "z")
|
||||||
|
@ -60,7 +60,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public void It_has_error_when_migrating_a_non_csharp_app()
|
public void ItHasErrorWhenMigratingANonCsharpApp()
|
||||||
{
|
{
|
||||||
var testProjectDirectory =
|
var testProjectDirectory =
|
||||||
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
|
TestAssetsManager.CreateTestInstance("FSharpTestProjects/TestApp", callingMethod: "z")
|
||||||
|
@ -77,6 +77,32 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||||
errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project");
|
errorMessage.Should().Contain("MIGRATE20013::Non-Csharp App: Cannot migrate project");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void ItHasErrorWhenMigratingAProjectJsonWithoutAFrameworks()
|
||||||
|
{
|
||||||
|
var testAppName = "TestLibraryWithProjectFileWithoutFrameworks";
|
||||||
|
var testInstance = TestAssets.Get(testAppName)
|
||||||
|
.CreateInstance(testAppName)
|
||||||
|
.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();
|
||||||
|
|
||||||
|
var errorMessage = projectReport.Errors.First().GetFormattedErrorMessage();
|
||||||
|
errorMessage.Should().Contain("MIGRATE1013::No Project:");
|
||||||
|
errorMessage.Should().Contain($"The project.json specifies no target frameworks in {testProjectDirectory}");
|
||||||
|
}
|
||||||
|
|
||||||
private IEnumerable<string> EnumerateFilesWithRelativePath(string testProjectDirectory)
|
private IEnumerable<string> EnumerateFilesWithRelativePath(string testProjectDirectory)
|
||||||
{
|
{
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue