Merge pull request #3375 from dotnet/toddmosc/serviceable
Adding support for --serviceable option to pack command
This commit is contained in:
commit
d06e2e3f24
12 changed files with 85 additions and 4 deletions
|
@ -68,6 +68,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public PackOptions PackOptions { get; set; }
|
||||
|
||||
public bool Serviceable { get; set; }
|
||||
|
||||
public RuntimeOptions RuntimeOptions { get; set; }
|
||||
|
||||
public IDictionary<string, string> Commands { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
|
|
@ -109,6 +109,7 @@ namespace NuGet
|
|||
metadata.Authors = copy.Authors.Distinct();
|
||||
metadata.Owners = copy.Owners.Distinct();
|
||||
metadata.Tags = string.Join(",", copy.Tags).Trim();
|
||||
metadata.Serviceable = copy.Serviceable;
|
||||
metadata.LicenseUrl = copy.LicenseUrl;
|
||||
metadata.ProjectUrl = copy.ProjectUrl;
|
||||
metadata.IconUrl = copy.IconUrl;
|
||||
|
|
|
@ -77,6 +77,8 @@ namespace NuGet
|
|||
|
||||
public string Tags { get; set; }
|
||||
|
||||
public bool Serviceable { get; set; }
|
||||
|
||||
public IEnumerable<PackageDependencySet> DependencySets { get; set; } = new List<PackageDependencySet>();
|
||||
|
||||
public ICollection<PackageReferenceSet> PackageAssemblyReferences { get; set; } = new List<PackageReferenceSet>();
|
||||
|
|
|
@ -130,6 +130,9 @@ namespace NuGet
|
|||
case "tags":
|
||||
manifestMetadata.Tags = value;
|
||||
break;
|
||||
case "serviceable":
|
||||
manifestMetadata.Serviceable = XmlConvert.ToBoolean(value);
|
||||
break;
|
||||
case "dependencies":
|
||||
manifestMetadata.DependencySets = ReadDependencySets(element);
|
||||
break;
|
||||
|
|
|
@ -41,13 +41,19 @@ namespace NuGet
|
|||
/// </summary>
|
||||
internal const string SchemaVersionV6 = "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd";
|
||||
|
||||
/// <summary>
|
||||
/// Added serviceble element under metadata.
|
||||
/// </summary>
|
||||
internal const string SchemaVersionV8 = "http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd";
|
||||
|
||||
private static readonly string[] VersionToSchemaMappings = new[] {
|
||||
SchemaVersionV1,
|
||||
SchemaVersionV2,
|
||||
SchemaVersionV3,
|
||||
SchemaVersionV4,
|
||||
SchemaVersionV5,
|
||||
SchemaVersionV6
|
||||
SchemaVersionV6,
|
||||
SchemaVersionV8
|
||||
};
|
||||
|
||||
public static int GetVersionFromNamespace(string @namespace)
|
||||
|
|
|
@ -15,6 +15,9 @@ namespace NuGet
|
|||
public const int TargetFrameworkSupportForDependencyContentsAndToolsVersion = 4;
|
||||
public const int TargetFrameworkSupportForReferencesVersion = 5;
|
||||
public const int XdtTransformationVersion = 6;
|
||||
// Note that this version should change from 7 to 8 when the PackageType
|
||||
// schema is merged into here
|
||||
public const int ServiceableVersion = 7;
|
||||
|
||||
public static int GetManifestVersion(ManifestMetadata metadata)
|
||||
{
|
||||
|
@ -23,7 +26,12 @@ namespace NuGet
|
|||
|
||||
private static int GetMaxVersionFromMetadata(ManifestMetadata metadata)
|
||||
{
|
||||
// Important: check for version 5 before version 4
|
||||
// Important: always add newer version checks at the top
|
||||
if (metadata.Serviceable)
|
||||
{
|
||||
return ServiceableVersion;
|
||||
}
|
||||
|
||||
bool referencesHasTargetFramework =
|
||||
metadata.PackageAssemblyReferences != null &&
|
||||
metadata.PackageAssemblyReferences.Any(r => r.TargetFramework != null);
|
||||
|
|
|
@ -87,6 +87,12 @@ namespace NuGet
|
|||
set;
|
||||
}
|
||||
|
||||
public bool Serviceable
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
public bool DevelopmentDependency
|
||||
{
|
||||
get;
|
||||
|
@ -284,6 +290,7 @@ namespace NuGet
|
|||
ProjectUrl = manifestMetadata.ProjectUrl;
|
||||
RequireLicenseAcceptance = manifestMetadata.RequireLicenseAcceptance;
|
||||
DevelopmentDependency = manifestMetadata.DevelopmentDependency;
|
||||
Serviceable = manifestMetadata.Serviceable;
|
||||
Description = manifestMetadata.Description;
|
||||
Summary = manifestMetadata.Summary;
|
||||
ReleaseNotes = manifestMetadata.ReleaseNotes;
|
||||
|
|
|
@ -51,6 +51,10 @@ namespace NuGet
|
|||
AddElementIfNotNull(elem, ns, "copyright", metadata.Copyright);
|
||||
AddElementIfNotNull(elem, ns, "language", metadata.Language);
|
||||
AddElementIfNotNull(elem, ns, "tags", metadata.Tags);
|
||||
if (metadata.Serviceable)
|
||||
{
|
||||
elem.Add(new XElement(ns + "serviceable", metadata.Serviceable));
|
||||
}
|
||||
|
||||
elem.Add(GetXElementFromGroupableItemSets(
|
||||
ns,
|
||||
|
|
|
@ -390,6 +390,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
builder.ReleaseNotes = project.PackOptions.ReleaseNotes;
|
||||
builder.Language = project.Language;
|
||||
builder.Tags.AddRange(project.PackOptions.Tags);
|
||||
builder.Serviceable = project.Serviceable;
|
||||
|
||||
if (!string.IsNullOrEmpty(project.PackOptions.IconUrl))
|
||||
{
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var buildBasePath = app.Option("-b|--build-base-path <OUTPUT_DIR>", "Directory in which to place temporary build outputs", CommandOptionType.SingleValue);
|
||||
var configuration = app.Option("-c|--configuration <CONFIGURATION>", "Configuration under which to build", CommandOptionType.SingleValue);
|
||||
var versionSuffix = app.Option("--version-suffix <VERSION_SUFFIX>", "Defines what `*` should be replaced with in version field in project.json", CommandOptionType.SingleValue);
|
||||
var serviceable = app.Option("-s|--serviceable", "Set the serviceable flag in the package", CommandOptionType.NoValue);
|
||||
var path = app.Argument("<PROJECT>", "The project to compile, defaults to the current directory. Can be a path to a project.json or a project directory");
|
||||
|
||||
app.OnExecute(() =>
|
||||
|
@ -64,6 +65,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
var artifactPathsCalculator = new ArtifactPathsCalculator(project, buildBasePathValue, outputValue, configValue);
|
||||
var packageBuilder = new PackagesGenerator(contexts, artifactPathsCalculator, configValue);
|
||||
|
||||
project.Serviceable = serviceable.HasValue();
|
||||
|
||||
int buildResult = 0;
|
||||
if (!noBuild.HasValue())
|
||||
{
|
||||
|
|
|
@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
private string _tempOutputDirectory;
|
||||
private string _configuration;
|
||||
private string _versionSuffix;
|
||||
private bool _serviceable;
|
||||
|
||||
private string OutputOption
|
||||
{
|
||||
|
@ -64,13 +65,24 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
|||
}
|
||||
}
|
||||
|
||||
private string ServiceableOption
|
||||
{
|
||||
get
|
||||
{
|
||||
return _serviceable ?
|
||||
$"--serviceable" :
|
||||
"";
|
||||
}
|
||||
}
|
||||
|
||||
public PackCommand(
|
||||
string projectPath,
|
||||
string output = "",
|
||||
string buildBasePath = "",
|
||||
string tempOutput="",
|
||||
string configuration="",
|
||||
string versionSuffix="")
|
||||
string versionSuffix="",
|
||||
bool serviceable = false)
|
||||
: 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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue