Add xproj tests to test migrate command.

This commit is contained in:
Sridhar Periyasamy 2016-09-23 17:02:46 -07:00
parent d43ade9629
commit ec7aa87576
10 changed files with 78 additions and 2 deletions

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>084222f1-7909-48f4-81e8-a97398b26b1c</ProjectGuid>
<RootNamespace>ProjectC</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">bin</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\ClassLibrary1\ClassLibrary1.csproj" />
<ProjectReference Include="..\..\ClassLibrary2\ClassLibrary2.csproj" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -18,6 +18,12 @@
"target": "project",
"version": "1.0.0-*"
},
"ClassLibrary1": {
"target": "project"
},
"ClassLibrary2": {
"target": "project"
},
"NETStandard.Library": "1.6.0"
},
"frameworks": {

View file

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>7fb8f138-ffb0-4eec-af9e-2e6ff9979593</ProjectGuid>
<RootNamespace>ProjectE</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">obj</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">bin</OutputPath>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\ClassLibrary2\ClassLibrary2.csproj" />
<ProjectReference Include="..\..\ClassLibrary3\ClassLibrary3.csproj" />
</ItemGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View file

@ -10,6 +10,12 @@
]
},
"dependencies": {
"ClassLibrary2": {
"target": "project"
},
"ClassLibrary3": {
"target": "project"
},
"NETStandard.Library": "1.6.0"
},
"frameworks": {

View file

@ -10,6 +10,7 @@ using System.IO;
using Newtonsoft.Json.Linq;
using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Common;
namespace Microsoft.DotNet.ProjectJsonMigration
{
@ -77,7 +78,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration
private IEnumerable<string> ResolveXProjProjectDependencyNames(ProjectRootElement xproj)
{
var xprojDependencies = ResolveXProjProjectDependencies(xproj).SelectMany(r => r.Includes());
return new HashSet<string>(xprojDependencies.Select(p => Path.GetFileNameWithoutExtension(p)));
return new HashSet<string>(xprojDependencies.Select(p => Path.GetFileNameWithoutExtension(
PathUtility.GetPathWithDirectorySeparator(p))));
}
internal IEnumerable<ProjectItemElement> ResolveXProjProjectDependencies(ProjectRootElement xproj)

View file

@ -31,7 +31,8 @@ namespace Microsoft.DotNet.ProjectJsonMigration.Rules
_projectDirectory = migrationSettings.ProjectDirectory;
var migratedXProjDependencyPaths = MigrateXProjProjectDependencies(migrationRuleInputs);
var migratedXProjDependencyNames = new HashSet<string>(migratedXProjDependencyPaths.Select(p => Path.GetFileNameWithoutExtension(p)));
var migratedXProjDependencyNames = new HashSet<string>(migratedXProjDependencyPaths.Select(p => Path.GetFileNameWithoutExtension(
PathUtility.GetPathWithDirectorySeparator(p))));
AddPropertyTransformsToCommonPropertyGroup(migrationRuleInputs.CommonPropertyGroup);
MigrateProjectJsonProjectDependencies(

View file

@ -124,6 +124,8 @@ namespace Microsoft.DotNet.Migration.Tests
var projectDirectory =
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"{projectName}.RefsTest").Path;
FixUpProjectJsons(projectDirectory);
MigrateProject(Path.Combine(projectDirectory, projectName));
string[] migratedProjects = expectedProjects.Split(new char[] { ',' });
@ -146,6 +148,8 @@ namespace Microsoft.DotNet.Migration.Tests
var projectDirectory =
TestAssetsManager.CreateTestInstance("TestAppDependencyGraph", callingMethod: $"{projectName}.SkipRefsTest").Path;
FixUpProjectJsons(projectDirectory);
MigrateCommand.Run(new [] { "-p", Path.Combine(projectDirectory, projectName), "--skip-project-references" }).Should().Be(0);
var migratedProjects = Directory.EnumerateFiles(projectDirectory, "*.csproj", SearchOption.AllDirectories);
@ -155,6 +159,17 @@ namespace Microsoft.DotNet.Migration.Tests
migratedProject.Should().Be($"{projectName}.csproj");
}
private void FixUpProjectJsons(string projectDirectory)
{
var pjs = Directory.EnumerateFiles(projectDirectory, "project.json.1", SearchOption.AllDirectories);
foreach(var pj in pjs)
{
var newPj = pj.Replace("project.json.1", "project.json");
File.Move(pj, newPj);
}
}
private MigratedBuildComparisonData GetDotnetNewComparisonData(string projectDirectory, string dotnetNewType)
{
DotnetNew(projectDirectory, dotnetNewType);