Merge pull request #1553 from dotnet/pakrym/tests2
Fix dotnet pack with buildbasepath
This commit is contained in:
commit
e352841a1e
5 changed files with 35 additions and 15 deletions
|
@ -12,24 +12,19 @@ namespace Microsoft.DotNet.Tools.Pack
|
|||
internal class BuildProjectCommand
|
||||
{
|
||||
private readonly Project _project;
|
||||
private readonly ArtifactPathsCalculator _artifactPathsCalculator;
|
||||
|
||||
private readonly string _buildBasePath;
|
||||
private readonly string _configuration;
|
||||
|
||||
private readonly string _versionSuffix;
|
||||
|
||||
private bool SkipBuild => _artifactPathsCalculator.CompiledArtifactsPathSet;
|
||||
|
||||
public BuildProjectCommand(
|
||||
Project project,
|
||||
ArtifactPathsCalculator artifactPathsCalculator,
|
||||
string buildBasePath,
|
||||
string configuration,
|
||||
string versionSuffix)
|
||||
{
|
||||
_project = project;
|
||||
_artifactPathsCalculator = artifactPathsCalculator;
|
||||
_buildBasePath = buildBasePath;
|
||||
_configuration = configuration;
|
||||
_versionSuffix = versionSuffix;
|
||||
|
@ -37,11 +32,6 @@ namespace Microsoft.DotNet.Tools.Pack
|
|||
|
||||
public int Execute()
|
||||
{
|
||||
if (SkipBuild)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (_project.Files.SourceFiles.Any())
|
||||
{
|
||||
var argsBuilder = new List<string>();
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
int buildResult = 0;
|
||||
if (!noBuild.HasValue())
|
||||
{
|
||||
var buildProjectCommand = new BuildProjectCommand(project, artifactPathsCalculator, buildBasePathValue, configValue, versionSuffixValue);
|
||||
var buildProjectCommand = new BuildProjectCommand(project, buildBasePathValue, configValue, versionSuffixValue);
|
||||
buildResult = buildProjectCommand.Execute();
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
private string _projectPath;
|
||||
private string _outputDirectory;
|
||||
private string _buildBasePath;
|
||||
private string _tempOutputDirectory;
|
||||
private string _configuration;
|
||||
private string _versionSuffix;
|
||||
|
@ -23,6 +24,15 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
$"-o \"{_outputDirectory}\"";
|
||||
}
|
||||
}
|
||||
private string BuildBasePathOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _buildBasePath == string.Empty ?
|
||||
"" :
|
||||
$"-b \"{_buildBasePath}\"";
|
||||
}
|
||||
}
|
||||
|
||||
private string TempOutputOption
|
||||
{
|
||||
|
@ -55,8 +65,9 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
}
|
||||
|
||||
public PackCommand(
|
||||
string projectPath,
|
||||
string output="",
|
||||
string projectPath,
|
||||
string output = "",
|
||||
string buildBasePath = "",
|
||||
string tempOutput="",
|
||||
string configuration="",
|
||||
string versionSuffix="")
|
||||
|
@ -64,6 +75,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
{
|
||||
_projectPath = projectPath;
|
||||
_outputDirectory = output;
|
||||
_buildBasePath = buildBasePath;
|
||||
_tempOutputDirectory = tempOutput;
|
||||
_configuration = configuration;
|
||||
_versionSuffix = versionSuffix;
|
||||
|
@ -77,7 +89,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
|
||||
private string BuildArgs()
|
||||
{
|
||||
return $"{_projectPath} {OutputOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption}";
|
||||
return $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
|
@ -78,6 +79,22 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
||||
}
|
||||
|
||||
[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);
|
||||
zip.Entries.Should().Contain(e => e.FullName == "lib/dnxcore50/TestLibraryWithConfiguration.dll");
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
// copy all the files to temp dir
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
"dependencies": {
|
||||
"NETStandard.Library": "1.0.0-rc2-23811",
|
||||
|
||||
"System.IO.Compression.ZipFile": "4.0.1-rc2-23811",
|
||||
|
||||
"Microsoft.DotNet.Tools.Tests.Utilities": { "target": "project" },
|
||||
"Microsoft.DotNet.Cli.Utils": {
|
||||
"target": "project"
|
||||
|
|
Loading…
Reference in a new issue