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" "include": "testcontentfile2.txt"
}, },
"out/": { "out/": {
"include": ["project.json", "Program.cs"], "include": ["Program.cs"],
"exclude": ["Program.cs"], "exclude": ["Program.cs"],
"includeFiles": ["Program.cs"], "includeFiles": ["Program.cs"],
"excludeFiles": ["Program.cs"] "excludeFiles": ["Program.cs"]

View file

@ -11,7 +11,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
public ProjectDependency(string name, string projectFilePath) public ProjectDependency(string name, string projectFilePath)
{ {
Name = name; 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) private IEnumerable<ProjectDependency> ResolveTransitiveClosureProjectDependencies(string rootProject, string xprojFile)
{ {
HashSet<ProjectDependency> projectsMap = new HashSet<ProjectDependency>(new ProjectDependencyComparer()); HashSet<ProjectDependency> projectsMap = new HashSet<ProjectDependency>(new ProjectDependencyComparer());

View file

@ -6,6 +6,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using Microsoft.Build.Construction; using Microsoft.Build.Construction;
using Microsoft.DotNet.Cli.Utils;
using Microsoft.DotNet.ProjectJsonMigration.Transforms; using Microsoft.DotNet.ProjectJsonMigration.Transforms;
using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Graph;
@ -38,11 +39,13 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var targetFrameworks = project.GetTargetFrameworks(); var targetFrameworks = project.GetTargetFrameworks();
// Inject Sdk dependency // Inject Sdk dependency
PackageDependencyInfoTransform.Transform(new PackageDependencyInfo _transformApplicator.Execute(
{ PackageDependencyInfoTransform.Transform(
Name = ConstantPackageNames.CSdkPackageName, new PackageDependencyInfo
Version = migrationSettings.SdkPackageVersion {
}); Name = ConstantPackageNames.CSdkPackageName,
Version = migrationSettings.SdkPackageVersion
}), migrationRuleInputs.CommonItemGroup);
// Migrate Direct Deps first // Migrate Direct Deps first
MigrateDependencies( MigrateDependencies(
@ -52,15 +55,18 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
project.Dependencies, project.Dependencies,
migrationRuleInputs.ProjectXproj); migrationRuleInputs.ProjectXproj);
MigrationTrace.Instance.WriteLine($"Migrating {targetFrameworks.Count()} target frameworks");
foreach (var targetFramework in targetFrameworks) foreach (var targetFramework in targetFrameworks)
{ {
MigrationTrace.Instance.WriteLine($"Migrating framework {targetFramework.FrameworkName.GetShortFolderName()}");
MigrateImports(migrationRuleInputs.CommonItemGroup, targetFramework); MigrateImports(migrationRuleInputs.CommonItemGroup, targetFramework);
MigrateDependencies( MigrateDependencies(
project, project,
migrationRuleInputs.OutputMSBuildProject, migrationRuleInputs.OutputMSBuildProject,
targetFramework.FrameworkName, targetFramework.FrameworkName,
project.Dependencies, targetFramework.Dependencies,
migrationRuleInputs.ProjectXproj); migrationRuleInputs.ProjectXproj);
} }
} }
@ -104,6 +110,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
foreach (var packageDependency in packageDependencies) foreach (var packageDependency in packageDependencies)
{ {
MigrationTrace.Instance.WriteLine(packageDependency.Name);
AddItemTransform<ProjectLibraryDependency> transform; AddItemTransform<ProjectLibraryDependency> transform;
if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference) if (packageDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference)
@ -124,7 +131,6 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
transform = transform.WithMetadata("PrivateAssets", metadataValue); transform = transform.WithMetadata("PrivateAssets", metadataValue);
} }
// TODO: include/exclude
if (packageDependency.IncludeType != LibraryIncludeFlags.All) if (packageDependency.IncludeType != LibraryIncludeFlags.All)
{ {
var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType); var metadataValue = ReadLibraryIncludeFlags(packageDependency.IncludeType);
@ -210,7 +216,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
"PackageTargetFallback", "PackageTargetFallback",
t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}", t => $"$(PackageTargetFallback);{string.Join(";", t.Imports)}",
t => "", t => "",
t => t.Imports.Any()); t => t.Imports.OrEmptyIfNull().Any());
private class PackageDependencyInfo private class PackageDependencyInfo
{ {

View file

@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
var sourceProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.json"); var sourceProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.json");
var renamedProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.migrated.json"); var renamedProjectFile = Path.Combine(migrationSettings.ProjectDirectory, "project.migrated.json");
File.Move(sourceProjectFile, renamedProjectFile); File.Copy(sourceProjectFile, renamedProjectFile);
sourceProjectFile = renamedProjectFile; sourceProjectFile = renamedProjectFile;
} }
} }

View file

@ -8,14 +8,11 @@ namespace Microsoft.DotNet.Tools.Migrate
{ {
public static string GetSdkVersion(this ProjectRootElement projectRootElement) 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 projectRootElement
return "1.0.0-alpha-20160929-1"; .Items
.Where(i => i.ItemType == "PackageReference")
// return projectRootElement .First(i => i.Include == ConstantPackageNames.CSdkPackageName)
// .Items .GetMetadataWithName("version").Value;
// .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] [Fact]
public void It_migrates_dotnet_new_console_with_identical_outputs() 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 outputComparisonData = GetDotnetNewComparisonData(projectDirectory, "console");
var outputsIdentical = var outputsIdentical =
@ -60,7 +63,7 @@ namespace Microsoft.DotNet.Migration.Tests
VerifyAllMSBuildOutputsRunnable(projectDirectory); 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() public void It_migrates_dotnet_new_web_with_outputs_containing_project_json_outputs()
{ {
var projectDirectory = Temp.CreateDirectory().Path; var projectDirectory = Temp.CreateDirectory().Path;
@ -214,7 +217,7 @@ namespace Microsoft.DotNet.Migration.Tests
Restore(projectDirectory); Restore(projectDirectory);
var outputComparisonData = var outputComparisonData =
BuildProjectJsonMigrateBuildMSBuild(projectDirectory, Path.GetFileNameWithoutExtension(projectDirectory)); BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
return outputComparisonData; 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); BuildProjectJson(projectDirectory);
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory)); var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
@ -243,8 +246,8 @@ namespace Microsoft.DotNet.Migration.Tests
MigrateProject(projectDirectory); MigrateProject(projectDirectory);
DeleteXproj(projectDirectory); DeleteXproj(projectDirectory);
Restore3(projectDirectory); Restore3(projectDirectory, projectName);
BuildMSBuild(projectDirectory); BuildMSBuild(projectDirectory, projectName);
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory)); var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
@ -306,22 +309,37 @@ namespace Microsoft.DotNet.Migration.Tests
.Pass(); .Pass();
} }
private void Restore3(string projectDirectory, string projectName) private void Restore3(string projectDirectory, string projectName=null)
{ {
new Restore3Command() var command = new Restore3Command()
.WithWorkingDirectory(projectDirectory) .WithWorkingDirectory(projectDirectory);
.Execute($"{projectName}.csproj")
if (projectName != null)
{
command.Execute($"{projectName}.csproj")
.Should() .Should()
.Pass(); .Pass();
}
else
{
command.Execute()
.Should()
.Pass();
}
} }
private string BuildMSBuild(string projectDirectory, string projectName, string configuration="Debug") private string BuildMSBuild(string projectDirectory, string projectName, string configuration="Debug")
{ {
if (projectName != null)
{
projectName = projectName + ".csproj";
}
DeleteXproj(projectDirectory); DeleteXproj(projectDirectory);
var result = new Build3Command() var result = new Build3Command()
.WithWorkingDirectory(projectDirectory) .WithWorkingDirectory(projectDirectory)
.ExecuteWithCapturedOutput($"{projectName}.csproj /p:Configuration={configuration}"); .ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}");
result result
.Should() .Should()