diff --git a/TestAssets/TestProjects/TestAppWithContents/project.json b/TestAssets/TestProjects/TestAppWithContents/project.json index 9bc98a36a..5620a3bc3 100644 --- a/TestAssets/TestProjects/TestAppWithContents/project.json +++ b/TestAssets/TestProjects/TestAppWithContents/project.json @@ -9,7 +9,7 @@ "include": "testcontentfile2.txt" }, "out/": { - "include": ["project.json", "Program.cs"], + "include": ["Program.cs"], "exclude": ["Program.cs"], "includeFiles": ["Program.cs"], "excludeFiles": ["Program.cs"] diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependency.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependency.cs index 017d123c6..03c780d43 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependency.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependency.cs @@ -11,7 +11,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration public ProjectDependency(string name, string projectFilePath) { Name = name; - ProjectFilePath = projectFilePath; + ProjectFilePath = System.IO.Path.GetFullPath(projectFilePath); } } } diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs index 97c8c544c..6bcb6f442 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectMigrator.cs @@ -60,6 +60,22 @@ namespace Microsoft.DotNet.ProjectJsonMigration } } + private void DeleteProjectJsons(MigrationSettings rootsettings, IEnumerable projectDependencies) + { + try + { + File.Delete(Path.Combine(rootsettings.ProjectDirectory, "project.json")); + } catch {} + + foreach (var projectDependency in projectDependencies) + { + try + { + File.Delete(projectDependency.ProjectFilePath); + } catch { } + } + } + private IEnumerable ResolveTransitiveClosureProjectDependencies(string rootProject, string xprojFile) { HashSet projectsMap = new HashSet(new ProjectDependencyComparer()); diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesRule.cs index 6ab1491ed..a619a40ea 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/MigratePackageDependenciesRule.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.Build.Construction; +using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectJsonMigration.Transforms; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Graph; @@ -38,11 +39,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules var targetFrameworks = project.GetTargetFrameworks(); // Inject Sdk dependency - PackageDependencyInfoTransform.Transform(new PackageDependencyInfo - { - Name = ConstantPackageNames.CSdkPackageName, - Version = migrationSettings.SdkPackageVersion - }); + _transformApplicator.Execute( + PackageDependencyInfoTransform.Transform( + new PackageDependencyInfo + { + Name = ConstantPackageNames.CSdkPackageName, + Version = migrationSettings.SdkPackageVersion + }), migrationRuleInputs.CommonItemGroup); // Migrate Direct Deps first MigrateDependencies( @@ -51,16 +54,19 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules null, project.Dependencies, migrationRuleInputs.ProjectXproj); - + + MigrationTrace.Instance.WriteLine($"Migrating {targetFrameworks.Count()} target frameworks"); foreach (var targetFramework in targetFrameworks) { + MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}"); + MigrateImports(migrationRuleInputs.CommonItemGroup, targetFramework); MigrateDependencies( project, migrationRuleInputs.OutputMSBuildProject, targetFramework.FrameworkName, - project.Dependencies, + targetFramework.Dependencies, migrationRuleInputs.ProjectXproj); } } @@ -104,6 +110,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules foreach (var packageDependency in packageDependencies) { + MigrationTrace.Instance.WriteLine(packageDependency.Name); AddItemTransform transform; if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference) @@ -124,7 +131,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules transform = transform.WithMetadata("PrivateAssets", metadataValue); } - // TODO: include/exclude if (packageDependency.IncludeType != LibraryIncludeFlags.All) { var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType); @@ -210,7 +216,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules "PackageTargetFallback", t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}", t => "", - t => t.Imports.Any()); + t => t.Imports.OrEmptyIfNull().Any()); private class PackageDependencyInfo { diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/TemporaryMutateProjectJsonRule.cs b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/TemporaryMutateProjectJsonRule.cs index 5ed862b76..c6f6387ad 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/Rules/TemporaryMutateProjectJsonRule.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/Rules/TemporaryMutateProjectJsonRule.cs @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules var sourceProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.json"); var renamedProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.migrated.json"); - File.Move(sourceProjectFile, renamedProjectFile); + File.Copy(sourceProjectFile, renamedProjectFile); sourceProjectFile = renamedProjectFile; } } diff --git a/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs b/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs index e1fc07ac5..262670ad0 100644 --- a/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs +++ b/src/dotnet/commands/dotnet-migrate/ProjectRootElementExtensions.cs @@ -8,14 +8,11 @@ namespace Microsoft.DotNet.Tools.Migrate { public static string GetSdkVersion(this ProjectRootElement projectRootElement) { - //TODO: Temporarily pinning the SDK version for Migration. Once we have packageref migration we can remove this. - return "1.0.0-alpha-20160929-1"; - - // return projectRootElement - // .Items - // .Where(i => i.ItemType == "PackageReference") - // .First(i => i.Include == ConstantPackageNames.CSdkPackageName) - // .GetMetadataWithName("version").Value; + return projectRootElement + .Items + .Where(i => i.ItemType == "PackageReference") + .First(i => i.Include == ConstantPackageNames.CSdkPackageName) + .GetMetadataWithName("version").Value; } } } \ No newline at end of file diff --git a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs index 95b292a5b..4bc1b0b27 100644 --- a/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs +++ b/test/dotnet-migrate.Tests/GivenThatIWantToMigrateTestApps.cs @@ -47,7 +47,10 @@ namespace Microsoft.DotNet.Migration.Tests [Fact] public void It_migrates_dotnet_new_console_with_identical_outputs() { - var projectDirectory = Temp.CreateDirectory().Path; + var projectDirectory = Path.Combine(AppContext.BaseDirectory, "newconsoletest"); + Directory.Delete(projectDirectory, true); + Directory.CreateDirectory(projectDirectory); + var outputComparisonData = GetDotnetNewComparisonData(projectDirectory, "console"); var outputsIdentical = @@ -60,7 +63,7 @@ namespace Microsoft.DotNet.Migration.Tests VerifyAllMSBuildOutputsRunnable(projectDirectory); } - [Fact] + [Fact(Skip="https://github.com/dotnet/cli/issues/4299")] public void It_migrates_dotnet_new_web_with_outputs_containing_project_json_outputs() { var projectDirectory = Temp.CreateDirectory().Path; @@ -214,7 +217,7 @@ namespace Microsoft.DotNet.Migration.Tests Restore(projectDirectory); var outputComparisonData = - BuildProjectJsonMigrateBuildMSBuild(projectDirectory, Path.GetFileNameWithoutExtension(projectDirectory)); + BuildProjectJsonMigrateBuildMSBuild(projectDirectory); return outputComparisonData; } @@ -231,7 +234,7 @@ namespace Microsoft.DotNet.Migration.Tests } } - private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory, string projectName) + private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory, string projectName=null) { BuildProjectJson(projectDirectory); var projectJsonBuildOutputs = new HashSet(CollectBuildOutputs(projectDirectory)); @@ -243,8 +246,8 @@ namespace Microsoft.DotNet.Migration.Tests MigrateProject(projectDirectory); DeleteXproj(projectDirectory); - Restore3(projectDirectory); - BuildMSBuild(projectDirectory); + Restore3(projectDirectory, projectName); + BuildMSBuild(projectDirectory, projectName); var msbuildBuildOutputs = new HashSet(CollectBuildOutputs(projectDirectory)); @@ -306,22 +309,37 @@ namespace Microsoft.DotNet.Migration.Tests .Pass(); } - private void Restore3(string projectDirectory, string projectName) + private void Restore3(string projectDirectory, string projectName=null) { - new Restore3Command() - .WithWorkingDirectory(projectDirectory) - .Execute($"{projectName}.csproj") + var command = new Restore3Command() + .WithWorkingDirectory(projectDirectory); + + if (projectName != null) + { + command.Execute($"{projectName}.csproj") .Should() .Pass(); + } + else + { + command.Execute() + .Should() + .Pass(); + } } private string BuildMSBuild(string projectDirectory, string projectName, string configuration="Debug") { + if (projectName != null) + { + projectName = projectName + ".csproj"; + } + DeleteXproj(projectDirectory); var result = new Build3Command() .WithWorkingDirectory(projectDirectory) - .ExecuteWithCapturedOutput($"{projectName}.csproj /p:Configuration={configuration}"); + .ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}"); result .Should()