Farzad J
Farzad J

Reputation: 1127

Nuget command line

I got an empty repository (project) in VSTS, to be very specific : I don't have a visual studio solution or visual studio project.

what I want to do : 1. set up a build in VSTS 2. enable Nuget in the build process 3. download a specific NuGet package (Newtonsoft.Json) in one of the build steps. e.g. if I had a package.config file then it would have the below line in it:

 <package id="Newtonsoft.Json" version="8.0.3" allowedVersions="[8,10)" targetFramework="net46" />

Question:

I know how to do the step 1 & 2 but I don't know how to do the step 3.

anyone has any idea?

Thanks in advance!

Upvotes: 0

Views: 813

Answers (3)

Farzad J
Farzad J

Reputation: 1127

FYI: I end up to host a file in GitHub and download it as a raw file via PowerShell. But I couldn't find any solution that works without the need of solution & project.

Upvotes: 0

PatrickLu-MSFT
PatrickLu-MSFT

Reputation: 51183

You could just call nuget.exe install command in your code or cmd task, which is similar to the NuGet task: VSTS-tasks/Tasks/NuGet

Upvotes: 0

Ankit Mishra
Ankit Mishra

Reputation: 494

You need to use NuGet.exe to restore the package as follows -

  1. Download NuGet.exe -

    wget https://dist.nuget.org/win-x86-commandline/latest/nuget.exe -OutFile nuget.exe

  2. Run restore -

    nuget.exe restore packages.config -PackagesDirectory <packages_directory>

  3. This will download the package into `packages_directory'.

But I would recommend you consider using PackageReference style of project that uses the project's csproj file to add package references and then you can use msbuild to restore packages and build - msbuild project.csproj /t:"restore;build"

Upvotes: 1

Related Questions