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.ProjectModel": "4.0.0-rc-2037",
|
||||
|
||||
"Microsoft.Build": "15.1.319-preview5",
|
||||
"Microsoft.Build.Utilities.Core": "15.1.319-preview5"
|
||||
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||
"Microsoft.Build.Utilities.Core": "15.1.0-preview-000366-00"
|
||||
},
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"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"
|
||||
},
|
||||
"frameworks": {
|
||||
|
|
|
@ -7,9 +7,11 @@ using System.IO;
|
|||
using System.Linq;
|
||||
using System.Text;
|
||||
using Microsoft.Build.Construction;
|
||||
using Microsoft.Build.Evaluation;
|
||||
using Microsoft.DotNet.Cli.Utils;
|
||||
using Microsoft.DotNet.ProjectJsonMigration;
|
||||
using Microsoft.DotNet.Internal.ProjectModel;
|
||||
using ProjectModel = Microsoft.DotNet.Internal.ProjectModel.Project;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Migrate
|
||||
{
|
||||
|
@ -23,8 +25,6 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
private readonly string _reportFile;
|
||||
private readonly bool _reportFormatJson;
|
||||
|
||||
private readonly TemporaryDotnetNewTemplateProject _temporaryDotnetNewProject;
|
||||
|
||||
public MigrateCommand(
|
||||
string templateFile,
|
||||
string projectArg,
|
||||
|
@ -39,19 +39,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.TryOpen(_templateFile) : _temporaryDotnetNewProject.MSBuildProject;
|
||||
var msBuildTemplatePath = _templateFile ?? temporaryDotnetNewProject.MSBuildProjectPath;
|
||||
|
||||
var sdkVersion = _sdkVersion ?? _temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||
var sdkVersion = _sdkVersion ?? temporaryDotnetNewProject.MSBuildProject.GetSdkVersion();
|
||||
|
||||
EnsureNotNull(sdkVersion, "Null Sdk Version");
|
||||
|
||||
|
@ -61,7 +60,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)
|
||||
|
@ -76,6 +80,8 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
|
||||
WriteReport(migrationReport);
|
||||
|
||||
temporaryDotnetNewProject.Clean();
|
||||
|
||||
return migrationReport.FailedProjectsCount;
|
||||
}
|
||||
|
||||
|
@ -188,7 +194,7 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
{
|
||||
IEnumerable<string> projects = null;
|
||||
|
||||
if (projectArg.EndsWith(Project.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
if (projectArg.EndsWith(ProjectModel.FileName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
projects = Enumerable.Repeat(projectArg, 1);
|
||||
}
|
||||
|
@ -202,7 +208,8 @@ namespace Microsoft.DotNet.Tools.Migrate
|
|||
}
|
||||
else if (Directory.Exists(projectArg))
|
||||
{
|
||||
projects = Directory.EnumerateFiles(projectArg, Project.FileName, SearchOption.AllDirectories);
|
||||
projects =
|
||||
Directory.EnumerateFiles(projectArg, ProjectModel.FileName, SearchOption.AllDirectories);
|
||||
if (!projects.Any())
|
||||
{
|
||||
throw new Exception($"No project.json file found in '{projectArg}'");
|
||||
|
|
|
@ -4,6 +4,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using Microsoft.DotNet.ProjectJsonMigration;
|
||||
using Microsoft.Build.Evaluation;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Migrate
|
||||
{
|
||||
|
@ -15,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()
|
||||
|
@ -47,12 +54,12 @@ 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);
|
||||
}
|
||||
|
||||
private void RunCommand(string commandToExecute, IEnumerable<string> args, string workingDirectory)
|
||||
|
|
|
@ -57,7 +57,7 @@
|
|||
"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.DotNet.PlatformAbstractions": "1.0.1-beta-000933"
|
||||
},
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
"tool_nuget": "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",
|
||||
"System.Runtime.Serialization.Xml": "4.1.1",
|
||||
"NuGet.Build.Tasks": "4.0.0-rc-2037",
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
"type": "platform",
|
||||
"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.CodeAnalysis.Build.Tasks": "2.0.0-beta6-60922-08",
|
||||
"Microsoft.Cci": "4.0.0-rc3-24128-00",
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
"xunit": "2.2.0-beta3-build3330",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-350904-49",
|
||||
"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": {
|
||||
"netcoreapp1.0": {
|
||||
|
|
|
@ -41,6 +41,10 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
outputsIdentical.Should().BeTrue();
|
||||
|
||||
VerifyAllMSBuildOutputsRunnable(projectDirectory);
|
||||
|
||||
var outputCsProj = Path.Combine(projectDirectory, projectName + ".csproj");
|
||||
var csproj = File.ReadAllText(outputCsProj);
|
||||
csproj.EndsWith("\n").Should().Be(true);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
"dotnet": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.Build": "15.1.319-preview5",
|
||||
"Microsoft.Build": "15.1.0-preview-000366-00",
|
||||
"xunit": "2.2.0-beta3-build3330",
|
||||
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
|
||||
},
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
"dotnet": {
|
||||
"target": "project"
|
||||
},
|
||||
"Microsoft.Build.Runtime": "15.1.319-preview5"
|
||||
"Microsoft.Build.Runtime": "15.1.0-preview-000366-00"
|
||||
},
|
||||
"imports": ["dnxcore50", "portable-net45+win8"]
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue