diff --git a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs index 4b2132663..e9ddebe68 100644 --- a/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs +++ b/src/dotnet/commands/dotnet-migrate/MigrateCommand.cs @@ -7,6 +7,7 @@ using System.IO; using System.Linq; using System.Text; using Microsoft.Build.Construction; +using Microsoft.Build.Evaluation; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectJsonMigration; using Microsoft.DotNet.Internal.ProjectModel; @@ -49,7 +50,9 @@ namespace Microsoft.DotNet.Tools.Migrate var projectsToMigrate = GetProjectsToMigrate(_projectArg); var msBuildTemplate = _templateFile != null ? - ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject; + ProjectRootElement.Open(_templateFile, + ProjectCollection.GlobalProjectCollection, + preserveFormatting: true) : _temporaryDotnetNewProject.MSBuildProject; var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion(); @@ -188,7 +191,7 @@ namespace Microsoft.DotNet.Tools.Migrate { IEnumerable projects = null; - if (projectArg.EndsWith(Project.FileName, StringComparison.OrdinalIgnoreCase)) + if (projectArg.EndsWith(ProjectModel.Project.FileName, StringComparison.OrdinalIgnoreCase)) { projects = Enumerable.Repeat(projectArg, 1); } @@ -202,7 +205,7 @@ namespace Microsoft.DotNet.Tools.Migrate } else if (Directory.Exists(projectArg)) { - projects = Directory.EnumerateFiles(projectArg, Project.FileName, SearchOption.AllDirectories); + projects = Directory.EnumerateFiles(projectArg, ProjectModel.Project.FileName, SearchOption.AllDirectories); if (!projects.Any()) { throw new Exception($"No project.json file found in '{projectArg}'"); diff --git a/src/dotnet/commands/dotnet-migrate/TemporaryDotnetNewTemplateProject.cs b/src/dotnet/commands/dotnet-migrate/TemporaryDotnetNewTemplateProject.cs index 124e0e81a..d14b9e627 100644 --- a/src/dotnet/commands/dotnet-migrate/TemporaryDotnetNewTemplateProject.cs +++ b/src/dotnet/commands/dotnet-migrate/TemporaryDotnetNewTemplateProject.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.DotNet.ProjectJsonMigration; +using Microsoft.Build.Evaluation; namespace Microsoft.DotNet.Tools.Migrate { @@ -52,7 +53,9 @@ namespace Microsoft.DotNet.Tools.Migrate var templateProjPath = Path.Combine(temporaryDotnetNewMSBuildDirectory, c_temporaryDotnetNewMSBuildProjectName + ".csproj"); - return ProjectRootElement.Open(templateProjPath); + return ProjectRootElement.Open(templateProjPath, + ProjectCollection.GlobalProjectCollection, + preserveFormatting: true); } private void RunCommand(string commandToExecute, IEnumerable args, string workingDirectory) diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 5b7a78b6c..4236911c9 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -20,7 +20,7 @@ namespace Microsoft.DotNet.Migration.Tests [InlineData("TestAppWithRuntimeOptions")] [InlineData("TestAppWithContents")] [InlineData("AppWithAssemblyInfo")] - public void It_migrates_apps(string projectName) + public void It_migrates_apps_and_puts_newline_at_end_of_file(string projectName) { var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, identifier: projectName) .WithLockFiles() @@ -41,6 +41,11 @@ namespace Microsoft.DotNet.Migration.Tests outputsIdentical.Should().BeTrue(); VerifyAllMSBuildOutputsRunnable(projectDirectory); + + var outputCsProj = Path.Combine(projectDirectory, projectName + ".csproj"); + var csproj = File.ReadAllText(outputCsProj); + Console.WriteLine(csproj); + csproj.EndsWith(Environment.NewLine).Should().Be(true); } [Fact]