Skip to content

GenerateNuGetSpecTask

guryanovev edited this page Dec 27, 2016 · 10 revisions

Generates .nuspec file according to the NuGet spec.

Input Output file path, package metadata, package dependencies, package file
Output none

Summary Example

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(root/"Artifacts"/"MyPackage.nuspec") // output path
        .Id("MyPackage")                                           // package ID
        .Description("My package description")
        .WithFile("C:\\MyPachakeTool.exe", "tools")            // adding single file
        .WithFiles(GetContentFiles(), "content")               // adding multiple files
        .WithDependency("Foo.Dependency", "1.0.0.0"));

Output path

Output IFile instance is passed as a required constructor argument:

IFile nuspec = root/"Artifacts"/"MyPackage.nuspec";

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(nucpec));

Package Metadata

Package metadata properties could be set using fluent interface methods:

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(nucpec)
        .Id("MyPackageID")
        .Version("1.0.0.0")
        .Title("My package")
        .Authors("Author1", "Author2"),
        .Owners("Owner1", "Owner2")
        .Description("My package description")
        .ReleaseNotes("My package release notes")
        .Summary("My package summary")
        .Language("LOCALE_ID") // string or System.Globalization.CultureInfo
        .ProjectUrl("http://example.com")
        .IconUrl("http://example.com")
        .LicenseUrl("http://example.com")
        .Copyright("text")
        .RequireLicenseAcceptance(true)
        .Tags("dotNet", "performance"));

Package Dependencies

There are two options for setting dependencies:

  • configure it manually or
  • read it from a specific project (packages.config) file.

Manual configuration:

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(nucpec)
        .WithDependency(
            "Common.Logging", // dependency ID
            "3.2.0.0",        // dependency version (optional)
            "net45"));        // frameworkVersion (optional)

Reading from a project's packages.config file:

IFile packagesConfig = root/"Src"/"MyProject"/"packages.config";

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(nucpec)
        .WithDependenciesFromPackagesConfig(packagesConfig);

or from project directory:

IDirectory projectDir = root/"Src"/"MyProject";

ITaskFuture<Nothing> generateNuSpec = Task(
    "GenerateNuSpec",
    new GenerateNuGetSpecTask(nucpec)
        .WithDependenciesFromPackagesConfig(projectDir);