2016-12-20 23:04:01 +00:00
|
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
|
|
using Microsoft.Build.Construction;
|
2016-10-18 01:02:10 +00:00
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Xunit;
|
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using System.IO;
|
2016-08-23 20:50:05 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Migrate;
|
2016-09-19 20:25:40 +00:00
|
|
|
|
using BuildCommand = Microsoft.DotNet.Tools.Test.Utilities.BuildCommand;
|
2016-10-04 23:48:14 +00:00
|
|
|
|
using System.Runtime.Loader;
|
2016-10-20 22:04:53 +00:00
|
|
|
|
using Newtonsoft.Json.Linq;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-10-29 08:58:37 +00:00
|
|
|
|
using MigrateCommand = Microsoft.DotNet.Tools.Migrate.MigrateCommand;
|
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
namespace Microsoft.DotNet.Migration.Tests
|
|
|
|
|
{
|
|
|
|
|
public class GivenThatIWantToMigrateTestApps : TestBase
|
|
|
|
|
{
|
|
|
|
|
[Theory]
|
2016-08-23 20:50:05 +00:00
|
|
|
|
[InlineData("TestAppWithRuntimeOptions")]
|
2016-09-08 21:40:46 +00:00
|
|
|
|
[InlineData("TestAppWithContents")]
|
2016-10-26 22:13:39 +00:00
|
|
|
|
[InlineData("AppWithAssemblyInfo")]
|
2016-12-14 21:59:01 +00:00
|
|
|
|
[InlineData("TestAppWithEmbeddedResources")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesApps(string projectName)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, identifier: projectName)
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.Path;
|
2016-09-29 20:05:27 +00:00
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
|
2016-09-28 02:25:13 +00:00
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
2016-08-23 20:50:05 +00:00
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2017-01-06 06:55:43 +00:00
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
|
|
|
|
|
|
|
|
|
var outputCsProj = Path.Combine(projectDirectory, projectName + ".csproj");
|
|
|
|
|
var csproj = File.ReadAllText(outputCsProj);
|
|
|
|
|
csproj.EndsWith("\n").Should().Be(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[WindowsOnlyTheory]
|
2017-01-06 19:34:37 +00:00
|
|
|
|
[InlineData("TestAppMultipleFrameworksNoRuntimes", null)]
|
2017-01-06 06:55:43 +00:00
|
|
|
|
[InlineData("TestAppWithMultipleFullFrameworksOnly", "net461")]
|
|
|
|
|
public void ItMigratesAppsWithFullFramework(string projectName, string framework)
|
|
|
|
|
{
|
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance(
|
|
|
|
|
projectName,
|
|
|
|
|
identifier: projectName).WithLockFiles().Path;
|
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
|
|
|
|
|
MigrateProject(new [] { projectDirectory });
|
|
|
|
|
|
|
|
|
|
Restore(projectDirectory);
|
|
|
|
|
|
|
|
|
|
BuildMSBuild(projectDirectory, projectName, framework: framework);
|
2016-08-23 20:50:05 +00:00
|
|
|
|
}
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-10-21 03:15:42 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesSignedApps()
|
2016-10-04 23:48:14 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppWithSigning").WithLockFiles().Path;
|
2016-10-04 23:48:14 +00:00
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
|
2016-10-21 03:15:42 +00:00
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, "TestAppWithSigning");
|
2016-10-04 23:48:14 +00:00
|
|
|
|
|
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
VerifyAllMSBuildOutputsAreSigned(projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesDotnetNewConsoleWithIdenticalOutputs()
|
2016-08-23 20:50:05 +00:00
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("ProjectJsonConsoleTemplate");
|
|
|
|
|
|
|
|
|
|
var projectDirectory = testInstance.Path;
|
2016-10-04 03:10:09 +00:00
|
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
|
var outputComparisonData = GetComparisonData(projectDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 08:30:02 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItMigratesOldDotnetNewWebWithoutToolsWithOutputsContainingProjectJsonOutputs()
|
2016-08-23 20:50:05 +00:00
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
2016-10-20 22:04:53 +00:00
|
|
|
|
.CreateTestInstance("ProjectJsonWebTemplate")
|
|
|
|
|
.WithLockFiles();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
|
|
|
|
var projectDirectory = testInstance.Path;
|
|
|
|
|
|
2016-10-20 22:04:53 +00:00
|
|
|
|
var globalDirectory = Path.Combine(projectDirectory, "..");
|
|
|
|
|
var projectJsonFile = Path.Combine(projectDirectory, "project.json");
|
|
|
|
|
|
2016-12-09 08:30:02 +00:00
|
|
|
|
WriteGlobalJson(globalDirectory);
|
2016-10-20 22:04:53 +00:00
|
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
|
var outputComparisonData = GetComparisonData(projectDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-09-01 18:42:35 +00:00
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-01 18:42:35 +00:00
|
|
|
|
if (!outputsIdentical)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-08-23 20:50:05 +00:00
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-01 18:42:35 +00:00
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-12 23:42:20 +00:00
|
|
|
|
[Fact]
|
2016-12-14 00:44:53 +00:00
|
|
|
|
public void ItMigratesAndPublishesWebApp()
|
2016-12-12 23:42:20 +00:00
|
|
|
|
{
|
|
|
|
|
const string projectName = "WebAppWithMissingFileInPublishOptions";
|
|
|
|
|
var testInstance = TestAssets.Get(projectName)
|
|
|
|
|
.CreateInstance()
|
|
|
|
|
.WithSourceFiles();
|
|
|
|
|
|
|
|
|
|
var projectDirectory = testInstance.Root.FullName;
|
2016-12-29 06:03:18 +00:00
|
|
|
|
|
|
|
|
|
File.Copy("NuGet.tempaspnetpatch.config", Path.Combine(projectDirectory, "NuGet.Config"));
|
2016-12-12 23:42:20 +00:00
|
|
|
|
|
|
|
|
|
MigrateProject(new [] { projectDirectory });
|
|
|
|
|
|
|
|
|
|
Restore(projectDirectory);
|
|
|
|
|
PublishMSBuild(projectDirectory, projectName);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-17 01:05:14 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItMigratesAPackageReferenceAsSuchEvenIfAFolderWithTheSameNameExistsInTheRepo()
|
|
|
|
|
{
|
|
|
|
|
var solutionDirectory =
|
|
|
|
|
TestAssetsManager.CreateTestInstance("AppWithPackageNamedAfterFolder").Path;
|
2017-01-19 19:34:37 +00:00
|
|
|
|
var appProject = Path.Combine(solutionDirectory, "src", "App", "App.csproj");
|
2017-01-17 01:05:14 +00:00
|
|
|
|
|
|
|
|
|
MigrateProject(solutionDirectory);
|
|
|
|
|
|
|
|
|
|
var projectRootElement = ProjectRootElement.Open(appProject);
|
|
|
|
|
projectRootElement.Items.Where(
|
|
|
|
|
i => i.Include == "EntityFramework" && i.ItemType == "PackageReference")
|
|
|
|
|
.Should().HaveCount(2);
|
|
|
|
|
}
|
2017-01-16 23:16:31 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void ItMigratesAProjectThatDependsOnAMigratedProjectWithTheSkipProjectReferenceFlag()
|
|
|
|
|
{
|
|
|
|
|
const string dependentProject = "ProjectA";
|
|
|
|
|
const string dependencyProject = "ProjectB";
|
|
|
|
|
|
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").Path;
|
|
|
|
|
|
|
|
|
|
MigrateProject(Path.Combine(projectDirectory, dependencyProject));
|
|
|
|
|
|
|
|
|
|
MigrateProject("--skip-project-references", Path.Combine(projectDirectory, dependentProject));
|
|
|
|
|
}
|
2017-01-17 01:05:14 +00:00
|
|
|
|
|
2016-12-12 23:42:20 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItAddsMicrosoftNetWebSdkToTheSdkAttributeOfAWebApp()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("ProjectJsonWebTemplate")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var projectDirectory = testInstance.Path;
|
|
|
|
|
|
|
|
|
|
var globalDirectory = Path.Combine(projectDirectory, "..");
|
|
|
|
|
var projectJsonFile = Path.Combine(projectDirectory, "project.json");
|
|
|
|
|
|
|
|
|
|
MigrateProject(new [] { projectDirectory });
|
|
|
|
|
|
|
|
|
|
var csProj = Path.Combine(projectDirectory, $"{new DirectoryInfo(projectDirectory).Name}.csproj");
|
|
|
|
|
|
|
|
|
|
File.ReadAllText(csProj).Should().Contain(@"Sdk=""Microsoft.NET.Sdk.Web""");
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-15 22:54:10 +00:00
|
|
|
|
[Theory]
|
2016-10-20 22:33:47 +00:00
|
|
|
|
[InlineData("TestLibraryWithTwoFrameworks")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesProjectsWithMultipleTFMs(string projectName)
|
2016-09-15 22:54:10 +00:00
|
|
|
|
{
|
|
|
|
|
var projectDirectory =
|
2016-10-28 01:46:43 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance(projectName, identifier: projectName).WithLockFiles().Path;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-28 02:25:13 +00:00
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
|
2016-09-15 22:54:10 +00:00
|
|
|
|
|
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
|
|
|
|
|
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outputsIdentical.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-12 01:05:12 +00:00
|
|
|
|
[WindowsOnlyFact]
|
|
|
|
|
public void ItMigratesLibraryWithMultipleTFMsAndFullFramework()
|
|
|
|
|
{
|
|
|
|
|
var projectName = "PJLibWithMultipleFrameworks";
|
|
|
|
|
var projectDirectory =
|
|
|
|
|
TestAssetsManager.CreateTestInstance(projectName, identifier: projectName).WithLockFiles().Path;
|
|
|
|
|
|
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
|
|
|
|
|
|
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
|
|
|
|
|
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outputsIdentical.Should().BeTrue();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("TestAppWithLibrary/TestLibrary")]
|
|
|
|
|
[InlineData("TestLibraryWithAnalyzer")]
|
2016-10-28 01:46:43 +00:00
|
|
|
|
[InlineData("PJTestLibraryWithConfiguration")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesALibrary(string projectName)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var projectDirectory =
|
2016-10-28 01:46:43 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance(projectName, identifier: projectName).WithLockFiles().Path;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-29 20:05:27 +00:00
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, Path.GetFileNameWithoutExtension(projectName));
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-09-01 18:42:35 +00:00
|
|
|
|
var outputsIdentical =
|
|
|
|
|
outputComparisonData.ProjectJsonBuildOutputs.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-09-01 18:42:35 +00:00
|
|
|
|
if (!outputsIdentical)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-08-23 20:50:05 +00:00
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
2016-09-01 18:42:35 +00:00
|
|
|
|
|
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-09-23 07:30:41 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("ProjectA", "ProjectA,ProjectB,ProjectC,ProjectD,ProjectE")]
|
|
|
|
|
[InlineData("ProjectB", "ProjectB,ProjectC,ProjectD,ProjectE")]
|
|
|
|
|
[InlineData("ProjectC", "ProjectC,ProjectD,ProjectE")]
|
|
|
|
|
[InlineData("ProjectD", "ProjectD")]
|
|
|
|
|
[InlineData("ProjectE", "ProjectE")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesRootProjectAndReferences(string projectName, string expectedProjects)
|
2016-09-23 07:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
var projectDirectory =
|
2016-12-20 22:19:37 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance(
|
|
|
|
|
"TestAppDependencyGraph",
|
|
|
|
|
identifier: $"{projectName}.RefsTest").Path;
|
2016-09-23 07:30:41 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(new [] { Path.Combine(projectDirectory, projectName) });
|
2016-09-23 07:30:41 +00:00
|
|
|
|
|
|
|
|
|
string[] migratedProjects = expectedProjects.Split(new char[] { ',' });
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-26 21:16:17 +00:00
|
|
|
|
VerifyMigration(migratedProjects, projectDirectory);
|
2016-09-23 07:30:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("ProjectA")]
|
|
|
|
|
[InlineData("ProjectB")]
|
|
|
|
|
[InlineData("ProjectC")]
|
|
|
|
|
[InlineData("ProjectD")]
|
|
|
|
|
[InlineData("ProjectE")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesRootProjectAndSkipsReferences(string projectName)
|
2016-09-23 07:30:41 +00:00
|
|
|
|
{
|
|
|
|
|
var projectDirectory =
|
2016-12-20 22:19:37 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", identifier: $"{projectName}.SkipRefsTest").Path;
|
2016-09-23 07:30:41 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(new [] { Path.Combine(projectDirectory, projectName), "--skip-project-references" });
|
2016-09-26 21:16:17 +00:00
|
|
|
|
|
|
|
|
|
VerifyMigration(Enumerable.Repeat(projectName, 1), projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 22:30:51 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData(true)]
|
|
|
|
|
[InlineData(false)]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesAllProjectsInGivenDirectory(bool skipRefs)
|
2016-09-26 21:16:17 +00:00
|
|
|
|
{
|
2016-09-26 22:30:51 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"MigrateDirectory.SkipRefs.{skipRefs}").Path;
|
2016-09-26 21:16:17 +00:00
|
|
|
|
|
2016-09-26 22:30:51 +00:00
|
|
|
|
if (skipRefs)
|
|
|
|
|
{
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(new [] { projectDirectory, "--skip-project-references" });
|
2016-09-26 22:30:51 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(new [] { projectDirectory });
|
2016-09-26 22:30:51 +00:00
|
|
|
|
}
|
2016-09-23 07:30:41 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE", "ProjectF", "ProjectG", "ProjectH", "ProjectI", "ProjectJ" };
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-26 21:16:17 +00:00
|
|
|
|
VerifyMigration(migratedProjects, projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesGivenProjectJson()
|
2016-09-26 21:16:17 +00:00
|
|
|
|
{
|
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").Path;
|
|
|
|
|
|
|
|
|
|
var project = Path.Combine(projectDirectory, "ProjectA", "project.json");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(new [] { project });
|
2016-09-26 21:16:17 +00:00
|
|
|
|
|
|
|
|
|
string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE" };
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-26 21:16:17 +00:00
|
|
|
|
VerifyMigration(migratedProjects, projectDirectory);
|
2016-09-23 07:30:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-03 17:58:32 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
// regression test for https://github.com/dotnet/cli/issues/4269
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesAndBuildsP2PReferences()
|
2016-09-24 00:02:46 +00:00
|
|
|
|
{
|
2016-10-03 17:58:32 +00:00
|
|
|
|
var assetsDir = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").WithLockFiles().Path;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-03 17:58:32 +00:00
|
|
|
|
var projectDirectory = Path.Combine(assetsDir, "ProjectF");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
var restoreDirectories = new string[]
|
|
|
|
|
{
|
|
|
|
|
projectDirectory,
|
|
|
|
|
Path.Combine(assetsDir, "ProjectG")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, "ProjectF", new [] { projectDirectory }, restoreDirectories);
|
2016-10-03 17:58:32 +00:00
|
|
|
|
|
|
|
|
|
var outputsIdentical = outputComparisonData.ProjectJsonBuildOutputs
|
|
|
|
|
.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
|
|
|
|
|
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
2016-09-24 00:02:46 +00:00
|
|
|
|
|
2016-10-03 17:58:32 +00:00
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-03 17:58:32 +00:00
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
2016-09-24 00:02:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("src", "ProjectH")]
|
|
|
|
|
[InlineData("src with spaces", "ProjectJ")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesAndBuildsProjectsInGlobalJson(string path, string projectName)
|
2016-10-04 17:39:55 +00:00
|
|
|
|
{
|
|
|
|
|
var assetsDir = TestAssetsManager.CreateTestInstance(Path.Combine("TestAppDependencyGraph", "ProjectsWithGlobalJson"),
|
|
|
|
|
callingMethod: $"ProjectsWithGlobalJson.{projectName}")
|
|
|
|
|
.WithLockFiles().Path;
|
|
|
|
|
var globalJson = Path.Combine(assetsDir, "global.json");
|
|
|
|
|
|
|
|
|
|
var restoreDirectories = new string[]
|
|
|
|
|
{
|
|
|
|
|
Path.Combine(assetsDir, "src", "ProjectH"),
|
|
|
|
|
Path.Combine(assetsDir, "src", "ProjectI"),
|
|
|
|
|
Path.Combine(assetsDir, "src with spaces", "ProjectJ")
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var projectDirectory = Path.Combine(assetsDir, path, projectName);
|
|
|
|
|
|
|
|
|
|
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory,
|
|
|
|
|
projectName,
|
|
|
|
|
new [] { globalJson },
|
|
|
|
|
restoreDirectories);
|
|
|
|
|
|
|
|
|
|
var outputsIdentical = outputComparisonData.ProjectJsonBuildOutputs
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
2016-10-04 17:39:55 +00:00
|
|
|
|
|
|
|
|
|
if (!outputsIdentical)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(outputComparisonData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
outputsIdentical.Should().BeTrue();
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
|
|
|
|
}
|
2016-10-11 01:01:59 +00:00
|
|
|
|
|
|
|
|
|
[Theory]
|
2016-10-11 18:19:04 +00:00
|
|
|
|
[InlineData(true)]
|
|
|
|
|
[InlineData(false)]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void MigrationOutputsErrorWhenNoProjectsFound(bool useGlobalJson)
|
2016-10-11 01:01:59 +00:00
|
|
|
|
{
|
2016-10-11 18:19:04 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestDirectory("Migration_outputs_error_when_no_projects_found");
|
|
|
|
|
|
|
|
|
|
string argstr = string.Empty;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-11 18:19:04 +00:00
|
|
|
|
string errorMessage = string.Empty;
|
2016-10-04 17:39:55 +00:00
|
|
|
|
|
2016-10-11 01:01:59 +00:00
|
|
|
|
if (useGlobalJson)
|
|
|
|
|
{
|
2016-10-11 18:19:04 +00:00
|
|
|
|
var globalJsonPath = Path.Combine(projectDirectory.Path, "global.json");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-11 18:19:04 +00:00
|
|
|
|
using (FileStream fs = File.Create(globalJsonPath))
|
|
|
|
|
{
|
|
|
|
|
using (StreamWriter sw = new StreamWriter(fs))
|
|
|
|
|
{
|
|
|
|
|
sw.WriteLine("{");
|
|
|
|
|
sw.WriteLine("\"projects\": [ \".\" ]");
|
|
|
|
|
sw.WriteLine("}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
argstr = globalJsonPath;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-11 18:19:04 +00:00
|
|
|
|
errorMessage = "Unable to find any projects in global.json";
|
2016-10-11 01:01:59 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-11 18:19:04 +00:00
|
|
|
|
argstr = projectDirectory.Path;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-11 18:19:04 +00:00
|
|
|
|
errorMessage = $"No project.json file found in '{projectDirectory.Path}'";
|
2016-10-11 01:01:59 +00:00
|
|
|
|
}
|
2016-10-11 18:19:04 +00:00
|
|
|
|
|
|
|
|
|
var result = new TestCommand("dotnet")
|
|
|
|
|
.WithWorkingDirectory(projectDirectory.Path)
|
|
|
|
|
.ExecuteWithCapturedOutput($"migrate {argstr}");
|
|
|
|
|
|
|
|
|
|
// Expecting an error exit code.
|
|
|
|
|
result.ExitCode.Should().Be(1);
|
|
|
|
|
|
|
|
|
|
// Verify the error messages. Note that debug builds also show the call stack, so we search
|
|
|
|
|
// for the error strings that should be present (rather than an exact match).
|
|
|
|
|
result.StdErr.Should().Contain(errorMessage);
|
|
|
|
|
result.StdErr.Should().Contain("Migration failed.");
|
2016-10-11 01:01:59 +00:00
|
|
|
|
}
|
2016-10-18 01:02:10 +00:00
|
|
|
|
|
2016-10-26 22:23:40 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesAndPublishesProjectsWithRuntimes()
|
2016-10-26 22:23:40 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var projectName = "PJTestAppSimple";
|
2016-10-29 08:58:37 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager
|
|
|
|
|
.CreateTestInstance(projectName)
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.Path;
|
2016-10-26 22:23:40 +00:00
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
|
|
|
|
|
PublishMSBuild(projectDirectory, projectName, "win7-x64");
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-18 01:02:10 +00:00
|
|
|
|
[WindowsOnlyTheory]
|
|
|
|
|
[InlineData("DesktopTestProjects", "AutoAddDesktopReferencesDuringMigrate", true)]
|
2016-10-28 01:46:43 +00:00
|
|
|
|
[InlineData("TestProjects", "PJTestAppSimple", false)]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItAutoAddDesktopReferencesDuringMigrate(string testGroup, string projectName, bool isDesktopApp)
|
2016-10-18 01:02:10 +00:00
|
|
|
|
{
|
2016-10-31 23:22:10 +00:00
|
|
|
|
var runtime = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-18 01:02:10 +00:00
|
|
|
|
var testAssetManager = GetTestGroupTestAssetsManager(testGroup);
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var projectDirectory = testAssetManager.CreateTestInstance(projectName).WithLockFiles().Path;
|
2016-10-18 01:02:10 +00:00
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
MigrateProject(new string[] { projectDirectory });
|
2016-10-31 23:22:10 +00:00
|
|
|
|
Restore(projectDirectory, runtime: runtime);
|
|
|
|
|
BuildMSBuild(projectDirectory, projectName, runtime:runtime);
|
2016-10-18 01:02:10 +00:00
|
|
|
|
VerifyAutoInjectedDesktopReferences(projectDirectory, projectName, isDesktopApp);
|
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:10:12 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItBuildsAMigratedAppWithAnIndirectDependency()
|
2016-10-28 01:10:12 +00:00
|
|
|
|
{
|
|
|
|
|
const string projectName = "ProjectA";
|
|
|
|
|
var solutionDirectory =
|
2016-12-20 22:19:37 +00:00
|
|
|
|
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").Path;
|
2016-10-28 01:10:12 +00:00
|
|
|
|
var projectDirectory = Path.Combine(solutionDirectory, projectName);
|
|
|
|
|
|
|
|
|
|
MigrateProject(new string[] { projectDirectory });
|
2016-10-28 03:56:36 +00:00
|
|
|
|
Restore(projectDirectory);
|
2016-10-28 01:10:12 +00:00
|
|
|
|
BuildMSBuild(projectDirectory, projectName);
|
|
|
|
|
|
|
|
|
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 00:27:07 +00:00
|
|
|
|
[Fact]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesProjectWithOutputName()
|
2016-10-29 00:27:07 +00:00
|
|
|
|
{
|
|
|
|
|
string projectName = "AppWithOutputAssemblyName";
|
|
|
|
|
string expectedOutputName = "MyApp";
|
|
|
|
|
|
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, callingMethod: $"It_migrates_{projectName}")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.Path;
|
|
|
|
|
|
|
|
|
|
string expectedCsprojPath = Path.Combine(projectDirectory, $"{projectName}.csproj");
|
|
|
|
|
if (File.Exists(expectedCsprojPath))
|
|
|
|
|
{
|
|
|
|
|
File.Delete(expectedCsprojPath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
MigrateProject(projectDirectory);
|
|
|
|
|
File.Exists(expectedCsprojPath).Should().BeTrue();
|
|
|
|
|
Restore(projectDirectory, projectName);
|
|
|
|
|
BuildMSBuild(projectDirectory, projectName);
|
2016-12-10 00:10:16 +00:00
|
|
|
|
Directory.EnumerateFiles(
|
|
|
|
|
Path.Combine(projectDirectory, "bin"),
|
|
|
|
|
$"{expectedOutputName}.pdb",
|
|
|
|
|
SearchOption.AllDirectories)
|
|
|
|
|
.Count().Should().Be(1);
|
|
|
|
|
|
|
|
|
|
PackMSBuild(projectDirectory, projectName);
|
|
|
|
|
Directory.EnumerateFiles(
|
|
|
|
|
Path.Combine(projectDirectory, "bin"),
|
|
|
|
|
$"{projectName}.1.0.0.nupkg",
|
|
|
|
|
SearchOption.AllDirectories)
|
2016-10-29 00:27:07 +00:00
|
|
|
|
.Count().Should().Be(1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:34:37 +00:00
|
|
|
|
[Theory]
|
|
|
|
|
[InlineData("LibraryWithoutNetStandardLibRef")]
|
|
|
|
|
[InlineData("LibraryWithNetStandardLibRef")]
|
2016-12-09 08:30:02 +00:00
|
|
|
|
public void ItMigratesAndBuildsLibrary(string projectName)
|
2016-10-31 23:34:37 +00:00
|
|
|
|
{
|
2016-12-21 02:17:36 +00:00
|
|
|
|
var projectDirectory = TestAssetsManager.CreateTestInstance(
|
|
|
|
|
projectName,
|
|
|
|
|
identifier: $"{projectName}").Path;
|
2016-10-31 23:34:37 +00:00
|
|
|
|
|
|
|
|
|
MigrateProject(projectDirectory);
|
|
|
|
|
Restore(projectDirectory, projectName);
|
|
|
|
|
BuildMSBuild(projectDirectory, projectName);
|
|
|
|
|
}
|
2016-12-28 22:48:38 +00:00
|
|
|
|
|
2016-10-18 01:02:10 +00:00
|
|
|
|
private void VerifyAutoInjectedDesktopReferences(string projectDirectory, string projectName, bool shouldBePresent)
|
|
|
|
|
{
|
|
|
|
|
if (projectName != null)
|
|
|
|
|
{
|
|
|
|
|
projectName = projectName + ".csproj";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var root = ProjectRootElement.Open(Path.Combine(projectDirectory, projectName));
|
|
|
|
|
var autoInjectedReferences = root.Items.Where(i => i.ItemType == "Reference" && (i.Include == "System" || i.Include == "Microsoft.CSharp"));
|
|
|
|
|
if (shouldBePresent)
|
|
|
|
|
{
|
|
|
|
|
autoInjectedReferences.Should().HaveCount(2);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
autoInjectedReferences.Should().BeEmpty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-11 01:01:59 +00:00
|
|
|
|
private void VerifyMigration(IEnumerable<string> expectedProjects, string rootDir)
|
2016-09-26 21:16:17 +00:00
|
|
|
|
{
|
2016-10-29 08:58:37 +00:00
|
|
|
|
var migratedProjects = Directory.EnumerateFiles(rootDir, "*.csproj", SearchOption.AllDirectories)
|
2016-10-05 23:25:04 +00:00
|
|
|
|
.Where(s => Directory.EnumerateFiles(Path.GetDirectoryName(s), "*.csproj").Count() == 1)
|
|
|
|
|
.Where(s => Path.GetFileName(Path.GetDirectoryName(s)).Contains("Project"))
|
|
|
|
|
.Select(s => Path.GetFileName(Path.GetDirectoryName(s)));
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-26 21:16:17 +00:00
|
|
|
|
migratedProjects.Should().BeEquivalentTo(expectedProjects);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-14 07:06:35 +00:00
|
|
|
|
private MigratedBuildComparisonData GetComparisonData(string projectDirectory)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-09-03 00:59:13 +00:00
|
|
|
|
File.Copy("NuGet.tempaspnetpatch.config", Path.Combine(projectDirectory, "NuGet.Config"));
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
RestoreProjectJson(projectDirectory);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
2016-09-28 02:25:13 +00:00
|
|
|
|
var outputComparisonData =
|
2016-10-04 17:39:55 +00:00
|
|
|
|
BuildProjectJsonMigrateBuildMSBuild(projectDirectory, Path.GetFileNameWithoutExtension(projectDirectory));
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
return outputComparisonData;
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
private void VerifyAllMSBuildOutputsRunnable(string projectDirectory)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
|
|
|
|
var dllFileName = Path.GetFileName(projectDirectory) + ".dll";
|
|
|
|
|
|
|
|
|
|
var runnableDlls = Directory.EnumerateFiles(Path.Combine(projectDirectory, "bin"), dllFileName,
|
|
|
|
|
SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
foreach (var dll in runnableDlls)
|
|
|
|
|
{
|
2016-10-04 17:39:55 +00:00
|
|
|
|
new TestCommand("dotnet").ExecuteWithCapturedOutput($"\"{dll}\"").Should().Pass();
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
private void VerifyAllMSBuildOutputsAreSigned(string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var dllFileName = Path.GetFileName(projectDirectory) + ".dll";
|
|
|
|
|
|
|
|
|
|
var runnableDlls = Directory.EnumerateFiles(Path.Combine(projectDirectory, "bin"), dllFileName,
|
|
|
|
|
SearchOption.AllDirectories);
|
|
|
|
|
|
|
|
|
|
foreach (var dll in runnableDlls)
|
|
|
|
|
{
|
|
|
|
|
var assemblyName = AssemblyLoadContext.GetAssemblyName(dll);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
var token = assemblyName.GetPublicKeyToken();
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-04 23:48:14 +00:00
|
|
|
|
token.Should().NotBeNullOrEmpty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory,
|
|
|
|
|
string projectName)
|
|
|
|
|
{
|
2016-10-14 07:06:35 +00:00
|
|
|
|
return BuildProjectJsonMigrateBuildMSBuild(projectDirectory,
|
|
|
|
|
projectName,
|
|
|
|
|
new [] { projectDirectory },
|
|
|
|
|
new [] { projectDirectory });
|
2016-10-04 17:39:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory,
|
|
|
|
|
string projectName,
|
|
|
|
|
string[] migrateArgs,
|
|
|
|
|
string[] restoreDirectories)
|
2016-08-23 20:50:05 +00:00
|
|
|
|
{
|
|
|
|
|
BuildProjectJson(projectDirectory);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
CleanBinObj(projectDirectory);
|
|
|
|
|
|
2016-09-22 04:23:50 +00:00
|
|
|
|
// Remove lock file for migration
|
2016-10-04 17:39:55 +00:00
|
|
|
|
foreach(var dir in restoreDirectories)
|
|
|
|
|
{
|
|
|
|
|
File.Delete(Path.Combine(dir, "project.lock.json"));
|
|
|
|
|
}
|
2016-09-27 04:40:11 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
MigrateProject(migrateArgs);
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-27 04:40:11 +00:00
|
|
|
|
DeleteXproj(projectDirectory);
|
2016-10-03 17:58:32 +00:00
|
|
|
|
|
2016-10-04 17:39:55 +00:00
|
|
|
|
foreach(var dir in restoreDirectories)
|
2016-10-03 17:58:32 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
Restore(dir);
|
2016-10-03 17:58:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 03:10:09 +00:00
|
|
|
|
BuildMSBuild(projectDirectory, projectName);
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
|
|
|
|
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
|
|
|
|
|
|
|
|
|
|
return new MigratedBuildComparisonData(projectJsonBuildOutputs, msbuildBuildOutputs);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
private IEnumerable<string> CollectBuildOutputs(string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var fullBinPath = Path.GetFullPath(Path.Combine(projectDirectory, "bin"));
|
|
|
|
|
|
|
|
|
|
return Directory.EnumerateFiles(fullBinPath, "*", SearchOption.AllDirectories)
|
|
|
|
|
.Select(p => Path.GetFullPath(p).Substring(fullBinPath.Length));
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-14 22:26:03 +00:00
|
|
|
|
private static void DeleteDirectory(string dir)
|
|
|
|
|
{
|
|
|
|
|
foreach (string directory in Directory.EnumerateDirectories(dir))
|
|
|
|
|
{
|
|
|
|
|
DeleteDirectory(directory);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// retry, if still doesn't delete then throw
|
|
|
|
|
Directory.Delete(dir, true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
private void CleanBinObj(string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var dirs = new string[] { Path.Combine(projectDirectory, "bin"), Path.Combine(projectDirectory, "obj") };
|
|
|
|
|
|
|
|
|
|
foreach (var dir in dirs)
|
|
|
|
|
{
|
2016-09-29 20:05:27 +00:00
|
|
|
|
if(Directory.Exists(dir))
|
|
|
|
|
{
|
2016-11-14 22:26:03 +00:00
|
|
|
|
DeleteDirectory(dir);
|
2016-09-29 20:05:27 +00:00
|
|
|
|
}
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void BuildProjectJson(string projectDirectory)
|
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
Console.WriteLine(projectDirectory);
|
|
|
|
|
var projectFile = "\"" + Path.Combine(projectDirectory, "project.json") + "\"";
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var result = new BuildPJCommand()
|
|
|
|
|
.WithCapturedOutput()
|
2016-12-20 22:19:37 +00:00
|
|
|
|
.WithForwardingToConsole()
|
2016-10-28 01:46:43 +00:00
|
|
|
|
.Execute(projectFile);
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-29 00:27:07 +00:00
|
|
|
|
private void MigrateProject(params string[] migrateArgs)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-12-20 22:19:37 +00:00
|
|
|
|
new TestCommand("dotnet")
|
|
|
|
|
.WithForwardingToConsole()
|
|
|
|
|
.Execute($"migrate {string.Join(" ", migrateArgs)}")
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
2016-08-23 20:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
private void RestoreProjectJson(string projectDirectory)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2017-01-07 00:28:04 +00:00
|
|
|
|
var projectFile = "\"" + Path.Combine(projectDirectory, "project.json") + "\"";
|
|
|
|
|
new RestoreProjectJsonCommand()
|
|
|
|
|
.Execute(projectFile)
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.Should().Pass();
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:22:10 +00:00
|
|
|
|
private void Restore(string projectDirectory, string projectName=null, string runtime=null)
|
2016-09-28 02:25:13 +00:00
|
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var command = new RestoreCommand()
|
2016-10-31 23:22:10 +00:00
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.WithRuntime(runtime);
|
2016-10-04 03:10:09 +00:00
|
|
|
|
|
|
|
|
|
if (projectName != null)
|
|
|
|
|
{
|
2016-12-07 21:49:15 +00:00
|
|
|
|
if (!Path.HasExtension(projectName))
|
|
|
|
|
{
|
|
|
|
|
projectName += ".csproj";
|
|
|
|
|
}
|
|
|
|
|
command.Execute($"{projectName} /p:SkipInvalidConfigurations=true;_InvalidConfigurationWarning=false")
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.Should().Pass();
|
2016-10-04 03:10:09 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2016-10-20 22:19:35 +00:00
|
|
|
|
command.Execute("/p:SkipInvalidConfigurations=true;_InvalidConfigurationWarning=false")
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.Should().Pass();
|
2016-10-04 17:39:55 +00:00
|
|
|
|
}
|
2016-09-28 02:25:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:22:10 +00:00
|
|
|
|
private string BuildMSBuild(
|
|
|
|
|
string projectDirectory,
|
|
|
|
|
string projectName,
|
|
|
|
|
string configuration="Debug",
|
2017-01-06 06:55:43 +00:00
|
|
|
|
string runtime=null,
|
|
|
|
|
string framework=null)
|
2016-08-22 19:24:10 +00:00
|
|
|
|
{
|
2016-12-07 21:49:15 +00:00
|
|
|
|
if (projectName != null && !Path.HasExtension(projectName))
|
2016-10-04 03:10:09 +00:00
|
|
|
|
{
|
|
|
|
|
projectName = projectName + ".csproj";
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 21:40:46 +00:00
|
|
|
|
DeleteXproj(projectDirectory);
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var result = new BuildCommand()
|
2016-08-22 19:24:10 +00:00
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
2016-10-31 23:22:10 +00:00
|
|
|
|
.WithRuntime(runtime)
|
2017-01-06 06:55:43 +00:00
|
|
|
|
.WithFramework(framework)
|
2016-10-04 03:10:09 +00:00
|
|
|
|
.ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}");
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
2016-08-22 19:24:10 +00:00
|
|
|
|
result
|
2016-10-14 07:06:35 +00:00
|
|
|
|
.Should().Pass();
|
2016-08-22 19:24:10 +00:00
|
|
|
|
|
|
|
|
|
return result.StdOut;
|
|
|
|
|
}
|
2016-08-23 20:50:05 +00:00
|
|
|
|
|
2016-12-10 00:10:16 +00:00
|
|
|
|
private string PublishMSBuild(
|
|
|
|
|
string projectDirectory,
|
|
|
|
|
string projectName,
|
2016-12-12 23:42:20 +00:00
|
|
|
|
string runtime = null,
|
2016-12-10 00:10:16 +00:00
|
|
|
|
string configuration = "Debug")
|
2016-10-26 22:23:40 +00:00
|
|
|
|
{
|
|
|
|
|
if (projectName != null)
|
|
|
|
|
{
|
|
|
|
|
projectName = projectName + ".csproj";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
DeleteXproj(projectDirectory);
|
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
|
var result = new PublishCommand()
|
2016-10-26 22:23:40 +00:00
|
|
|
|
.WithRuntime(runtime)
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}");
|
|
|
|
|
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
return result.StdOut;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-10 00:10:16 +00:00
|
|
|
|
private string PackMSBuild(string projectDirectory, string projectName)
|
|
|
|
|
{
|
|
|
|
|
if (projectName != null && !Path.HasExtension(projectName))
|
|
|
|
|
{
|
|
|
|
|
projectName = projectName + ".csproj";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var result = new PackCommand()
|
|
|
|
|
.WithWorkingDirectory(projectDirectory)
|
|
|
|
|
.ExecuteWithCapturedOutput($"{projectName}");
|
|
|
|
|
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
return result.StdOut;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 21:40:46 +00:00
|
|
|
|
private void DeleteXproj(string projectDirectory)
|
|
|
|
|
{
|
|
|
|
|
var xprojFiles = Directory.EnumerateFiles(projectDirectory, "*.xproj");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-09-08 21:40:46 +00:00
|
|
|
|
foreach (var xprojFile in xprojFiles)
|
|
|
|
|
{
|
|
|
|
|
File.Delete(xprojFile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
private void OutputDiagnostics(MigratedBuildComparisonData comparisonData)
|
|
|
|
|
{
|
|
|
|
|
OutputDiagnostics(comparisonData.MSBuildBuildOutputs, comparisonData.ProjectJsonBuildOutputs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OutputDiagnostics(HashSet<string> msbuildBuildOutputs, HashSet<string> projectJsonBuildOutputs)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Project.json Outputs:");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
Console.WriteLine(string.Join("\n", projectJsonBuildOutputs));
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("");
|
|
|
|
|
|
|
|
|
|
Console.WriteLine("MSBuild Outputs:");
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
Console.WriteLine(string.Join("\n", msbuildBuildOutputs));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class MigratedBuildComparisonData
|
|
|
|
|
{
|
|
|
|
|
public HashSet<string> ProjectJsonBuildOutputs { get; }
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
public HashSet<string> MSBuildBuildOutputs { get; }
|
|
|
|
|
|
|
|
|
|
public MigratedBuildComparisonData(HashSet<string> projectJsonBuildOutputs,
|
|
|
|
|
HashSet<string> msBuildBuildOutputs)
|
|
|
|
|
{
|
|
|
|
|
ProjectJsonBuildOutputs = projectJsonBuildOutputs;
|
2016-10-14 07:06:35 +00:00
|
|
|
|
|
2016-08-23 20:50:05 +00:00
|
|
|
|
MSBuildBuildOutputs = msBuildBuildOutputs;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-20 22:04:53 +00:00
|
|
|
|
|
|
|
|
|
private void WriteGlobalJson(string globalDirectory)
|
|
|
|
|
{
|
|
|
|
|
var file = Path.Combine(globalDirectory, "global.json");
|
|
|
|
|
File.WriteAllText(file, @"
|
|
|
|
|
{
|
|
|
|
|
""projects"": [ ]
|
|
|
|
|
}");
|
|
|
|
|
}
|
2016-08-22 19:24:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|