Merge pull request #4305 from dotnet/sridhar-ms/migrate-p2p-fix
Fix P2P migration and migrate folders in global.json
This commit is contained in:
commit
5c6e3a05fb
41 changed files with 450 additions and 81 deletions
|
@ -0,0 +1,17 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v1.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
|
||||
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
// 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 System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class ProjectC
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from CsprojLibrary1";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Sdk": "1.0.0-alpha-20160923-4",
|
||||
"NETStandard.Library": "1.6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v1.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
|
||||
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
// 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 System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class ProjectC
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from CsprojLibrary2";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Sdk": "1.0.0-alpha-20160923-4",
|
||||
"NETStandard.Library": "1.6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<TargetFrameworkIdentifier>.NETStandard</TargetFrameworkIdentifier>
|
||||
<TargetFrameworkVersion>v1.5</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="**\*.cs" Exclude="$(GlobalExclude)" />
|
||||
<EmbeddedResource Include="**\*.resx" Exclude="$(GlobalExclude)" />
|
||||
<None Include="project.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
// 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 System;
|
||||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class ProjectC
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from CsprojLibrary3";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"dependencies": {},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore.Sdk": "1.0.0-alpha-20160923-4",
|
||||
"NETStandard.Library": "1.6.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ namespace TestApp
|
|||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This string came from ProjectA");
|
||||
return 100;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ClassLibrary1\ClassLibrary1.csproj" />
|
||||
<ProjectReference Include="..\..\ClassLibrary2\ClassLibrary2.csproj" />
|
||||
<ProjectReference Include="..\CsprojLibrary1\CsprojLibrary1.csproj" />
|
||||
<ProjectReference Include="..\CsprojLibrary2\CsprojLibrary2.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -18,10 +18,10 @@
|
|||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"ClassLibrary1": {
|
||||
"CsprojLibrary1": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary2": {
|
||||
"CsprojLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"NETStandard.Library": "1.6.0"
|
|
@ -16,8 +16,8 @@
|
|||
<SchemaVersion>2.0</SchemaVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\ClassLibrary2\ClassLibrary2.csproj" />
|
||||
<ProjectReference Include="..\..\ClassLibrary3\ClassLibrary3.csproj" />
|
||||
<ProjectReference Include="..\CsprojLibrary2\CsprojLibrary2.csproj" />
|
||||
<ProjectReference Include="..\CsprojLibrary3\CsprojLibrary3.csproj" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
</Project>
|
|
@ -10,10 +10,10 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"ClassLibrary2": {
|
||||
"CsprojLibrary2": {
|
||||
"target": "project"
|
||||
},
|
||||
"ClassLibrary3": {
|
||||
"CsprojLibrary3": {
|
||||
"target": "project"
|
||||
},
|
||||
"NETStandard.Library": "1.6.0"
|
|
@ -0,0 +1,19 @@
|
|||
// 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 System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This string came from ProjectF");
|
||||
string helperStr = TestLibrary.ProjectG.GetMessage();
|
||||
Console.WriteLine(helperStr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"dependencies": {
|
||||
"ProjectG": {
|
||||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {}
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@ using System;
|
|||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class ProjectE
|
||||
public static class ProjectG
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
|
||||
{
|
||||
"projects": [ "src", "src with spaces", "src without projects" ]
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// 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 System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This string came from ProjectJ");
|
||||
string helperStr = TestLibrary.ProjectI.GetMessage();
|
||||
Console.WriteLine(helperStr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"dependencies": {
|
||||
"ProjectI": {
|
||||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// 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 System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("This string came from ProjectH");
|
||||
string helperStr = TestLibrary.ProjectI.GetMessage();
|
||||
Console.WriteLine(helperStr);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
"version": "1.0.0-*",
|
||||
"buildOptions": {
|
||||
"emitEntryPoint": true,
|
||||
"preserveCompilationContext": true
|
||||
},
|
||||
"dependencies": {
|
||||
"ProjectI": {
|
||||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"Microsoft.NETCore.App": {
|
||||
"type": "platform",
|
||||
"version": "1.0.1"
|
||||
}
|
||||
},
|
||||
"frameworks": {
|
||||
"netcoreapp1.0": {}
|
||||
}
|
||||
}
|
|
@ -5,11 +5,11 @@ using System;
|
|||
|
||||
namespace TestLibrary
|
||||
{
|
||||
public static class ProjectE
|
||||
public static class ProjectI
|
||||
{
|
||||
public static string GetMessage()
|
||||
{
|
||||
return "This string came from ProjectF";
|
||||
return "This string came from ProjectI";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,10 +10,6 @@
|
|||
]
|
||||
},
|
||||
"dependencies": {
|
||||
"ProjectG": {
|
||||
"target": "project",
|
||||
"version": "1.0.0-*"
|
||||
},
|
||||
"NETStandard.Library": "1.6.0"
|
||||
},
|
||||
"frameworks": {
|
|
@ -23,7 +23,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
ProjectDirectory = projectDirectory;
|
||||
OutputDirectory = outputDirectory;
|
||||
SdkPackageVersion = sdkPackageVersion;
|
||||
MSBuildProjectTemplate = msBuildProjectTemplate;
|
||||
MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null;
|
||||
ProjectXProjFilePath = projectXprojFilePath;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ProjectDependency> ResolveProjectDependenciesForFramework(
|
||||
Project project,
|
||||
NuGetFramework framework,
|
||||
|
@ -70,10 +71,15 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var dependencyName = projectFileDependency.Name;
|
||||
|
||||
ProjectDependency projectDependency;
|
||||
|
||||
if (preResolvedProjects.Contains(dependencyName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!possibleProjectDependencies.TryGetValue(dependencyName, out projectDependency))
|
||||
{
|
||||
if (projectFileDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project
|
||||
&& !preResolvedProjects.Contains(dependencyName))
|
||||
if (projectFileDependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Project)
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1014($"Unresolved project dependency ({dependencyName})").Throw();
|
||||
|
@ -104,10 +110,14 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var projectExportName = projectExport.Library.Identity.Name;
|
||||
ProjectDependency projectDependency;
|
||||
|
||||
if (preResolvedProjects.Contains(projectExportName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!possibleProjectDependencies.TryGetValue(projectExportName, out projectDependency))
|
||||
{
|
||||
if (projectExport.Library.Identity.Type.Equals(LibraryType.Project)
|
||||
&& !preResolvedProjects.Contains(projectExportName))
|
||||
if (projectExport.Library.Identity.Type.Equals(LibraryType.Project))
|
||||
{
|
||||
MigrationErrorCodes
|
||||
.MIGRATE1014($"Unresolved project dependency ({projectExportName})").Throw();
|
||||
|
@ -264,7 +274,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
return projects;
|
||||
}
|
||||
|
||||
private static List<string> GetGlobalPaths(string rootPath)
|
||||
internal static List<string> GetGlobalPaths(string rootPath)
|
||||
{
|
||||
var paths = new List<string>();
|
||||
|
||||
|
@ -347,7 +357,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var projects = settings["projects"];
|
||||
var dependencies = settings["dependencies"] as JObject;
|
||||
|
||||
globalSettings.ProjectPaths = projects == null ? new string[] { } : projects.Select(a => a.Value<string>()).ToArray();;
|
||||
globalSettings.ProjectPaths = projects == null ? new string[] { } :
|
||||
projects.Select(a => a.Value<string>()).ToArray();
|
||||
globalSettings.PackagesPath = settings.Value<string>("packages");
|
||||
globalSettings.FilePath = globalJsonPath;
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
Exception exc = null;
|
||||
IEnumerable<ProjectDependency> projectDependencies = null;
|
||||
|
||||
var tempMSBuildProjectTemplate = rootSettings.MSBuildProjectTemplate.DeepClone();
|
||||
|
||||
try
|
||||
{
|
||||
projectDependencies = ResolveTransitiveClosureProjectDependencies(
|
||||
|
@ -66,7 +68,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
var settings = new MigrationSettings(projectDir,
|
||||
projectDir,
|
||||
rootSettings.SdkPackageVersion,
|
||||
rootSettings.MSBuildProjectTemplate);
|
||||
tempMSBuildProjectTemplate);
|
||||
MigrateProject(settings);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,3 +4,4 @@
|
|||
using System.Runtime.CompilerServices;
|
||||
|
||||
[assembly:InternalsVisibleTo("Microsoft.DotNet.ProjectJsonMigration.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100039ac461fa5c82c7dd2557400c4fd4e9dcdf7ac47e3d572548c04cd4673e004916610f4ea5cbf86f2b1ca1cb824f2a7b3976afecfcf4eb72d9a899aa6786effa10c30399e6580ed848231fec48374e41b3acf8811931343fc2f73acf72dae745adbcb7063cc4b50550618383202875223fc75401351cd89c44bf9b50e7fa3796")]
|
||||
[assembly: InternalsVisibleTo("dotnet, PublicKey=0024000004800000940000000602000000240000525341310004000001000100f33a29044fa9d740c9b3213a93e57c84b472c84e0b8a0e1ae48e67a9f8f6de9d5f7f3d52ac23e48ac51801f1dc950abe901da34d2a9e3baadb141a17c77ef3c565dd5ee5054b91cf63bb3c6ab83f72ab3aafe93d0fc3c2348b764fafb0b1c0733de51459aeab46580384bf9d74c4e28164b7cde247f891ba07891c9d872ad2bb")]
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.DotNet.ProjectJsonMigration;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
|
@ -55,24 +56,35 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
private IEnumerable<string> GetProjectsToMigrate(string projectArg)
|
||||
{
|
||||
if (projectArg.EndsWith(Project.FileName))
|
||||
IEnumerable<string> projects = null;
|
||||
|
||||
if (projectArg.EndsWith(Project.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
yield return GetProjectJsonPath(projectArg);
|
||||
projects = Enumerable.Repeat(projectArg, 1);
|
||||
}
|
||||
else if (projectArg.EndsWith(GlobalSettings.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
projects = GetProjectsFromGlobalJson(projectArg);
|
||||
}
|
||||
else if (Directory.Exists(projectArg))
|
||||
{
|
||||
var projects = Directory.EnumerateFiles(projectArg, Project.FileName, SearchOption.AllDirectories);
|
||||
projects = Directory.EnumerateFiles(projectArg, Project.FileName, SearchOption.AllDirectories);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid project argument - '{projectArg}' is not a project.json or a global.json file and a directory named '{projectArg}' doesn't exist.");
|
||||
}
|
||||
|
||||
if (!projects.Any())
|
||||
{
|
||||
throw new Exception($"Invalid project argument - Unable to find any projects in global.json or directory '{projectArg}'");
|
||||
}
|
||||
|
||||
foreach(var project in projects)
|
||||
{
|
||||
yield return GetProjectJsonPath(project);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"Invalid project argument - '{projectArg}' is not a project.json file and a directory named '{projectArg}' doesn't exist.");
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureNotNull(string variable, string message)
|
||||
{
|
||||
|
@ -93,5 +105,35 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
throw new Exception($"Unable to find project file at {projectJson}");
|
||||
}
|
||||
|
||||
private IEnumerable<string> GetProjectsFromGlobalJson(string globalJson)
|
||||
{
|
||||
if (!File.Exists(globalJson))
|
||||
{
|
||||
throw new Exception($"Unable to find global settings file at {globalJson}");
|
||||
}
|
||||
|
||||
var searchPaths = ProjectDependencyFinder.GetGlobalPaths(Path.GetDirectoryName(globalJson));
|
||||
|
||||
foreach (var searchPath in searchPaths)
|
||||
{
|
||||
var directory = new DirectoryInfo(searchPath);
|
||||
|
||||
if (!directory.Exists)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (var projectDirectory in directory.EnumerateDirectories())
|
||||
{
|
||||
var projectFilePath = Path.Combine(projectDirectory.FullName, "project.json");
|
||||
|
||||
if (File.Exists(projectFilePath))
|
||||
{
|
||||
yield return projectFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,10 +26,15 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
app.HandleResponseFiles = true;
|
||||
app.HelpOption("-h|--help");
|
||||
|
||||
CommandArgument projectArgument = app.Argument("<PROJECT_JSON/PROJECT_DIR>",
|
||||
"The path to project.json file or a directory to migrate." +
|
||||
" If a directory is specified, then it will recursively search for project.json files to migrate." +
|
||||
" Defaults to current directory if nothing is specified.");
|
||||
CommandArgument projectArgument = app.Argument("<PROJECT_JSON/GLOBAL_JSON/PROJECT_DIR>",
|
||||
string.Join(Environment.NewLine,
|
||||
"The path to ",
|
||||
" - a project.json file to migrate.",
|
||||
"or",
|
||||
" - a global.json file, it will migrate the folders specified in global.json.",
|
||||
"or",
|
||||
" - a directory to migrate, it will recursively search for project.json files to migrate.",
|
||||
"Defaults to current directory if nothing is specified."));
|
||||
|
||||
CommandOption template = app.Option("-t|--template-file", "Base MSBuild template to use for migrated app. The default is the project included in dotnet new -t msbuild", CommandOptionType.SingleValue);
|
||||
CommandOption sdkVersion = app.Option("-v|--sdk-package-version", "The version of the sdk package that will be referenced in the migrated app. The default is the version of the sdk in dotnet new -t msbuild", CommandOptionType.SingleValue);
|
||||
|
|
|
@ -153,9 +153,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
var projectDirectory =
|
||||
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"{projectName}.RefsTest").Path;
|
||||
|
||||
FixUpProjectJsons(projectDirectory);
|
||||
|
||||
MigrateProject(Path.Combine(projectDirectory, projectName));
|
||||
MigrateProject(new [] { Path.Combine(projectDirectory, projectName) });
|
||||
|
||||
string[] migratedProjects = expectedProjects.Split(new char[] { ',' });
|
||||
VerifyMigration(migratedProjects, projectDirectory);
|
||||
|
@ -172,9 +170,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
var projectDirectory =
|
||||
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"{projectName}.SkipRefsTest").Path;
|
||||
|
||||
FixUpProjectJsons(projectDirectory);
|
||||
|
||||
MigrateCommand.Run(new [] { Path.Combine(projectDirectory, projectName), "--skip-project-references" }).Should().Be(0);
|
||||
MigrateProject(new [] { Path.Combine(projectDirectory, projectName), "--skip-project-references" });
|
||||
|
||||
VerifyMigration(Enumerable.Repeat(projectName, 1), projectDirectory);
|
||||
}
|
||||
|
@ -186,18 +182,16 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
{
|
||||
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"MigrateDirectory.SkipRefs.{skipRefs}").Path;
|
||||
|
||||
FixUpProjectJsons(projectDirectory);
|
||||
|
||||
if (skipRefs)
|
||||
{
|
||||
MigrateCommand.Run(new [] { projectDirectory, "--skip-project-references" }).Should().Be(0);
|
||||
MigrateProject(new [] { projectDirectory, "--skip-project-references" });
|
||||
}
|
||||
else
|
||||
{
|
||||
MigrateCommand.Run(new [] { projectDirectory }).Should().Be(0);
|
||||
MigrateProject(new [] { projectDirectory });
|
||||
}
|
||||
|
||||
string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE", "ProjectF", "ProjectG" };
|
||||
string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE", "ProjectF", "ProjectG", "ProjectH", "ProjectI", "ProjectJ" };
|
||||
VerifyMigration(migratedProjects, projectDirectory);
|
||||
}
|
||||
|
||||
|
@ -206,30 +200,81 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
{
|
||||
var projectDirectory = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").Path;
|
||||
|
||||
FixUpProjectJsons(projectDirectory);
|
||||
|
||||
var project = Path.Combine(projectDirectory, "ProjectA", "project.json");
|
||||
MigrateCommand.Run(new [] { project }).Should().Be(0);
|
||||
MigrateProject(new [] { project });
|
||||
|
||||
string[] migratedProjects = new string[] { "ProjectA", "ProjectB", "ProjectC", "ProjectD", "ProjectE" };
|
||||
VerifyMigration(migratedProjects, projectDirectory);
|
||||
}
|
||||
|
||||
private void FixUpProjectJsons(string projectDirectory)
|
||||
[Fact]
|
||||
// regression test for https://github.com/dotnet/cli/issues/4269
|
||||
public void It_migrates_and_builds_P2P_references()
|
||||
{
|
||||
var pjs = Directory.EnumerateFiles(projectDirectory, "project.json.1", SearchOption.AllDirectories);
|
||||
var assetsDir = TestAssetsManager.CreateTestInstance("TestAppDependencyGraph").WithLockFiles().Path;
|
||||
var projectDirectory = Path.Combine(assetsDir, "ProjectF");
|
||||
var restoreDirectories = new string[]
|
||||
{
|
||||
projectDirectory,
|
||||
Path.Combine(assetsDir, "ProjectG")
|
||||
};
|
||||
|
||||
foreach(var pj in pjs)
|
||||
var outputComparisonData = BuildProjectJsonMigrateBuildMSBuild(projectDirectory, "ProjectF", new [] { projectDirectory }, restoreDirectories);
|
||||
|
||||
var outputsIdentical = outputComparisonData.ProjectJsonBuildOutputs
|
||||
.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
||||
|
||||
if (!outputsIdentical)
|
||||
{
|
||||
var newPj = pj.Replace("project.json.1", "project.json");
|
||||
File.Move(pj, newPj);
|
||||
OutputDiagnostics(outputComparisonData);
|
||||
}
|
||||
|
||||
outputsIdentical.Should().BeTrue();
|
||||
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData("src", "ProjectH")]
|
||||
[InlineData("src with spaces", "ProjectJ")]
|
||||
public void It_migrates_and_builds_projects_in_global_json(string path, string projectName)
|
||||
{
|
||||
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
|
||||
.SetEquals(outputComparisonData.MSBuildBuildOutputs);
|
||||
|
||||
if (!outputsIdentical)
|
||||
{
|
||||
OutputDiagnostics(outputComparisonData);
|
||||
}
|
||||
|
||||
outputsIdentical.Should().BeTrue();
|
||||
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
||||
}
|
||||
|
||||
private void VerifyMigration(IEnumerable<string> expectedProjects, string rootDir)
|
||||
{
|
||||
var migratedProjects = Directory.EnumerateFiles(rootDir, "*.csproj", SearchOption.AllDirectories)
|
||||
.Select(s => Path.GetFileNameWithoutExtension(s));
|
||||
var migratedProjects = Directory.EnumerateFiles(rootDir, "project.json", SearchOption.AllDirectories)
|
||||
.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)));
|
||||
migratedProjects.Should().BeEquivalentTo(expectedProjects);
|
||||
}
|
||||
|
||||
|
@ -240,7 +285,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
Restore(projectDirectory);
|
||||
|
||||
var outputComparisonData =
|
||||
BuildProjectJsonMigrateBuildMSBuild(projectDirectory);
|
||||
BuildProjectJsonMigrateBuildMSBuild(projectDirectory, Path.GetFileNameWithoutExtension(projectDirectory));
|
||||
return outputComparisonData;
|
||||
}
|
||||
|
||||
|
@ -253,7 +298,7 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
|
||||
foreach (var dll in runnableDlls)
|
||||
{
|
||||
new TestCommand("dotnet").ExecuteWithCapturedOutput(dll).Should().Pass();
|
||||
new TestCommand("dotnet").ExecuteWithCapturedOutput($"\"{dll}\"").Should().Pass();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -272,19 +317,36 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
}
|
||||
}
|
||||
|
||||
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory, string projectName=null)
|
||||
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory,
|
||||
string projectName)
|
||||
{
|
||||
return BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName,
|
||||
new [] { projectDirectory }, new [] { projectDirectory });
|
||||
}
|
||||
|
||||
private MigratedBuildComparisonData BuildProjectJsonMigrateBuildMSBuild(string projectDirectory,
|
||||
string projectName,
|
||||
string[] migrateArgs,
|
||||
string[] restoreDirectories)
|
||||
{
|
||||
BuildProjectJson(projectDirectory);
|
||||
var projectJsonBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
|
||||
CleanBinObj(projectDirectory);
|
||||
|
||||
// Remove lock file for migration
|
||||
File.Delete(Path.Combine(projectDirectory, "project.lock.json"));
|
||||
|
||||
MigrateProject(projectDirectory);
|
||||
foreach(var dir in restoreDirectories)
|
||||
{
|
||||
File.Delete(Path.Combine(dir, "project.lock.json"));
|
||||
}
|
||||
|
||||
MigrateProject(migrateArgs);
|
||||
DeleteXproj(projectDirectory);
|
||||
Restore3(projectDirectory, projectName);
|
||||
|
||||
foreach(var dir in restoreDirectories)
|
||||
{
|
||||
Restore3(dir);
|
||||
}
|
||||
|
||||
BuildMSBuild(projectDirectory, projectName);
|
||||
|
||||
var msbuildBuildOutputs = new HashSet<string>(CollectBuildOutputs(projectDirectory));
|
||||
|
@ -322,10 +384,10 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
result.Should().Pass();
|
||||
}
|
||||
|
||||
private void MigrateProject(string projectDirectory)
|
||||
private void MigrateProject(string[] migrateArgs)
|
||||
{
|
||||
var result =
|
||||
MigrateCommand.Run(new [] { projectDirectory });
|
||||
MigrateCommand.Run(migrateArgs);
|
||||
|
||||
result.Should().Be(0);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue