Changing the migrate command to obtain the sdk package version from the PackageRef in csproj instead of project.json.

This commit is contained in:
Livar Cunha 2016-09-27 16:11:16 -07:00
parent c41b35f06f
commit c04f7a0cd0
4 changed files with 22 additions and 14 deletions

View file

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.Build.Construction;
using Microsoft.DotNet.Cli;
using Microsoft.DotNet.ProjectJsonMigration;
using Microsoft.DotNet.ProjectModel;
@ -37,8 +36,9 @@ namespace Microsoft.DotNet.Tools.Migrate
var msBuildTemplate = _templateFile != null ?
ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject;
var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
var sdkVersion = _sdkVersion ?? new ProjectJsonParser(_temporaryDotnetNewProject.ProjectJson).SdkPackageVersion;
EnsureNotNull(sdkVersion, "Null Sdk Version");
foreach (var project in projectsToMigrate)

View file

@ -0,0 +1,18 @@
using System.Linq;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration;
namespace Microsoft.DotNet.Tools.Migrate
{
public static class ProjectRootElementExtensions
{
public static string GetSdkVersion(this ProjectRootElement projectRootElement)
{
return projectRootElement
.Items
.Where(i => i.ItemType == "PackageReference")
.First(i=> i.Include == ConstantPackageNames.CSdkPackageName)
.GetMetadataWithName("version").Value;
}
}
}

View file

@ -1,11 +1,8 @@
using Microsoft.Build.Construction;
using Microsoft.DotNet.Cli;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.DotNet.ProjectJsonMigration;
namespace Microsoft.DotNet.Tools.Migrate
@ -17,13 +14,11 @@ namespace Microsoft.DotNet.Tools.Migrate
private readonly string _projectDirectory;
public ProjectRootElement MSBuildProject { get; }
public JObject ProjectJson { get; }
public TemporaryDotnetNewTemplateProject()
{
_projectDirectory = CreateDotnetNewMSBuild(c_temporaryDotnetNewMSBuildProjectName);
MSBuildProject = GetMSBuildProject(_projectDirectory);
ProjectJson = GetProjectJson(_projectDirectory);
Clean();
}
@ -60,12 +55,6 @@ namespace Microsoft.DotNet.Tools.Migrate
return ProjectRootElement.Open(templateProjPath);
}
private JObject GetProjectJson(string temporaryDotnetNewMSBuildDirectory)
{
var projectJsonFile = Path.Combine(temporaryDotnetNewMSBuildDirectory, "project.json");
return JObject.Parse(File.ReadAllText(projectJsonFile));
}
private void RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
{
var command = new DotNetCommandFactory()

View file

@ -12,7 +12,8 @@
"type": "platform",
"version": "1.0.1"
}
}
},
"imports": "dnxcore50"
}
}
}