npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gulp-nuget

v1.3.0

Published

gulp nuget support to pack, push and restore nuget packages

Downloads

4,466

Readme

Build Status

gulp-nuget

Version 1.0.0 have breaking changes so please check the release notes before updating

This is hopefully all you need to get started with the plugin. If you think anything is missing or not working as described below, please open an issue or send a pull request...thanks!

First off, you will need nuget. Here is an example on how you can download it. Do this in a step prior to running the gulp-nuget plugin. If you already have it on the machine you could just skip this step.


var gulp = require('gulp');
var request = require('request');
var fs = require('fs');

gulp.task('nuget-download', function(done) {
    if(fs.existsSync('nuget.exe')) {
        return done();
    }

    request.get('http://nuget.org/nuget.exe')
        .pipe(fs.createWriteStream('nuget.exe'))
        .on('close', done);
});

Then you can use the following commands:

How to use gulp-nuget pack:

Select the .nuspec or .csproj files you want to pack and pipe them to nuget pack. Stream the output from nuget pack to the place you want to save the package(s).


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-pack', function() {
  var nugetPath = './path/to/nuget.exe';

  return gulp.src('project.nuspec')
    .pipe(nuget.pack({ nuget: nugetPath, version: "1.0.0" }))
    .pipe(gulp.dest('project.1.0.0.nupkg'));
});

An example when using the default options.


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-pack', function() {
  return gulp.src('project.csproj')
    .pipe(nuget.pack())
    .pipe(gulp.dest('project.1.0.0.nupkg'));
});
Valid options for nuget pack

Options that have a default value is specified by a comment except of boolean values that are by default always false. The new temp folder that is used is ./gulp-nuget and should be added to your .gitignore file.

Read more about the options here: http://docs.nuget.org/consume/command-line-reference#pack-command


var options = {
  nuget: './path/to/nuget.exe', //./nuget.exe
  outputDirectory: './nupkgs/', //./gulp-nuget/
  maxBuffer: 200*1024, // node child_process buffer
  version: '1.0.0',
  basePath: './',
  exclude: '**/*.designer.cs',
  properties: 'configuration=release',
  minClientVersion: '2.5',
  msBuildVersion: '12',
  verbosity: 'normal',
  build: true,
  symbols: true,
  symbolPackageFormat: "snupkg",
  excludeEmptyDirectories: true,
  includeReferencedProjects: true,
  noDefaultExcludes: true,
  tool: true,
  interactive: true // Override the default nonInteractive option
};

var stream = nuget.pack(options);

How to use gulp-nuget push:

You could choose to just push a single nuget package like this:


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-pack', function() {
  var nugetPath = './path/to/nuget.exe';

  return gulp.src('project.1.0.0.nupkg')
    .pipe(nuget.push({ source: 'http://your-nuget-feed.org/', nuget: nugetPath, apiKey: 'secret-key-goes-here' }));
});

Or you could push multiple packages like this:


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-pack', function() {
  var nugetPath = './path/to/nuget.exe';

  return gulp.src(['project.1.0.0.nupkg', 'project.1.1.0.nupkg'])
    .pipe(nuget.push({ source: 'http://your-nuget-feed.org/', nuget: nugetPath, apiKey: 'secret-key-goes-here' }));
});
Valid options for nuget push

Options that have a default value is specified by a comment except of boolean values that are by default always false.

Read more about the options here: http://docs.nuget.org/consume/command-line-reference#push-command


var options = {
  nuget: './path/to/nuget.exe', //./nuget.exe
  maxBuffer: 200*1024, // node child_process buffer
  source: 'http://your-nuget-feed.org',
  apiKey: 'secret-key-goes-here',
  timeout: '300',
  configFile: '%AppData%/NuGet/NuGet.config',
  verbosity: 'normal',
  interactive: true // Override the default nonInteractive option
};

var stream = nuget.push(options);

How to use gulp-nuget pack then push:

If you don't want to save your nuget package you could push it directly by piping the output from pack to push. The name of the nuget package will be the name that's provided by nuget.exe. It would be project.1.0.0.nupkg in the example below.


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-pack-n-push', function() {
  var nugetPath = './path/to/nuget.exe';

  return gulp.src('./project.nuspec')
    .pipe(nuget.pack({ nuget: nugetPath, version: '1.0.0' }))
    .pipe(nuget.push({ feed: 'http://your-nuget-feed.org/', nuget: nugetPath, apiKey: 'secret-key-goes-here' }));
});

How to use gulp-nuget restore:

You can use restore by pipe packages.config, project.json or *.sln file. The packages specified in the piped file will be restored according to given options.


var gulp = require('gulp');
var nuget = require('gulp-nuget');

gulp.task('nuget-restore', function() {
  var nugetPath = './path/to/nuget.exe';

  return gulp.src('./project.sln')
    .pipe(nuget.restore({ nuget: nugetPath }));
});
Valid options for nuget restore

Options that have a default value is specified by a comment except of boolean values that are by default always false.

Read more about the options here: http://docs.nuget.org/consume/command-line-reference#restore-command


var options = {
  nuget: './path/to/nuget.exe', //./nuget.exe
  maxBuffer: 200*1024, // node child_process buffer
  source: 'http://your-nuget-feed.org',
  configFile: '%appdata%/NuGet/nuget.config',
  packagesDirectory: './packages',
  solutionDirectory: './',
  msBuildVersion: '12',
  verbosity: 'normal',
  noCache: true,
  requireConsent: true,
  disableParallelProcessing: true,
  interactive: true // Override the default nonInteractive option
};

var stream = nuget.restore(options);

Want to help?

Before submitting a pull request make sure the tests are green. Run them by using docker as described below:

# to get the source and build the docker image.
git clone [email protected]:mckn/gulp-nuget.git
cd gulp-nuget
docker-compose build

# to run the tests inside a container of the image
docker-compose run gulp-nuget npm test