This commit is contained in:
Bryan Thornbury 2016-10-03 20:10:09 -07:00
parent bf45ab19ca
commit adff632929
7 changed files with 68 additions and 31 deletions

View file

@ -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"]

View file

@ -11,7 +11,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public ProjectDependency(string name, string projectFilePath)
{
Name = name;
ProjectFilePath = projectFilePath;
ProjectFilePath = System.IO.Path.GetFullPath(projectFilePath);
}
}
}

View file

@ -60,6 +60,22 @@ namespace Microsoft.DotNet.ProjectJsonMigration
}
}
private void DeleteProjectJsons(MigrationSettings rootsettings, IEnumerable<ProjectDependency> projectDependencies)
{
try
{
File.Delete(Path.Combine(rootsettings.ProjectDirectory, "project.json"));
} catch {}
foreach (var projectDependency in projectDependencies)
{
try
{
File.Delete(projectDependency.ProjectFilePath);
} catch { }
}
}
private IEnumerable<ProjectDependency> ResolveTransitiveClosureProjectDependencies(string rootProject, string xprojFile)
{
HashSet<ProjectDependency> projectsMap = new HashSet<ProjectDependency>(new ProjectDependencyComparer());

View file

@ -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
_transformApplicator.Execute(
PackageDependencyInfoTransform.Transform(
new PackageDependencyInfo
{
Name = ConstantPackageNames.CSdkPackageName,
Version = migrationSettings.SdkPackageVersion
});
}), migrationRuleInputs.CommonItemGroup);
// Migrate Direct Deps first
MigrateDependencies(
@ -52,15 +55,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
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<ProjectLibraryDependency> 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
{

View file

@ -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;
}
}

View file

@ -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;
}
}
}

View file

@ -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<string>(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<string>(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()