Adding support for --serviceable option to pack command which puts <serviceable>true</serviceable> into the output nuspec

This commit is contained in:
Todd Moscinski 2016-06-03 14:53:58 -07:00
parent 90fbc3bb53
commit 8099e6b9f7
10 changed files with 37 additions and 2 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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>();

View file

@ -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;

View file

@ -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 SchemaVersionV7 = "http://schemas.microsoft.com/packaging/2016/06/nuspec.xsd";
private static readonly string[] VersionToSchemaMappings = new[] {
SchemaVersionV1,
SchemaVersionV2,
SchemaVersionV3,
SchemaVersionV4,
SchemaVersionV5,
SchemaVersionV6
SchemaVersionV6,
SchemaVersionV7
};
public static int GetVersionFromNamespace(string @namespace)

View file

@ -15,6 +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 static int GetManifestVersion(ManifestMetadata metadata)
{
@ -23,7 +24,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);

View file

@ -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;

View file

@ -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,

View file

@ -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))
{

View file

@ -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 output nuspec", 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())
{