Flow the version suffix via pack as well
This commit is contained in:
parent
c941162b17
commit
ed16632a33
4 changed files with 46 additions and 15 deletions
|
@ -17,18 +17,22 @@ namespace Microsoft.DotNet.Tools.Pack
|
|||
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)
|
||||
Project project,
|
||||
ArtifactPathsCalculator artifactPathsCalculator,
|
||||
string buildBasePath,
|
||||
string configuration,
|
||||
string versionSuffix)
|
||||
{
|
||||
_project = project;
|
||||
_artifactPathsCalculator = artifactPathsCalculator;
|
||||
_buildBasePath = buildBasePath;
|
||||
_configuration = configuration;
|
||||
_versionSuffix = versionSuffix;
|
||||
}
|
||||
|
||||
public int Execute()
|
||||
|
@ -44,6 +48,12 @@ namespace Microsoft.DotNet.Tools.Pack
|
|||
argsBuilder.Add("--configuration");
|
||||
argsBuilder.Add($"{_configuration}");
|
||||
|
||||
if (!string.IsNullOrEmpty(_versionSuffix))
|
||||
{
|
||||
argsBuilder.Add("--version-suffix");
|
||||
argsBuilder.Add(_versionSuffix);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(_buildBasePath))
|
||||
{
|
||||
argsBuilder.Add("--build-base-path");
|
||||
|
|
|
@ -39,12 +39,12 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
pathValue = Directory.GetCurrentDirectory();
|
||||
}
|
||||
|
||||
if(!pathValue.EndsWith(Project.FileName))
|
||||
if (!pathValue.EndsWith(Project.FileName))
|
||||
{
|
||||
pathValue = Path.Combine(pathValue, Project.FileName);
|
||||
}
|
||||
|
||||
if(!File.Exists(pathValue))
|
||||
if (!File.Exists(pathValue))
|
||||
{
|
||||
Reporter.Error.WriteLine($"Unable to find a project.json in {pathValue}");
|
||||
return 1;
|
||||
|
@ -52,18 +52,18 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
// Set defaults based on the environment
|
||||
var settings = ProjectReaderSettings.ReadFromEnvironment();
|
||||
var versionSuffixValue = versionSuffix.Value();
|
||||
|
||||
if (versionSuffix.HasValue())
|
||||
if (!string.IsNullOrEmpty(versionSuffixValue))
|
||||
{
|
||||
settings.VersionSuffix = versionSuffix.Value();
|
||||
settings.VersionSuffix = versionSuffixValue;
|
||||
}
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(pathValue, settings);
|
||||
|
||||
var configValue = configuration.Value() ?? Cli.Utils.Constants.DefaultConfiguration;
|
||||
var outputValue = output.Value();
|
||||
var buildBasePathValue = buildBasePath.Value();
|
||||
|
||||
var contexts = ProjectContext.CreateContextForEachFramework(pathValue, settings);
|
||||
var project = contexts.First().ProjectFile;
|
||||
|
||||
var artifactPathsCalculator = new ArtifactPathsCalculator(project, buildBasePathValue, outputValue, configValue);
|
||||
|
@ -72,7 +72,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
int buildResult = 0;
|
||||
if (!noBuild.HasValue())
|
||||
{
|
||||
var buildProjectCommand = new BuildProjectCommand(project, artifactPathsCalculator, buildBasePathValue, configValue);
|
||||
var buildProjectCommand = new BuildProjectCommand(project, artifactPathsCalculator, buildBasePathValue, configValue, versionSuffixValue);
|
||||
buildResult = buildProjectCommand.Execute();
|
||||
}
|
||||
|
||||
|
@ -92,6 +92,6 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
#endif
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,11 +7,11 @@ using System.Linq;
|
|||
using System.Reflection.Metadata;
|
||||
using System.Reflection.PortableExecutable;
|
||||
|
||||
namespace Microsoft.DotNet.Tools.Builder.Tests
|
||||
namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||
{
|
||||
public static class PeReaderUtils
|
||||
{
|
||||
internal static string GetAssemblyAttributeValue(string assemblyPath, string attributeName)
|
||||
public static string GetAssemblyAttributeValue(string assemblyPath, string attributeName)
|
||||
{
|
||||
if (!File.Exists(assemblyPath))
|
||||
{
|
|
@ -3,6 +3,8 @@
|
|||
|
||||
using System;
|
||||
using System.IO;
|
||||
using FluentAssertions;
|
||||
using Microsoft.DotNet.ProjectModel;
|
||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||
using Xunit;
|
||||
|
||||
|
@ -56,6 +58,25 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
|||
outputDir.Should().Exist();
|
||||
outputDir.Should().HaveFiles(new[] { "TestLibrary.1.0.0.nupkg", "TestLibrary.1.0.0.symbols.nupkg" });
|
||||
}
|
||||
|
||||
[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();
|
||||
|
||||
var output = Path.Combine(testInstance.TestRoot, "bin", "Debug", DefaultFramework, "TestLibraryWithConfiguration.dll");
|
||||
var informationalVersion = PeReaderUtils.GetAssemblyAttributeValue(output, "AssemblyInformationalVersionAttribute");
|
||||
|
||||
informationalVersion.Should().NotBeNull();
|
||||
informationalVersion.Should().BeEquivalentTo("1.0.0-85");
|
||||
|
||||
var outputPackage = Path.Combine(testInstance.TestRoot, "bin", "Debug", "TestLibraryWithConfiguration.1.0.0-85.nupkg");
|
||||
File.Exists(outputPackage).Should().BeTrue(outputPackage);
|
||||
}
|
||||
|
||||
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue