Handle "runtimes" section (#4503)
* Migrate "runtimes" section as a RuntimeIdentifiers property in the resulting csproj file. Also do not call restore3 from publish3 anymore. * Fix up the publish3 tests to call restore3 first and the csproj files to have RuntimeIdentifiers
This commit is contained in:
parent
4aa1c1bfb4
commit
68afda8e4d
10 changed files with 183 additions and 37 deletions
|
@ -0,0 +1,79 @@
|
|||
using Microsoft.Build.Construction;
|
||||
using Microsoft.DotNet.ProjectJsonMigration;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using NuGet.Frameworks;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.ProjectJsonMigration.Rules;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectJsonMigration.Tests
|
||||
{
|
||||
public class GivenThatIWantToMigrateRuntimes : TestBase
|
||||
{
|
||||
[Fact]
|
||||
public void It_migrates_runtimes()
|
||||
{
|
||||
var projectJson = @"
|
||||
{
|
||||
""runtimes"": {
|
||||
""win7-x64"": { },
|
||||
""win7-x86"": { },
|
||||
""osx.10.10-x64"": { }
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
var migratedProj = TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]
|
||||
{
|
||||
new MigrateRuntimesRule()
|
||||
}, projectJson, testDirectory);
|
||||
|
||||
migratedProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(1);
|
||||
migratedProj.Properties.First(p => p.Name == "RuntimeIdentifiers").Value
|
||||
.Should().Be("win7-x64;win7-x86;osx.10.10-x64");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_has_an_empty_runtime_node_to_migrate()
|
||||
{
|
||||
var projectJson = @"
|
||||
{
|
||||
""runtimes"": {
|
||||
}
|
||||
}
|
||||
";
|
||||
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
var migratedProj = TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]
|
||||
{
|
||||
new MigrateRuntimesRule()
|
||||
}, projectJson, testDirectory);
|
||||
|
||||
migratedProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_has_no_runtimes_to_migrate()
|
||||
{
|
||||
var projectJson = @"
|
||||
{
|
||||
}
|
||||
";
|
||||
|
||||
var testDirectory = Temp.CreateDirectory().Path;
|
||||
var migratedProj = TemporaryProjectFileRuleRunner.RunRules(new IMigrationRule[]
|
||||
{
|
||||
new MigrateRuntimesRule()
|
||||
}, projectJson, testDirectory);
|
||||
|
||||
migratedProj.Properties.Count(p => p.Name == "RuntimeIdentifiers").Should().Be(0);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,13 +29,13 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
public override CommandResult Execute(string args = "")
|
||||
{
|
||||
args = $"publish3 {args} {BuildArgs()}";
|
||||
args = $"publish3 {BuildArgs()} {args} ";
|
||||
return base.Execute(args);
|
||||
}
|
||||
|
||||
public override CommandResult ExecuteWithCapturedOutput(string args = "")
|
||||
{
|
||||
args = $"publish3 {args} {BuildArgs()}";
|
||||
args = $"publish3 {BuildArgs()} {args}";
|
||||
return base.ExecuteWithCapturedOutput(args);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,8 +10,8 @@ using System.IO;
|
|||
using Microsoft.DotNet.Tools.Migrate;
|
||||
using Build3Command = Microsoft.DotNet.Tools.Test.Utilities.Build3Command;
|
||||
using BuildCommand = Microsoft.DotNet.Tools.Test.Utilities.BuildCommand;
|
||||
using Publish3Command = Microsoft.DotNet.Tools.Test.Utilities.Publish3Command;
|
||||
using System.Runtime.Loader;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.Migration.Tests
|
||||
|
@ -346,6 +346,19 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
result.StdErr.Should().Contain("Migration failed.");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void It_migrates_and_publishes_projects_with_runtimes()
|
||||
{
|
||||
var projectName = "TestAppSimple";
|
||||
var projectDirectory = TestAssetsManager.CreateTestInstance(projectName, callingMethod: "i")
|
||||
.WithLockFiles()
|
||||
.Path;
|
||||
|
||||
CleanBinObj(projectDirectory);
|
||||
BuildProjectJsonMigrateBuildMSBuild(projectDirectory, projectName);
|
||||
PublishMSBuild(projectDirectory, projectName, "win7-x64");
|
||||
}
|
||||
|
||||
[WindowsOnlyTheory]
|
||||
[InlineData("DesktopTestProjects", "AutoAddDesktopReferencesDuringMigrate", true)]
|
||||
[InlineData("TestProjects", "TestAppSimple", false)]
|
||||
|
@ -558,6 +571,25 @@ namespace Microsoft.DotNet.Migration.Tests
|
|||
return result.StdOut;
|
||||
}
|
||||
|
||||
private string PublishMSBuild(string projectDirectory, string projectName, string runtime, string configuration = "Debug")
|
||||
{
|
||||
if (projectName != null)
|
||||
{
|
||||
projectName = projectName + ".csproj";
|
||||
}
|
||||
|
||||
DeleteXproj(projectDirectory);
|
||||
|
||||
var result = new Publish3Command()
|
||||
.WithRuntime(runtime)
|
||||
.WithWorkingDirectory(projectDirectory)
|
||||
.ExecuteWithCapturedOutput($"{projectName} /p:Configuration={configuration}");
|
||||
|
||||
result.Should().Pass();
|
||||
|
||||
return result.StdOut;
|
||||
}
|
||||
|
||||
private void DeleteXproj(string projectDirectory)
|
||||
{
|
||||
var xprojFiles = Directory.EnumerateFiles(projectDirectory, "*.xproj");
|
||||
|
|
|
@ -25,24 +25,20 @@ namespace Microsoft.DotNet.Cli.Publish3.Tests
|
|||
new Restore3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
.Should().Pass();
|
||||
|
||||
new Publish3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute("--framework netcoreapp1.0")
|
||||
.Should()
|
||||
.Pass();
|
||||
.Should().Pass();
|
||||
|
||||
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0", "publish", $"{testAppName}.dll");
|
||||
|
||||
new TestCommand("dotnet")
|
||||
.ExecuteWithCapturedOutput(outputDll)
|
||||
.Should()
|
||||
.Pass()
|
||||
.And
|
||||
.HaveStdOutContaining("Hello World");
|
||||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("Hello World");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
|
@ -55,23 +51,25 @@ namespace Microsoft.DotNet.Cli.Publish3.Tests
|
|||
var testProjectDirectory = testInstance.TestRoot;
|
||||
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
||||
|
||||
new Restore3Command()
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should().Pass();
|
||||
|
||||
new Publish3Command()
|
||||
.WithFramework("netcoreapp1.0")
|
||||
.WithRuntime(rid)
|
||||
.WithWorkingDirectory(testProjectDirectory)
|
||||
.Execute()
|
||||
.Should()
|
||||
.Pass();
|
||||
.Should().Pass();
|
||||
|
||||
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
||||
var outputProgram = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp1.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}");
|
||||
|
||||
new TestCommand(outputProgram)
|
||||
.ExecuteWithCapturedOutput()
|
||||
.Should()
|
||||
.Pass()
|
||||
.And
|
||||
.HaveStdOutContaining("Hello World");
|
||||
.Should().Pass()
|
||||
.And.HaveStdOutContaining("Hello World");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue