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
|
||||
{
|
||||
return ProjectContexts.First();
|
||||
return ProjectContexts.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
{
|
||||
new ProjectMigrationReport(
|
||||
rootSettings.ProjectDirectory,
|
||||
rootInputs?.DefaultProjectContext.GetProjectName(),
|
||||
rootInputs?.DefaultProjectContext?.GetProjectName(),
|
||||
new List<MigrationError> {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();
|
||||
|
|
|
@ -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,32 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
|||
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)
|
||||
{
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue