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