Create NuGet package from folder - nuget

I need to package an Azure function app that we've built in TeamCity as a Nuget package for deployment via Octopus Deploy. Standard practice would be to use MSBuild and OctoPack but with Azure Functions this will not work as the function.json files are created after the build is complete and they would therefore not be included in any package that OctoPack creates.
So I need to build first and then create a package from the \bin\Release\net471 folder. Would be grateful to hear peoples opinions on the best way to acheive this?

In the end I went with octo.exe using a start directory of \bin\Release\net471 which saved me having to create a nuspec file as I would have had to if using the NuGet CLI or dotnet pack

Related

Extract NuGet packager in Azure DevOps

I am trying to extract Nuget Package in Azure DevOps as part of build. I don't have dedicated plugin in Azure DevOps to unpack Nuget package. I just use zip extractor.
I see some errors,
stderr: 2019-10-25T14:28:54.9806038Z ERROR: Can't allocate required
memory!
I have attached pic as well
How many nuget packages are in your project? As my test, I upload two nuget packages in my project.
If I set the Archive file patterns as *.nupkg
I will get the same error message as yours.
But if I add two Extract files tasks and set the Archive file patterns as below.
The task will run successed.
Hope this will help.
Add the NuGet Restore Task before your build step.

Cake nuget addin problem with Azure Artifacts

We are started migration from TeamCity+Proget to Azure Pipelines and Azure Artifacts. For builds we use cake scripts and it's a part of problem.
In our cake scripts a lot of #addin nuget:?package=My.Private.Package
Unfortunately cake nuget cannot authenticate on Azure Artifacts, which is required by it. #addin is run before other code inside cake scripts, so i cant add any internal authentication.
Also problem is that we are using Hosted Agents.
So my idea is for resolving it, is download nuget packages from Azure Artifacts (with Download Package steps), unzip them (cause its downloaded as zip files), pack again to nupkg files and somehow add to local cache.
So i got few questions:
1. Maybe somebody know better way to resolve authentication problem between cake addin nuget and Azure Artifacts?
2. If not, how to add to local cache nuget packages from .nupkg files on Hosted Agents without adding it to csproj/sln files. (Dev team is totally against it, cause those packages needed for build and not a part of application).
Will be appreciate for any ideas. Thanks

Command to update packages repo in PackageManager console

I need to update package repo before building a solution in TFS Build Definition. I want to implement this using CommandLine build task.
Could someone tell me how to write a command to update package repo using a path.
According to your prior question, there are just missing some external packages during your TFS build pipeline.
Usually TFS use Package Management that hosts NuGet, npm, and Maven packages alongside all your other TFS assets: source code, builds, releases, etc, also be able to handle the external packages.
You could directly add external packages to a TFS Package Management feed. When you restore the packages, select the feed. All need packages will be restored entirely. To achieve this, just use Push NuGet packages to specify the packages you want to publish and the target feed location.
More details please refer Get started with NuGet Package Management in TFS

Where is the nuget packages folder located on a hosted build server using TFS?

I need to execute a command line utility from a package that is downloaded as part of nuget package restore in the TFS build process.
On my local computer that is stored in c:\users\me.nuget*
I've tried every permutation of that on TFS without success. I've also tried \mydir\packages with no success as well.
The biggest problem is that I have to run the package restore step before being able to see any sort of feedback from the log. That's some slow debugging.
Any ideas? Thanks ahead.
With the latest nuget/msbuild the packages folder is held under the active user's profile directory, so an appropriate Powershell command is
Get-ChildItem $(UserProfile)\.nuget\packages
This currently evaluates on the VSTS 2017 Hosted build agent to C:\Users\VssAdministrator\.nuget\packages but by using the variable you are insulated from any changes made.
Just an addition to #Paul Hatcher's answer:
I also faced the same problem in Azure DevOps build pipeline where a specific package and nuget packages directory could not be found.
It is a Xamarin.Forms app based on a .net standard library where no packages folder exists. I later noticed in build logs that the packages are restored to nuget folder under user's profile. However this particular case is not documented on https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=vsts#agent-variables.
That means #Paul Hatcher's answer is also valid if you try to reference nuget package folder directly from your build pipeline. This ($(UserProfile).nuget\packages) should actually be a (standard) predefined build variable.
The Nuget package cache folder is in C:\Users\buildguest.nuget\packages, but it will be cleaned after build if you are using Hosted build server.
The simple way to verify:
Add NuGet restore or .Net Core Restore build step to restore packages
Add PowerShell build step to list files in C:\Users\buildguest.nuget\packages
Code:
Get-ChildItem -Path C:\Users\buildguest\.nuget\packages
Queue build and check the PowerShell step log (the packages’ will be listed in the log)
Remove/disable NuGet restore or .Net Core Restore build step > Save build definition
Queue build
The build will be failed, because the path does not exist.
So, the packages need to be restored before build solution/project if aren’t existing. You can add packages to source control and map to build agent to deal with the issue of too long time takes to restore packages.

NuGet package dependencies and build/deploy servers

We're using FluentMigrator (a NuGet package) on an ASP.net/MVC project to maintain database changes to our SQL Server.
What is the "correct" way to distribute a NuGet package with other build artifacts for usage during a deployment? Do I only need the "packages" folder?
I'm hoping for a response other than "use package manager and install the Nuget package on PROD".
I don't want to pull the package (from either local or non-local sources) during deployment, I want to include the correct package with my compiled code.
The correct way is to pull the package down before building the project, then assuming your project references the assembly such that Copy Local is true, it will be included in the build output, which should be stored as an artifact in your CI tool.
You definitely should not be doing anything related to NuGet beyond this point in your build/deployment process.