Replacing DeepClone with a call that creates a copy of the project using the template csproj under a new ProjectCollection everytime.
This commit is contained in:
parent
c9f9421b93
commit
9e49ec2723
4 changed files with 72 additions and 19 deletions
|
@ -2,11 +2,14 @@
|
|||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.Build.Evaluation;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration
|
||||
{
|
||||
internal class MigrationSettings
|
||||
{
|
||||
private string _msBuildProjectTemplatePath;
|
||||
|
||||
public string ProjectXProjFilePath { get; }
|
||||
public string ProjectDirectory { get; }
|
||||
public string OutputDirectory { get; }
|
||||
|
@ -20,14 +23,58 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
string sdkPackageVersion,
|
||||
ProjectRootElement msBuildProjectTemplate,
|
||||
string projectXprojFilePath=null,
|
||||
string sdkDefaultsFilePath=null) : this(
|
||||
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath)
|
||||
{
|
||||
MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null;
|
||||
}
|
||||
|
||||
public MigrationSettings(
|
||||
string projectDirectory,
|
||||
string outputDirectory,
|
||||
string sdkPackageVersion,
|
||||
string msBuildProjectTemplatePath,
|
||||
string projectXprojFilePath=null,
|
||||
string sdkDefaultsFilePath=null) : this(
|
||||
projectDirectory, outputDirectory, sdkPackageVersion, projectXprojFilePath, sdkDefaultsFilePath)
|
||||
{
|
||||
_msBuildProjectTemplatePath = msBuildProjectTemplatePath;
|
||||
MSBuildProjectTemplate = ProjectRootElement.Open(
|
||||
_msBuildProjectTemplatePath,
|
||||
new ProjectCollection(),
|
||||
preserveFormatting: true);
|
||||
}
|
||||
|
||||
private MigrationSettings(
|
||||
string projectDirectory,
|
||||
string outputDirectory,
|
||||
string sdkPackageVersion,
|
||||
string projectXprojFilePath=null,
|
||||
string sdkDefaultsFilePath=null)
|
||||
{
|
||||
ProjectDirectory = projectDirectory;
|
||||
OutputDirectory = outputDirectory;
|
||||
SdkPackageVersion = sdkPackageVersion;
|
||||
MSBuildProjectTemplate = msBuildProjectTemplate != null ? msBuildProjectTemplate.DeepClone() : null;
|
||||
ProjectXProjFilePath = projectXprojFilePath;
|
||||
SdkDefaultsFilePath = sdkDefaultsFilePath;
|
||||
}
|
||||
|
||||
public ProjectRootElement CloneMSBuildProjectTemplate()
|
||||
{
|
||||
ProjectRootElement msBuildProjectTemplateClone = null;
|
||||
if(!string.IsNullOrEmpty(_msBuildProjectTemplatePath))
|
||||
{
|
||||
msBuildProjectTemplateClone = ProjectRootElement.Open(
|
||||
_msBuildProjectTemplatePath,
|
||||
new ProjectCollection(),
|
||||
preserveFormatting: true);
|
||||
}
|
||||
else if(MSBuildProjectTemplate != null)
|
||||
{
|
||||
msBuildProjectTemplateClone = MSBuildProjectTemplate.DeepClone();
|
||||
}
|
||||
|
||||
return msBuildProjectTemplateClone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
MigrationRuleInputs rootInputs = ComputeMigrationRuleInputs(rootSettings);
|
||||
IEnumerable<ProjectDependency> projectDependencies = null;
|
||||
|
||||
var tempMSBuildProjectTemplate = rootSettings.MSBuildProjectTemplate.DeepClone();
|
||||
var tempMSBuildProjectTemplate = rootSettings.CloneMSBuildProjectTemplate();
|
||||
|
||||
try
|
||||
{
|
||||
|
|
|
@ -24,8 +24,6 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
private readonly string _reportFile;
|
||||
private readonly bool _reportFormatJson;
|
||||
|
||||
private readonly TemporaryDotnetNewTemplateProject _temporaryDotnetNewProject;
|
||||
|
||||
public MigrateCommand(
|
||||
string templateFile,
|
||||
string projectArg,
|
||||
|
@ -40,21 +38,18 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
_sdkVersion = sdkVersion;
|
||||
_xprojFilePath = xprojFilePath;
|
||||
_skipProjectReferences = skipProjectReferences;
|
||||
_temporaryDotnetNewProject = new TemporaryDotnetNewTemplateProject();
|
||||
_reportFile = reportFile;
|
||||
_reportFormatJson = reportFormatJson;
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
{
|
||||
var temporaryDotnetNewProject = new TemporaryDotnetNewTemplateProject();
|
||||
var projectsToMigrate = GetProjectsToMigrate(_projectArg);
|
||||
|
||||
var msBuildTemplate = _templateFile != null ?
|
||||
ProjectRootElement.Open(_templateFile,
|
||||
ProjectCollection.GlobalProjectCollection,
|
||||
preserveFormatting: true) : _temporaryDotnetNewProject.MSBuildProject;
|
||||
var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath;
|
||||
|
||||
var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||
var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||
|
||||
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
||||
|
||||
|
@ -64,7 +59,12 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
{
|
||||
var projectDirectory = Path.GetDirectoryName(project);
|
||||
var outputDirectory = projectDirectory;
|
||||
var migrationSettings = new MigrationSettings(projectDirectory, outputDirectory, sdkVersion, msBuildTemplate, _xprojFilePath);
|
||||
var migrationSettings = new MigrationSettings(
|
||||
projectDirectory,
|
||||
outputDirectory,
|
||||
sdkVersion,
|
||||
msBuildTemplatePath,
|
||||
_xprojFilePath);
|
||||
var projectMigrationReport = new ProjectMigrator().Migrate(migrationSettings, _skipProjectReferences);
|
||||
|
||||
if (migrationReport == null)
|
||||
|
@ -79,6 +79,8 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
WriteReport(migrationReport);
|
||||
|
||||
temporaryDotnetNewProject.Clean();
|
||||
|
||||
return migrationReport.FailedProjectsCount;
|
||||
}
|
||||
|
||||
|
|
|
@ -16,12 +16,18 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
public ProjectRootElement MSBuildProject { get; }
|
||||
|
||||
public string MSBuildProjectPath
|
||||
{
|
||||
get
|
||||
{
|
||||
return Path.Combine(_projectDirectory, c_temporaryDotnetNewMSBuildProjectName + ".csproj");
|
||||
}
|
||||
}
|
||||
|
||||
public TemporaryDotnetNewTemplateProject()
|
||||
{
|
||||
_projectDirectory = CreateDotnetNewMSBuild(c_temporaryDotnetNewMSBuildProjectName);
|
||||
MSBuildProject = GetMSBuildProject(_projectDirectory);
|
||||
|
||||
Clean();
|
||||
MSBuildProject = GetMSBuildProject();
|
||||
}
|
||||
|
||||
public void Clean()
|
||||
|
@ -48,12 +54,10 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
return tempDir;
|
||||
}
|
||||
|
||||
private ProjectRootElement GetMSBuildProject(string temporaryDotnetNewMSBuildDirectory)
|
||||
private ProjectRootElement GetMSBuildProject()
|
||||
{
|
||||
var templateProjPath = Path.Combine(temporaryDotnetNewMSBuildDirectory,
|
||||
c_temporaryDotnetNewMSBuildProjectName + ".csproj");
|
||||
|
||||
return ProjectRootElement.Open(templateProjPath,
|
||||
return ProjectRootElement.Open(
|
||||
MSBuildProjectPath,
|
||||
ProjectCollection.GlobalProjectCollection,
|
||||
preserveFormatting: true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue