2017-02-14 01:56:25 +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 FluentAssertions;
|
2017-06-20 20:19:51 +00:00
|
|
|
using Microsoft.DotNet.PlatformAbstractions;
|
|
|
|
using Microsoft.DotNet.TestFramework;
|
2017-02-14 01:56:25 +00:00
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
2017-04-07 19:15:38 +00:00
|
|
|
using System;
|
|
|
|
using System.IO;
|
2017-02-14 01:56:25 +00:00
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Cli.Publish.Tests
|
|
|
|
{
|
2017-06-20 20:19:51 +00:00
|
|
|
public class GivenDotnetStoresAndPublishesProjects : TestBase
|
2017-02-14 01:56:25 +00:00
|
|
|
{
|
|
|
|
private static string _tfm = "netcoreapp2.0";
|
2017-06-20 20:19:51 +00:00
|
|
|
private static string _frameworkVersion = TestAssetInstance.CurrentRuntimeFrameworkVersion;
|
|
|
|
private static string _arch = RuntimeEnvironment.RuntimeArchitecture.ToLowerInvariant();
|
2017-04-07 19:15:38 +00:00
|
|
|
|
2017-02-14 01:56:25 +00:00
|
|
|
[Fact]
|
|
|
|
public void ItPublishesARunnablePortableApp()
|
|
|
|
{
|
|
|
|
var testAppName = "NewtonSoftDependentProject";
|
2017-03-03 22:27:35 +00:00
|
|
|
var profileProjectName = "NewtonsoftProfile";
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
2017-06-20 20:19:51 +00:00
|
|
|
.WithSourceFiles();
|
2017-02-14 01:56:25 +00:00
|
|
|
|
2017-06-20 20:19:51 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2017-02-14 01:56:25 +00:00
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
|
|
|
var localAssemblyCache = Path.Combine(testProjectDirectory, "localAssemblyCache");
|
|
|
|
var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory");
|
2017-03-07 06:57:40 +00:00
|
|
|
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
2017-02-16 00:33:21 +00:00
|
|
|
var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml");
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
2017-04-07 19:15:38 +00:00
|
|
|
new StoreCommand()
|
|
|
|
.WithManifest(profileProject)
|
2017-02-14 01:56:25 +00:00
|
|
|
.WithFramework(_tfm)
|
|
|
|
.WithRuntime(rid)
|
|
|
|
.WithOutput(localAssemblyCache)
|
|
|
|
.WithRuntimeFrameworkVersion(_frameworkVersion)
|
|
|
|
.WithIntermediateWorkingDirectory(intermediateWorkingDirectory)
|
2017-05-19 00:36:28 +00:00
|
|
|
.Execute()
|
2017-02-14 01:56:25 +00:00
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
2017-03-07 06:57:40 +00:00
|
|
|
var profileFilter = Path.Combine(localAssemblyCache, _arch, _tfm, "artifact.xml");
|
2017-03-03 22:27:35 +00:00
|
|
|
|
2017-02-14 01:56:25 +00:00
|
|
|
new PublishCommand()
|
|
|
|
.WithFramework(_tfm)
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-04-07 19:15:38 +00:00
|
|
|
.WithTargetManifest(profileFilter)
|
2017-02-14 01:56:25 +00:00
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
|
|
|
|
|
2017-03-16 08:31:16 +00:00
|
|
|
new DotnetCommand()
|
2017-04-10 23:55:12 +00:00
|
|
|
.WithEnvironmentVariable("DOTNET_SHARED_STORE", localAssemblyCache)
|
2017-02-14 01:56:25 +00:00
|
|
|
.ExecuteWithCapturedOutput(outputDll)
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("{}");
|
|
|
|
}
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void AppFailsDueToMissingCache()
|
|
|
|
{
|
2017-05-02 19:37:29 +00:00
|
|
|
var testAppName = "NuGetConfigDependentProject";
|
|
|
|
var profileProjectName = "NuGetConfigProfile";
|
|
|
|
var targetManifestFileName = "NuGetConfigFilterProfile.xml";
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
2017-06-20 20:19:51 +00:00
|
|
|
.WithSourceFiles();
|
2017-02-14 01:56:25 +00:00
|
|
|
|
2017-06-20 20:19:51 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2017-03-07 06:57:40 +00:00
|
|
|
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
2017-04-14 03:03:01 +00:00
|
|
|
var profileFilter = Path.Combine(profileProjectPath, targetManifestFileName);
|
2017-02-14 01:56:25 +00:00
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
|
|
|
|
|
|
|
new PublishCommand()
|
|
|
|
.WithFramework(_tfm)
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-04-07 19:15:38 +00:00
|
|
|
.WithTargetManifest(profileFilter)
|
2017-02-14 01:56:25 +00:00
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
|
|
|
|
|
2017-03-16 08:31:16 +00:00
|
|
|
new DotnetCommand()
|
2017-02-14 01:56:25 +00:00
|
|
|
.ExecuteWithCapturedOutput(outputDll)
|
|
|
|
.Should().Fail()
|
2017-06-02 14:18:24 +00:00
|
|
|
.And.HaveStdErrContaining($"Error:{Environment.NewLine}" +
|
|
|
|
$" An assembly specified in the application dependencies manifest (NuGetConfigDependentProject.deps.json) was not found:{Environment.NewLine}" +
|
|
|
|
$" package: 'NuGet.Configuration', version: '4.3.0-beta1-2418'{Environment.NewLine}" +
|
|
|
|
" path: 'lib/netstandard1.3/NuGet.Configuration.dll'");
|
2017-02-14 01:56:25 +00:00
|
|
|
}
|
2017-03-07 06:57:40 +00:00
|
|
|
|
|
|
|
[Fact]
|
|
|
|
public void ItPublishesAnAppWithMultipleProfiles()
|
|
|
|
{
|
|
|
|
var testAppName = "MultiDependentProject";
|
|
|
|
var profileProjectName = "NewtonsoftProfile";
|
|
|
|
var profileProjectName1 = "FluentProfile";
|
|
|
|
|
|
|
|
var testInstance = TestAssets.Get(testAppName)
|
|
|
|
.CreateInstance()
|
2017-06-20 20:19:51 +00:00
|
|
|
.WithSourceFiles();
|
2017-03-07 06:57:40 +00:00
|
|
|
|
2017-06-20 20:19:51 +00:00
|
|
|
var testProjectDirectory = testInstance.Root.FullName;
|
2017-03-07 06:57:40 +00:00
|
|
|
var rid = DotnetLegacyRuntimeIdentifiers.InferLegacyRestoreRuntimeIdentifier();
|
|
|
|
var localAssemblyCache = Path.Combine(testProjectDirectory, "lAC");
|
|
|
|
var intermediateWorkingDirectory = Path.Combine(testProjectDirectory, "workingDirectory");
|
|
|
|
|
|
|
|
var profileProjectPath = TestAssets.Get(profileProjectName).Root.FullName;
|
|
|
|
var profileProject = Path.Combine(profileProjectPath, $"{profileProjectName}.xml");
|
|
|
|
var profileFilter = Path.Combine(profileProjectPath, "NewtonsoftFilterProfile.xml");
|
|
|
|
|
|
|
|
var profileProjectPath1 = TestAssets.Get(profileProjectName1).Root.FullName;
|
|
|
|
var profileProject1 = Path.Combine(profileProjectPath1, $"{profileProjectName1}.xml");
|
|
|
|
var profileFilter1 = Path.Combine(profileProjectPath1, "FluentFilterProfile.xml");
|
|
|
|
|
|
|
|
new RestoreCommand()
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
2017-04-07 19:15:38 +00:00
|
|
|
new StoreCommand()
|
|
|
|
.WithManifest(profileProject)
|
|
|
|
.WithManifest(profileProject1)
|
2017-03-07 06:57:40 +00:00
|
|
|
.WithFramework(_tfm)
|
|
|
|
.WithRuntime(rid)
|
|
|
|
.WithOutput(localAssemblyCache)
|
|
|
|
.WithRuntimeFrameworkVersion(_frameworkVersion)
|
|
|
|
.WithIntermediateWorkingDirectory(intermediateWorkingDirectory)
|
2017-05-19 00:36:28 +00:00
|
|
|
.Execute()
|
2017-03-07 06:57:40 +00:00
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var configuration = Environment.GetEnvironmentVariable("CONFIGURATION") ?? "Debug";
|
|
|
|
|
|
|
|
new PublishCommand()
|
|
|
|
.WithFramework(_tfm)
|
|
|
|
.WithWorkingDirectory(testProjectDirectory)
|
2017-04-07 19:15:38 +00:00
|
|
|
.WithTargetManifest(profileFilter)
|
|
|
|
.WithTargetManifest(profileFilter1)
|
2017-03-07 06:57:40 +00:00
|
|
|
.Execute()
|
|
|
|
.Should().Pass();
|
|
|
|
|
|
|
|
var outputDll = Path.Combine(testProjectDirectory, "bin", configuration, _tfm, "publish", $"{testAppName}.dll");
|
|
|
|
|
2017-03-16 08:31:16 +00:00
|
|
|
new DotnetCommand()
|
2017-04-10 23:55:12 +00:00
|
|
|
.WithEnvironmentVariable("DOTNET_SHARED_STORE", localAssemblyCache)
|
2017-03-07 06:57:40 +00:00
|
|
|
.ExecuteWithCapturedOutput(outputDll)
|
|
|
|
.Should().Pass()
|
|
|
|
.And.HaveStdOutContaining("{}");
|
|
|
|
}
|
2017-02-14 01:56:25 +00:00
|
|
|
}
|
|
|
|
}
|