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 PackOptions PackOptions { get; set; }
|
||||||
|
|
||||||
|
public bool Serviceable { get; set; }
|
||||||
|
|
||||||
public RuntimeOptions RuntimeOptions { get; set; }
|
public RuntimeOptions RuntimeOptions { get; set; }
|
||||||
|
|
||||||
public IDictionary<string, string> Commands { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
public IDictionary<string, string> Commands { get; } = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
|
@ -109,6 +109,7 @@ namespace NuGet
|
||||||
metadata.Authors = copy.Authors.Distinct();
|
metadata.Authors = copy.Authors.Distinct();
|
||||||
metadata.Owners = copy.Owners.Distinct();
|
metadata.Owners = copy.Owners.Distinct();
|
||||||
metadata.Tags = string.Join(",", copy.Tags).Trim();
|
metadata.Tags = string.Join(",", copy.Tags).Trim();
|
||||||
|
metadata.Serviceable = copy.Serviceable;
|
||||||
metadata.LicenseUrl = copy.LicenseUrl;
|
metadata.LicenseUrl = copy.LicenseUrl;
|
||||||
metadata.ProjectUrl = copy.ProjectUrl;
|
metadata.ProjectUrl = copy.ProjectUrl;
|
||||||
metadata.IconUrl = copy.IconUrl;
|
metadata.IconUrl = copy.IconUrl;
|
||||||
|
|
|
@ -77,6 +77,8 @@ namespace NuGet
|
||||||
|
|
||||||
public string Tags { get; set; }
|
public string Tags { get; set; }
|
||||||
|
|
||||||
|
public bool Serviceable { get; set; }
|
||||||
|
|
||||||
public IEnumerable<PackageDependencySet> DependencySets { get; set; } = new List<PackageDependencySet>();
|
public IEnumerable<PackageDependencySet> DependencySets { get; set; } = new List<PackageDependencySet>();
|
||||||
|
|
||||||
public ICollection<PackageReferenceSet> PackageAssemblyReferences { get; set; } = new List<PackageReferenceSet>();
|
public ICollection<PackageReferenceSet> PackageAssemblyReferences { get; set; } = new List<PackageReferenceSet>();
|
||||||
|
|
|
@ -130,6 +130,9 @@ namespace NuGet
|
||||||
case "tags":
|
case "tags":
|
||||||
manifestMetadata.Tags = value;
|
manifestMetadata.Tags = value;
|
||||||
break;
|
break;
|
||||||
|
case "serviceable":
|
||||||
|
manifestMetadata.Serviceable = XmlConvert.ToBoolean(value);
|
||||||
|
break;
|
||||||
case "dependencies":
|
case "dependencies":
|
||||||
manifestMetadata.DependencySets = ReadDependencySets(element);
|
manifestMetadata.DependencySets = ReadDependencySets(element);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -41,13 +41,19 @@ namespace NuGet
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal const string SchemaVersionV6 = "http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd";
|
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[] {
|
private static readonly string[] VersionToSchemaMappings = new[] {
|
||||||
SchemaVersionV1,
|
SchemaVersionV1,
|
||||||
SchemaVersionV2,
|
SchemaVersionV2,
|
||||||
SchemaVersionV3,
|
SchemaVersionV3,
|
||||||
SchemaVersionV4,
|
SchemaVersionV4,
|
||||||
SchemaVersionV5,
|
SchemaVersionV5,
|
||||||
SchemaVersionV6
|
SchemaVersionV6,
|
||||||
|
SchemaVersionV8
|
||||||
};
|
};
|
||||||
|
|
||||||
public static int GetVersionFromNamespace(string @namespace)
|
public static int GetVersionFromNamespace(string @namespace)
|
||||||
|
|
|
@ -15,6 +15,9 @@ namespace NuGet
|
||||||
public const int TargetFrameworkSupportForDependencyContentsAndToolsVersion = 4;
|
public const int TargetFrameworkSupportForDependencyContentsAndToolsVersion = 4;
|
||||||
public const int TargetFrameworkSupportForReferencesVersion = 5;
|
public const int TargetFrameworkSupportForReferencesVersion = 5;
|
||||||
public const int XdtTransformationVersion = 6;
|
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)
|
public static int GetManifestVersion(ManifestMetadata metadata)
|
||||||
{
|
{
|
||||||
|
@ -23,7 +26,12 @@ namespace NuGet
|
||||||
|
|
||||||
private static int GetMaxVersionFromMetadata(ManifestMetadata metadata)
|
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 =
|
bool referencesHasTargetFramework =
|
||||||
metadata.PackageAssemblyReferences != null &&
|
metadata.PackageAssemblyReferences != null &&
|
||||||
metadata.PackageAssemblyReferences.Any(r => r.TargetFramework != null);
|
metadata.PackageAssemblyReferences.Any(r => r.TargetFramework != null);
|
||||||
|
|
|
@ -87,6 +87,12 @@ namespace NuGet
|
||||||
set;
|
set;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool Serviceable
|
||||||
|
{
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
}
|
||||||
|
|
||||||
public bool DevelopmentDependency
|
public bool DevelopmentDependency
|
||||||
{
|
{
|
||||||
get;
|
get;
|
||||||
|
@ -284,6 +290,7 @@ namespace NuGet
|
||||||
ProjectUrl = manifestMetadata.ProjectUrl;
|
ProjectUrl = manifestMetadata.ProjectUrl;
|
||||||
RequireLicenseAcceptance = manifestMetadata.RequireLicenseAcceptance;
|
RequireLicenseAcceptance = manifestMetadata.RequireLicenseAcceptance;
|
||||||
DevelopmentDependency = manifestMetadata.DevelopmentDependency;
|
DevelopmentDependency = manifestMetadata.DevelopmentDependency;
|
||||||
|
Serviceable = manifestMetadata.Serviceable;
|
||||||
Description = manifestMetadata.Description;
|
Description = manifestMetadata.Description;
|
||||||
Summary = manifestMetadata.Summary;
|
Summary = manifestMetadata.Summary;
|
||||||
ReleaseNotes = manifestMetadata.ReleaseNotes;
|
ReleaseNotes = manifestMetadata.ReleaseNotes;
|
||||||
|
|
|
@ -51,6 +51,10 @@ namespace NuGet
|
||||||
AddElementIfNotNull(elem, ns, "copyright", metadata.Copyright);
|
AddElementIfNotNull(elem, ns, "copyright", metadata.Copyright);
|
||||||
AddElementIfNotNull(elem, ns, "language", metadata.Language);
|
AddElementIfNotNull(elem, ns, "language", metadata.Language);
|
||||||
AddElementIfNotNull(elem, ns, "tags", metadata.Tags);
|
AddElementIfNotNull(elem, ns, "tags", metadata.Tags);
|
||||||
|
if (metadata.Serviceable)
|
||||||
|
{
|
||||||
|
elem.Add(new XElement(ns + "serviceable", metadata.Serviceable));
|
||||||
|
}
|
||||||
|
|
||||||
elem.Add(GetXElementFromGroupableItemSets(
|
elem.Add(GetXElementFromGroupableItemSets(
|
||||||
ns,
|
ns,
|
||||||
|
|
|
@ -390,6 +390,7 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
builder.ReleaseNotes = project.PackOptions.ReleaseNotes;
|
builder.ReleaseNotes = project.PackOptions.ReleaseNotes;
|
||||||
builder.Language = project.Language;
|
builder.Language = project.Language;
|
||||||
builder.Tags.AddRange(project.PackOptions.Tags);
|
builder.Tags.AddRange(project.PackOptions.Tags);
|
||||||
|
builder.Serviceable = project.Serviceable;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(project.PackOptions.IconUrl))
|
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 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 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 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");
|
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(() =>
|
app.OnExecute(() =>
|
||||||
|
@ -64,6 +65,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
||||||
var artifactPathsCalculator = new ArtifactPathsCalculator(project, buildBasePathValue, outputValue, configValue);
|
var artifactPathsCalculator = new ArtifactPathsCalculator(project, buildBasePathValue, outputValue, configValue);
|
||||||
var packageBuilder = new PackagesGenerator(contexts, artifactPathsCalculator, configValue);
|
var packageBuilder = new PackagesGenerator(contexts, artifactPathsCalculator, configValue);
|
||||||
|
|
||||||
|
project.Serviceable = serviceable.HasValue();
|
||||||
|
|
||||||
int buildResult = 0;
|
int buildResult = 0;
|
||||||
if (!noBuild.HasValue())
|
if (!noBuild.HasValue())
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
private string _tempOutputDirectory;
|
private string _tempOutputDirectory;
|
||||||
private string _configuration;
|
private string _configuration;
|
||||||
private string _versionSuffix;
|
private string _versionSuffix;
|
||||||
|
private bool _serviceable;
|
||||||
|
|
||||||
private string OutputOption
|
private string OutputOption
|
||||||
{
|
{
|
||||||
|
@ -64,13 +65,24 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private string ServiceableOption
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _serviceable ?
|
||||||
|
$"--serviceable" :
|
||||||
|
"";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public PackCommand(
|
public PackCommand(
|
||||||
string projectPath,
|
string projectPath,
|
||||||
string output = "",
|
string output = "",
|
||||||
string buildBasePath = "",
|
string buildBasePath = "",
|
||||||
string tempOutput="",
|
string tempOutput="",
|
||||||
string configuration="",
|
string configuration="",
|
||||||
string versionSuffix="")
|
string versionSuffix="",
|
||||||
|
bool serviceable = false)
|
||||||
: base("dotnet")
|
: base("dotnet")
|
||||||
{
|
{
|
||||||
_projectPath = projectPath;
|
_projectPath = projectPath;
|
||||||
|
@ -79,6 +91,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
_tempOutputDirectory = tempOutput;
|
_tempOutputDirectory = tempOutput;
|
||||||
_configuration = configuration;
|
_configuration = configuration;
|
||||||
_versionSuffix = versionSuffix;
|
_versionSuffix = versionSuffix;
|
||||||
|
_serviceable = serviceable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override CommandResult Execute(string args = "")
|
public override CommandResult Execute(string args = "")
|
||||||
|
@ -89,7 +102,7 @@ namespace Microsoft.DotNet.Tools.Test.Utilities
|
||||||
|
|
||||||
private string BuildArgs()
|
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;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Xml.Linq;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using Microsoft.DotNet.ProjectModel;
|
using Microsoft.DotNet.ProjectModel;
|
||||||
using Microsoft.DotNet.Tools.Test.Utilities;
|
using Microsoft.DotNet.Tools.Test.Utilities;
|
||||||
|
@ -150,6 +152,35 @@ namespace Microsoft.DotNet.Tools.Compiler.Tests
|
||||||
.Pass();
|
.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)
|
private void CopyProjectToTempDir(string projectDir, TempDirectory tempDir)
|
||||||
{
|
{
|
||||||
// copy all the files to temp dir
|
// copy all the files to temp dir
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue