简体   繁体   中英

How to restore NuGet package in Azure Pipeline?

I am new to Azure DevOps and trying to create my first Azure pipeline. I have a ASP.NET MVC project and there are a few NuGet packages that need to be restored before the MSBuild step.

Unfortunately, the NuGet restore is failing with the following error:

The pipeline is not valid. Job Job_1: Step 'NuGetCommand' references task 'NuGetCommand' at version '2.194.0' contains an execution handler that relies on NodeJS version '6' which is restricted by your administrator.

NodeJS 6 came disabled out of the box so we are not going to enable it.

My Questions:

  1. Is there an alternative to NuGet restore that does not use NodeJS?
  2. Is there a way to update the NodeJS6 to a higher version?

It's AzureDevOps' NuGetCommand task that uses NodeJS , not NuGet itself. Therefore, you can find a way to restore without using Azure DevOps' NuGetCommand task.

Idea 1: use DotnetCoreCli task instead. However, this probably won't work for you since you said your project is ASP.NET MVC, rather than ASP.NET Core. Also, it also appears to need NodeJS to run .

Idea 2: Use MSBuild restore. You can test on your local machine whether or not this works by clearing your global packages folder, or temporarily configuring NuGet to use a different path, and then running msbuild -t:restore My.sln from a Developer PowerShell For Visual Studio prompt.If your project uses packages.config, rather than PackageReference, you'll need to also pass -p:RestorePackagesConfig=true (although maybe this is currently broken ). I'm not an expert on Azure Pipelines tasks, so I don't know what it means that this task defines both PowerShell and Node execution entry points , but maybe it means it will work even if your CI agent doesn't allow NodeJS.

Idea 3: Don't use any of the built-in tasks, just use - script: or - task: PowerShell@2 , but even that is a little questionable whether it'll work since even the powershell task defines a Node execution entry point . I'm guessing it will work, but I don't have access to a CI agent where NodeJS is forbidden, so I couldn't test even if I wanted to. Anyway, if this works, then you can run MSBuild yourself (but it might also be your responsibility to find msbuild.exe if it's not on the path). Or you can download nuget.exe yourself and execute it in your script. The point is, if you can get Azure Pipeline's script task working, you can run any script and do everything you need yourself.

Idea 4: Use Microsoft Hosted agents . They have documented all the software they pre-install on the machines, which includes Node JS. Downside is that once you exceed the free quota it costs money, and I've worked for companies where it's easier to get money to buy hardware once-off, and pretend that maintenance of the server is free, even though it reduces team productivity, rather than pay for a monthly service. So, I'll totally understand if this is not an option for you.

Idea 5: Talk to whoever maintains your CI agents and convince them to allow & install NodeJS. It's clearly a fundamental part of Azure Pipelines. The tasks are open source on github, and you can see that pretty much all of them use NodeJS to orchestrate whatever work it does. Frankly, I thought the agent software itself was a NodeJS application, so I'm surprised that it runs without NodeJS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM