2016-02-16 18:20:23 +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;
|
2016-02-24 03:07:27 +00:00
|
|
|
|
using System.IO.Compression;
|
2016-06-03 22:46:16 +00:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Xml.Linq;
|
2016-02-18 10:27:35 +00:00
|
|
|
|
using FluentAssertions;
|
|
|
|
|
using Microsoft.DotNet.ProjectModel;
|
2016-02-16 18:20:23 +00:00
|
|
|
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
|
|
|
|
using Xunit;
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|
|
|
|
{
|
|
|
|
|
public class PackTests : TestBase
|
|
|
|
|
{
|
|
|
|
|
private readonly string _testProjectsRoot;
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OutputsPackagesToConfigurationSubdirWhenOutputParameterIsNotPassed()
|
|
|
|
|
{
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("TestLibraryWithConfiguration")
|
|
|
|
|
.WithBuildArtifacts()
|
|
|
|
|
.WithLockFiles();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testProject = Path.Combine(testInstance.Path, "project.json");
|
2016-04-13 00:29:07 +00:00
|
|
|
|
var packCommand = new PackCommand(testProject, configuration: "Test");
|
|
|
|
|
var result = packCommand.Execute();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin", "Test"));
|
2016-02-16 18:20:23 +00:00
|
|
|
|
outputDir.Should().Exist();
|
2016-08-10 06:00:26 +00:00
|
|
|
|
outputDir.Should().HaveFiles(new [] { "TestLibraryWithConfiguration.1.0.0.nupkg" , "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
|
2016-02-16 18:20:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OutputsPackagesFlatIntoOutputDirWhenOutputParameterIsPassed()
|
|
|
|
|
{
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("TestLibraryWithConfiguration")
|
|
|
|
|
.WithBuildArtifacts()
|
|
|
|
|
.WithLockFiles();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testProject = Path.Combine(testInstance.Path, "project.json");
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin2"));
|
2016-04-13 00:29:07 +00:00
|
|
|
|
var packCommand = new PackCommand(testProject, output: outputDir.FullName);
|
|
|
|
|
var result = packCommand.Execute();
|
2016-02-16 18:20:23 +00:00
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
|
|
|
|
outputDir.Should().Exist();
|
2016-08-10 06:00:26 +00:00
|
|
|
|
outputDir.Should().HaveFiles(new[] { "TestLibraryWithConfiguration.1.0.0.nupkg", "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
|
2016-02-16 18:20:23 +00:00
|
|
|
|
}
|
2016-04-07 22:59:25 +00:00
|
|
|
|
|
2016-02-18 10:27:35 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void SettingVersionSuffixFlag_ShouldStampAssemblyInfoInOutputAssemblyAndPackage()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName), versionSuffix: "85");
|
|
|
|
|
cmd.Execute().Should().Pass();
|
|
|
|
|
|
2016-04-13 00:29:07 +00:00
|
|
|
|
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultLibraryFramework, "TestLibraryWithConfiguration.dll");
|
2016-02-18 10:27:35 +00:00
|
|
|
|
var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");
|
2016-04-07 22:59:25 +00:00
|
|
|
|
|
2016-02-18 10:27:35 +00:00
|
|
|
|
informationalVersion.Should().NotBeNull();
|
|
|
|
|
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
|
2016-04-07 22:59:25 +00:00
|
|
|
|
|
2016-02-18 10:27:35 +00:00
|
|
|
|
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "TestLibraryWithConfiguration.1.0.0-85.nupkg");
|
|
|
|
|
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
|
|
|
|
}
|
2016-02-16 18:20:23 +00:00
|
|
|
|
|
2016-02-24 03:07:27 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void HasBuildOutputWhenUsingBuildBasePath()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssetsManager.CreateTestInstance("TestLibraryWithConfiguration")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName), buildBasePath: "buildBase");
|
|
|
|
|
cmd.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "TestLibraryWithConfiguration.1.0.0.nupkg");
|
|
|
|
|
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
|
|
|
|
|
|
|
|
|
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
|
2016-04-13 00:29:07 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/TestLibraryWithConfiguration.dll");
|
2016-02-24 03:07:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 02:25:28 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void HasIncludedFiles()
|
|
|
|
|
{
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("EndToEndTestApp")
|
|
|
|
|
.WithLockFiles()
|
|
|
|
|
.WithBuildArtifacts();
|
2016-04-12 02:25:28 +00:00
|
|
|
|
|
|
|
|
|
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName));
|
|
|
|
|
cmd.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "EndToEndTestApp.1.0.0.nupkg");
|
|
|
|
|
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
|
|
|
|
|
|
|
|
|
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
|
2016-05-04 07:41:01 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "packfiles/pack1.txt");
|
2016-04-12 02:25:28 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "newpath/pack2.txt");
|
2016-07-13 21:56:22 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "anotherpath/pack2.txt");
|
2016-04-12 02:25:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-07 22:59:25 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PackAddsCorrectFilesForProjectsWithOutputNameSpecified()
|
|
|
|
|
{
|
|
|
|
|
var testInstance =
|
|
|
|
|
TestAssetsManager
|
|
|
|
|
.CreateTestInstance("LibraryWithOutputAssemblyName")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
var cmd = new PackCommand(Path.Combine(testInstance.TestRoot, Project.FileName));
|
|
|
|
|
cmd.Execute().Should().Pass();
|
|
|
|
|
|
|
|
|
|
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "LibraryWithOutputAssemblyName.1.0.0.nupkg");
|
|
|
|
|
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
|
|
|
|
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
|
2016-04-13 00:29:07 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll");
|
2016-04-07 22:59:25 +00:00
|
|
|
|
|
|
|
|
|
var symbolsPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "LibraryWithOutputAssemblyName.1.0.0.symbols.nupkg");
|
|
|
|
|
File.Exists(symbolsPackage).Should().BeTrue(symbolsPackage);
|
|
|
|
|
zip = ZipFile.Open(symbolsPackage, ZipArchiveMode.Read);
|
2016-04-13 00:29:07 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.dll");
|
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "lib/netstandard1.5/MyLibrary.pdb");
|
2016-04-07 22:59:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-26 22:22:09 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void PackWorksWithLocalProjectJson()
|
|
|
|
|
{
|
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("TestAppSimple")
|
|
|
|
|
.WithLockFiles();
|
|
|
|
|
|
|
|
|
|
new PackCommand(Project.FileName)
|
|
|
|
|
.WithWorkingDirectory(testInstance.TestRoot)
|
|
|
|
|
.Execute()
|
|
|
|
|
.Should()
|
|
|
|
|
.Pass();
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 22:46:16 +00:00
|
|
|
|
[Fact]
|
|
|
|
|
public void HasServiceableFlagWhenArgumentPassed()
|
|
|
|
|
{
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testInstance = TestAssetsManager
|
|
|
|
|
.CreateTestInstance("TestLibraryWithConfiguration")
|
|
|
|
|
.WithBuildArtifacts()
|
|
|
|
|
.WithLockFiles();
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var testProject = Path.Combine(testInstance.Path, "project.json");
|
2016-06-05 18:52:41 +00:00
|
|
|
|
var packCommand = new PackCommand(testProject, configuration: "Debug", serviceable: true);
|
2016-06-03 22:46:16 +00:00
|
|
|
|
var result = packCommand.Execute();
|
|
|
|
|
result.Should().Pass();
|
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var outputDir = new DirectoryInfo(Path.Combine(testInstance.Path, "bin", "Debug"));
|
2016-06-03 22:46:16 +00:00
|
|
|
|
outputDir.Should().Exist();
|
2016-08-10 06:00:26 +00:00
|
|
|
|
outputDir.Should().HaveFiles(new[] { "TestLibraryWithConfiguration.1.0.0.nupkg", "TestLibraryWithConfiguration.1.0.0.symbols.nupkg" });
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var outputPackage = Path.Combine(outputDir.FullName, "TestLibraryWithConfiguration.1.0.0.nupkg");
|
2016-06-03 22:46:16 +00:00
|
|
|
|
var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read);
|
2016-08-10 06:00:26 +00:00
|
|
|
|
zip.Entries.Should().Contain(e => e.FullName == "TestLibraryWithConfiguration.nuspec");
|
2016-06-03 22:46:16 +00:00
|
|
|
|
|
2016-08-10 06:00:26 +00:00
|
|
|
|
var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibraryWithConfiguration.nuspec").Open());
|
2016-06-03 22:46:16 +00:00
|
|
|
|
var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd());
|
|
|
|
|
var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable");
|
|
|
|
|
Assert.Equal("true", node.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-16 18:20:23 +00:00
|
|
|
|
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
|
|
|
|
{
|
|
|
|
|
// copy all the files to temp dir
|
|
|
|
|
foreach (var file in Directory.EnumerateFiles(projectDir))
|
|
|
|
|
{
|
|
|
|
|
tempDir.CopyFile(file);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetProjectPath(TempDirectory projectDir)
|
|
|
|
|
{
|
|
|
|
|
return Path.Combine(projectDir.Path, "project.json");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|