Merge pull request #4519 from livarcocc/whitespace
Adding whitespace to csproj and removing xml node from the beginning of it
This commit is contained in:
commit
be8f2e212e
13 changed files with 93 additions and 28 deletions
|
@ -13,8 +13,8 @@
|
||||||
"NuGet.Frameworks": "4.0.0-rc-2037",
|
"NuGet.Frameworks": "4.0.0-rc-2037",
|
||||||
"NuGet.ProjectModel": "4.0.0-rc-2037",
|
"NuGet.ProjectModel": "4.0.0-rc-2037",
|
||||||
|
|
||||||
"Microsoft.Build": "15.1.319-preview5",
|
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||||
"Microsoft.Build.Utilities.Core": "15.1.319-preview5"
|
"Microsoft.Build.Utilities.Core": "15.1.0-preview-000366-00"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netstandard1.5": {
|
"netstandard1.5": {
|
||||||
|
|
|
@ -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
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"Microsoft.DotNet.Cli.Utils": {
|
"Microsoft.DotNet.Cli.Utils": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"Microsoft.Build": "15.1.319-preview5",
|
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||||
"Microsoft.CodeAnalysis.CSharp": "2.0.0-beta6-60922-08"
|
"Microsoft.CodeAnalysis.CSharp": "2.0.0-beta6-60922-08"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
|
|
|
@ -7,9 +7,11 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using Microsoft.Build.Construction;
|
using Microsoft.Build.Construction;
|
||||||
|
using Microsoft.Build.Evaluation;
|
||||||
using Microsoft.DotNet.Cli.Utils;
|
using Microsoft.DotNet.Cli.Utils;
|
||||||
using Microsoft.DotNet.ProjectJsonMigration;
|
using Microsoft.DotNet.ProjectJsonMigration;
|
||||||
using Microsoft.DotNet.Internal.ProjectModel;
|
using Microsoft.DotNet.Internal.ProjectModel;
|
||||||
|
using ProjectModel = Microsoft.DotNet.Internal.ProjectModel.Project;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Migrate
|
namespace Microsoft.DotNet.Tools.Migrate
|
||||||
{
|
{
|
||||||
|
@ -23,8 +25,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,
|
||||||
|
@ -39,19 +39,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.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject;
|
|
||||||
|
|
||||||
var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||||
|
|
||||||
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
||||||
|
|
||||||
|
@ -61,7 +60,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)
|
||||||
|
@ -76,6 +80,8 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
|
|
||||||
WriteReport(migrationReport);
|
WriteReport(migrationReport);
|
||||||
|
|
||||||
|
temporaryDotnetNewProject.Clean();
|
||||||
|
|
||||||
return migrationReport.FailedProjectsCount;
|
return migrationReport.FailedProjectsCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,7 +194,7 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
{
|
{
|
||||||
IEnumerable<string> projects = null;
|
IEnumerable<string> projects = null;
|
||||||
|
|
||||||
if (projectArg.EndsWith(Project.FileName, StringComparison.OrdinalIgnoreCase))
|
if (projectArg.EndsWith(ProjectModel.FileName, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
projects = Enumerable.Repeat(projectArg, 1);
|
projects = Enumerable.Repeat(projectArg, 1);
|
||||||
}
|
}
|
||||||
|
@ -202,7 +208,8 @@ namespace Microsoft.DotNet.Tools.Migrate
|
||||||
}
|
}
|
||||||
else if (Directory.Exists(projectArg))
|
else if (Directory.Exists(projectArg))
|
||||||
{
|
{
|
||||||
projects = Directory.EnumerateFiles(projectArg, Project.FileName, SearchOption.AllDirectories);
|
projects =
|
||||||
|
Directory.EnumerateFiles(projectArg, ProjectModel.FileName, SearchOption.AllDirectories);
|
||||||
if (!projects.Any())
|
if (!projects.Any())
|
||||||
{
|
{
|
||||||
throw new Exception($"No project.json file found in '{projectArg}'");
|
throw new Exception($"No project.json file found in '{projectArg}'");
|
||||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using Microsoft.DotNet.ProjectJsonMigration;
|
using Microsoft.DotNet.ProjectJsonMigration;
|
||||||
|
using Microsoft.Build.Evaluation;
|
||||||
|
|
||||||
namespace Microsoft.DotNet.Tools.Migrate
|
namespace Microsoft.DotNet.Tools.Migrate
|
||||||
{
|
{
|
||||||
|
@ -15,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()
|
||||||
|
@ -47,12 +54,12 @@ 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,
|
||||||
|
ProjectCollection.GlobalProjectCollection,
|
||||||
return ProjectRootElement.Open(templateProjPath);
|
preserveFormatting: true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
|
private void RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
"exclude": "compile"
|
"exclude": "compile"
|
||||||
},
|
},
|
||||||
|
|
||||||
"Microsoft.Build": "15.1.319-preview5",
|
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||||
"Microsoft.CodeAnalysis.CSharp": "2.0.0-beta6-60922-08",
|
"Microsoft.CodeAnalysis.CSharp": "2.0.0-beta6-60922-08",
|
||||||
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933"
|
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933"
|
||||||
},
|
},
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
"tool_nuget": "1.0.0-preview3-*",
|
"tool_nuget": "1.0.0-preview3-*",
|
||||||
"tool_msbuild": "1.0.0-preview3-*",
|
"tool_msbuild": "1.0.0-preview3-*",
|
||||||
|
|
||||||
"Microsoft.Build.Runtime": "15.1.319-preview5",
|
"Microsoft.Build.Runtime": "15.1.0-preview-000366-00",
|
||||||
"Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
|
"Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
|
||||||
"System.Runtime.Serialization.Xml": "4.1.1",
|
"System.Runtime.Serialization.Xml": "4.1.1",
|
||||||
"NuGet.Build.Tasks": "4.0.0-rc-2037",
|
"NuGet.Build.Tasks": "4.0.0-rc-2037",
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
"type": "platform",
|
"type": "platform",
|
||||||
"version": "1.0.1"
|
"version": "1.0.1"
|
||||||
},
|
},
|
||||||
"Microsoft.Build.Runtime": "15.1.319-preview5",
|
"Microsoft.Build.Runtime": "15.1.0-preview-000366-00",
|
||||||
"Microsoft.Net.Compilers.netcore": "2.0.0-beta6-60922-08",
|
"Microsoft.Net.Compilers.netcore": "2.0.0-beta6-60922-08",
|
||||||
"Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
|
"Microsoft.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
|
||||||
"Microsoft.Cci": "4.0.0-rc3-24128-00",
|
"Microsoft.Cci": "4.0.0-rc3-24128-00",
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
"xunit": "2.2.0-beta3-build3330",
|
"xunit": "2.2.0-beta3-build3330",
|
||||||
"dotnet-test-xunit": "1.0.0-rc2-350904-49",
|
"dotnet-test-xunit": "1.0.0-rc2-350904-49",
|
||||||
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933",
|
"Microsoft.DotNet.PlatformAbstractions": "1.0.1-beta-000933",
|
||||||
"Microsoft.Build.Runtime": "15.1.319-preview5"
|
"Microsoft.Build.Runtime": "15.1.0-preview-000366-00"
|
||||||
},
|
},
|
||||||
"frameworks": {
|
"frameworks": {
|
||||||
"netcoreapp1.0": {
|
"netcoreapp1.0": {
|
||||||
|
|
|
@ -41,6 +41,10 @@ namespace Microsoft.DotNet.Migration.Tests
|
||||||
outputsIdentical.Should().BeTrue();
|
outputsIdentical.Should().BeTrue();
|
||||||
|
|
||||||
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
||||||
|
|
||||||
|
var outputCsProj = Path.Combine(projectDirectory, projectName + ".csproj");
|
||||||
|
var csproj = File.ReadAllText(outputCsProj);
|
||||||
|
csproj.EndsWith("\n").Should().Be(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
"dotnet": {
|
"dotnet": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"Microsoft.Build": "15.1.319-preview5",
|
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||||
"xunit": "2.2.0-beta3-build3330",
|
"xunit": "2.2.0-beta3-build3330",
|
||||||
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
|
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
|
||||||
},
|
},
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
"dotnet": {
|
"dotnet": {
|
||||||
"target": "project"
|
"target": "project"
|
||||||
},
|
},
|
||||||
"Microsoft.Build.Runtime": "15.1.319-preview5"
|
"Microsoft.Build.Runtime": "15.1.0-preview-000366-00"
|
||||||
},
|
},
|
||||||
"imports": ["dnxcore50", "portable-net45+win8"]
|
"imports": ["dnxcore50", "portable-net45+win8"]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue