Changing the migrate command to obtain the sdk package version from the PackageRef in csproj instead of project.json.
This commit is contained in:
parent
c41b35f06f
commit
c04f7a0cd0
4 changed files with 22 additions and 14 deletions
|
@ -5,7 +5,6 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using Microsoft.DotNet.Cli;
|
|
||||||
using Microsoft.DotNet.ProjectJsonMigration;
|
using Microsoft.DotNet.ProjectJsonMigration;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
|
|
||||||
|
@ -37,8 +36,9 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
|
|
||||||
var msBuildTemplate = _templateFile != null ?
|
var msBuildTemplate = _templateFile != null ?
|
||||||
ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject;
|
ProjectRootElement.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject;
|
||||||
|
|
||||||
|
var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||||
|
|
||||||
var sdkVersion = _sdkVersion ?? new ProjectJsonParser(_temporaryDotnetNewProject.ProjectJson).SdkPackageVersion;
|
|
||||||
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
||||||
|
|
||||||
foreach (var project in projectsToMigrate)
|
foreach (var project in projectsToMigrate)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,11 +1,8 @@
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
using Microsoft.DotNet.Cli;
|
using Microsoft.DotNet.Cli;
|
||||||
using Newtonsoft.Json.Linq;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.DotNet.ProjectJsonMigration;
|
using Microsoft.DotNet.ProjectJsonMigration;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Migrate
|
namespace Microsoft.DotNet.Tools.Migrate
|
||||||
|
@ -17,13 +14,11 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
private readonly string _projectDirectory;
|
private readonly string _projectDirectory;
|
||||||
|
|
||||||
public ProjectRootElement MSBuildProject { get; }
|
public ProjectRootElement MSBuildProject { get; }
|
||||||
public JObject ProjectJson { get; }
|
|
||||||
|
|
||||||
public TemporaryDotnetNewTemplateProject()
|
public TemporaryDotnetNewTemplateProject()
|
||||||
{
|
{
|
||||||
_projectDirectory = CreateDotnetNewMSBuild(c_temporaryDotnetNewMSBuildProjectName);
|
_projectDirectory = CreateDotnetNewMSBuild(c_temporaryDotnetNewMSBuildProjectName);
|
||||||
MSBuildProject = GetMSBuildProject(_projectDirectory);
|
MSBuildProject = GetMSBuildProject(_projectDirectory);
|
||||||
ProjectJson = GetProjectJson(_projectDirectory);
|
|
||||||
|
|
||||||
Clean();
|
Clean();
|
||||||
}
|
}
|
||||||
|
@ -60,12 +55,6 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
return ProjectRootElement.Open(templateProjPath);
|
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)
|
private void RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
|
||||||
{
|
{
|
||||||
var command = new DotNetCommandFactory()
|
var command = new DotNetCommandFactory()
|
||||||
|
|
|
@ -12,7 +12,8 @@
|
||||||
"type": "platform",
|
"type": "platform",
|
||||||
"version": "1.0.1"
|
"version": "1.0.1"
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"imports": "dnxcore50"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue