2016-09-23 16:11:44 +00:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.IO;
|
2017-01-26 18:17:21 +00:00
|
|
|
using System.Diagnostics;
|
|
|
|
using System.Runtime.InteropServices;
|
2016-09-23 16:11:44 +00:00
|
|
|
using FluentAssertions;
|
2016-09-30 22:47:23 +00:00
|
|
|
using Microsoft.DotNet.Cli.Utils;
|
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
2016-09-23 16:11:44 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
using Xunit;
|
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
namespace Microsoft.DotNet.Cli.Publish.Tests
|
2016-09-23 16:11:44 +00:00
|
|
|
{
|
2016-10-28 01:46:43 +00:00
|
|
|
public class GivenDotnetPublishPublishesProjects : TestBase
|
2016-09-23 16:11:44 +00:00
|
|
|
{
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesARunnablePortableApp()
|
|
|
|
{
|
|
|
|
var testAppName = "MSBuildTestApp";
|
2017-02-15 23:35:03 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles();
|
2016-09-23 16:11:44 +00:00
|
|
|
|
2017-02-15 23:35:03 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2016-09-23 16:11:44 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new RestoreCommand()
|
2016-09-27 21:41:06 +00:00
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-28 01:46:43 +00:00
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-27 21:41:06 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new PublishCommand()
|
2016-09-23 16:11:44 +00:00
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-03-02 20:46:21 +00:00
|
|
|
.Execute("--framework netcoreapp2.0")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-23 16:11:44 +00:00
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2017-03-02 20:46:21 +00:00
|
|
|
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, "netcoreapp2.0", "publish", $"{testAppName}.dll");
|
2016-09-23 16:11:44 +00:00
|
|
|
|
2017-03-16 08:31:16 +00:00
|
|
|
new DotnetCommand()
|
2016-09-23 16:11:44 +00:00
|
|
|
.ExecuteWithCapturedOutput(outputDll)
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass()
|
2016-10-28 01:46:43 +00:00
|
|
|
.And.HaveStdOutContaining("Hello World");
|
2016-09-23 16:11:44 +00:00
|
|
|
}
|
2016-09-30 22:47:23 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesARunnableSelfContainedApp()
|
|
|
|
{
|
2016-10-03 14:37:15 +00:00
|
|
|
var testAppName = "MSBuildTestApp";
|
2016-09-30 22:47:23 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
|
|
|
.WithSourceFiles()
|
|
|
|
.WithRestoreFiles();
|
2016-09-30 22:47:23 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
var testProjectDirectory = testInstance.Root;
|
|
|
|
|
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
2016-10-26 22:23:40 +00:00
|
|
|
|
2016-10-28 01:46:43 +00:00
|
|
|
new PublishCommand()
|
2017-03-02 20:46:21 +00:00
|
|
|
.WithFramework("netcoreapp2.0")
|
2016-09-30 22:47:23 +00:00
|
|
|
.WithRuntime(rid)
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2016-10-28 01:46:43 +00:00
|
|
|
//Workaround for https://github.com/dotnet/cli/issues/4501
|
|
|
|
.WithEnvironmentVariable("SkipInvalidConfigurations", "true")
|
|
|
|
.Execute("/p:SkipInvalidConfigurations=true")
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass();
|
2016-09-30 22:47:23 +00:00
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2016-10-28 01:46:43 +00:00
|
|
|
|
|
|
|
var outputProgram = testProjectDirectory
|
2017-03-02 20:46:21 +00:00
|
|
|
.GetDirectory("bin", configuration, "netcoreapp2.0", rid, "publish", $"{testAppName}{Constants.ExeSuffix}")
|
2016-10-28 01:46:43 +00:00
|
|
|
.FullName;
|
2016-09-30 22:47:23 +00:00
|
|
|
|
2017-01-26 18:17:21 +00:00
|
|
|
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
|
|
|
{
|
|
|
|
//Workaround for https://github.com/dotnet/corefx/issues/15516
|
|
|
|
Process.Start("chmod", $"u+x {outputProgram}").WaitForExit();
|
|
|
|
}
|
|
|
|
|
2016-09-30 22:47:23 +00:00
|
|
|
new TestCommand(outputProgram)
|
|
|
|
.ExecuteWithCapturedOutput()
|
2016-10-26 22:23:40 +00:00
|
|
|
.Should().Pass()
|
2016-10-28 01:46:43 +00:00
|
|
|
.And.HaveStdOutContaining("Hello World");
|
2016-09-30 22:47:23 +00:00
|
|
|
}
|
2016-12-18 08:45:25 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesAppWhenRestoringToSpecificPackageDirectory()
|
|
|
|
{
|
2017-02-15 23:35:03 +00:00
|
|
|
var rootPath = TestAssets.CreateTestDirectory().FullName;
|
2016-12-18 08:45:25 +00:00
|
|
|
var rootDir = new DirectoryInfo(rootPath);
|
|
|
|
|
|
|
|
string dir = "pkgs";
|
|
|
|
string args = $"--packages {dir}";
|
|
|
|
|
2017-03-02 20:46:21 +00:00
|
|
|
string newArgs = $"console -o \"{rootPath}\"";
|
2017-02-01 01:31:37 +00:00
|
|
|
new NewCommandShim()
|
2016-12-18 08:45:25 +00:00
|
|
|
.WithWorkingDirectory(rootPath)
|
2017-02-01 01:31:37 +00:00
|
|
|
.Execute(newArgs)
|
2016-12-18 08:45:25 +00:00
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.Execute(args)
|
|
|
|
.Should()
|
|
|
|
.Pass();
|
|
|
|
|
|
|
|
new PublishCommand()
|
|
|
|
.WithWorkingDirectory(rootPath)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
|
|
|
|
|
|
|
var outputProgram = rootDir
|
2017-01-27 23:46:55 +00:00
|
|
|
.GetDirectory("bin", configuration, "netcoreapp2.0", "publish", $"{rootDir.Name}.dll")
|
2016-12-18 08:45:25 +00:00
|
|
|
.FullName;
|
|
|
|
|
|
|
|
new TestCommand(outputProgram)
|
|
|
|
.ExecuteWithCapturedOutput()
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("Hello World");
|
|
|
|
}
|
2016-09-23 16:11:44 +00:00
|
|
|
}
|
|
|
|
}
|