diff --git a/src/dotnet/commands/dotnet-pack/NuGet/ManifestSchemaUtility.cs b/src/dotnet/commands/dotnet-pack/NuGet/ManifestSchemaUtility.cs index 510aad70a..f839f8c19 100644 --- a/src/dotnet/commands/dotnet-pack/NuGet/ManifestSchemaUtility.cs +++ b/src/dotnet/commands/dotnet-pack/NuGet/ManifestSchemaUtility.cs @@ -44,7 +44,7 @@ namespace NuGet /// /// Added serviceble element under metadata. /// - internal const string SchemaVersionV7 = "http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd"; + internal const string SchemaVersionV8 = "http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd"; private static readonly string[] VersionToSchemaMappings = new[] { SchemaVersionV1, @@ -53,7 +53,7 @@ namespace NuGet SchemaVersionV4, SchemaVersionV5, SchemaVersionV6, - SchemaVersionV7 + SchemaVersionV8 }; public static int GetVersionFromNamespace(string @namespace) diff --git a/src/dotnet/commands/dotnet-pack/NuGet/ManifestVersionUtility.cs b/src/dotnet/commands/dotnet-pack/NuGet/ManifestVersionUtility.cs index e3e841cbc..6c1a719e8 100644 --- a/src/dotnet/commands/dotnet-pack/NuGet/ManifestVersionUtility.cs +++ b/src/dotnet/commands/dotnet-pack/NuGet/ManifestVersionUtility.cs @@ -15,7 +15,7 @@ namespace NuGet public const int TargetFrameworkSupportForDependencyContentsAndToolsVersion = 4; public const int TargetFrameworkSupportForReferencesVersion = 5; public const int XdtTransformationVersion = 6; - public const int ServiceableVersion = 7; + public const int ServiceableVersion = 8; public static int GetManifestVersion(ManifestMetadata metadata) { diff --git a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs index ffedf3f0a..54cff340d 100644 --- a/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs +++ b/test/Microsoft.DotNet.Tools.Tests.Utilities/Commands/PackCommand.cs @@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string _tempOutputDirectory; private string _configuration; private string _versionSuffix; + private string _serviceable; private string OutputOption { @@ -64,13 +65,24 @@ namespace Microsoft.DotNet.Tools.Test.Utilities } } + private string ServiceableOption + { + get + { + return _serviceable == string.Empty ? + "" : + $"--serviceable"; + } + } + public PackCommand( string projectPath, string output = "", string buildBasePath = "", string tempOutput="", string configuration="", - string versionSuffix="") + string versionSuffix="", + string serviceable = "") : base("dotnet") { _projectPath = projectPath; @@ -79,6 +91,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities _tempOutputDirectory = tempOutput; _configuration = configuration; _versionSuffix = versionSuffix; + _serviceable = serviceable; } public override CommandResult Execute(string args = "") @@ -89,7 +102,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities private string BuildArgs() { - return $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption}"; + return $"{_projectPath} {OutputOption} {BuildBasePathOption} {TempOutputOption} {ConfigurationOption} {VersionSuffixOption} {ServiceableOption}"; } } } diff --git a/test/dotnet-pack.Tests/PackTests.cs b/test/dotnet-pack.Tests/PackTests.cs index 7613ed159..ed4d35224 100644 --- a/test/dotnet-pack.Tests/PackTests.cs +++ b/test/dotnet-pack.Tests/PackTests.cs @@ -4,6 +4,8 @@ using System; using System.IO; using System.IO.Compression; +using System.Linq; +using System.Xml.Linq; using FluentAssertions; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.Tools.Test.Utilities; @@ -150,6 +152,35 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests .Pass(); } + [Fact] + public void HasServiceableFlagWhenArgumentPassed() + { + var root = Temp.CreateDirectory(); + + var testLibDir = root.CreateDirectory("TestLibrary"); + var sourceTestLibDir = Path.Combine(_testProjectsRoot, "TestLibraryWithConfiguration"); + + CopyProjectToTempDir(sourceTestLibDir, testLibDir); + + var testProject = GetProjectPath(testLibDir); + var packCommand = new PackCommand(testProject, configuration: "Debug", serviceable: "true"); + var result = packCommand.Execute(); + result.Should().Pass(); + + var outputDir = new DirectoryInfo(Path.Combine(testLibDir.Path, "bin", "Debug")); + outputDir.Should().Exist(); + outputDir.Should().HaveFiles(new[] { "TestLibrary.1.0.0.nupkg", "TestLibrary.1.0.0.symbols.nupkg" }); + + var outputPackage = Path.Combine(outputDir.FullName, "TestLibrary.1.0.0.nupkg"); + var zip = ZipFile.Open(outputPackage, ZipArchiveMode.Read); + zip.Entries.Should().Contain(e => e.FullName == "TestLibrary.nuspec"); + + var manifestReader = new StreamReader(zip.Entries.First(e => e.FullName == "TestLibrary.nuspec").Open()); + var nuspecXml = XDocument.Parse(manifestReader.ReadToEnd()); + var node = nuspecXml.Descendants().Single(e => e.Name.LocalName == "serviceable"); + Assert.Equal("true", node.Value); + } + private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir) { // copy all the files to temp dir