Create NuGet Package using MSBuild and VS Team Services - msbuild

I am using visual studio 2015, from past few days I was trying to create nuget package that are hosted on Visual Studio Team Services (previously Visual Studio Online) and created every time a project is build, but with no success. Can someone please provide step by step intro to how to achieve this task. I am very thankful to you.

Following is a simple build definition to create nuget package and publish the package to VSTS hosted package service:
Create a build definition in VSTS to build the project.
Add "NuGet Packager" task in the build definition to create the Nuget package. I use project file to generate the nuget package, so set the path to "NugetP.csproj".
Add "NuGet Publisher" task to publish the package to Feed. Since I use the VSTS hosted package feed, so choose "Internal NuGet Feed", and enter the nuget feed URL in "Internal Feed URL".
Save the build definition and queue a new build. The nuget package will be created and pushed to the feed.

Related

Error NU1101: Unable to find package ProjectABC.Core.Services. No packages exist with this id in source(s)

I am trying to implement CI/CD on Azure DevOps for my Asp.net Core project.
Project having Nuget packages from three different sources:
MSBUild in Azure Pipeline is going to find nuget packages in Offline Packages or Nuget.org only but not going to find external source which i am also using:
http://dev-abc-api-nugetserver-wi.azurewebsites.net/nuget/
I have tried below code in Azure Pipeline Build but that didn't work
/p:RestoreAdditionalSources="http://dev-abc-api-nugetserver-wi.azurewebsites.net/nuget/" /t:Rebuild
But still receiving same error:
Error NU1101: Unable to find package abc.Core.Services. No packages
exist with this id in source(s): Microsoft Visual Studio Offline
Packages, nuget.org
My build pipeline:
You need to create nuget.config file (and commit/check in to your project), in the file you need specify your NuGet sources (include your external source).
In your build pipeline add .Net core task with the restore command, specify your .csproj file and check the "Feeds in my NuGet config", create a NuGet endpoint with username & password for your external nuget repo.
After this task all your packages should be downloaded and the build should be run successfully.

Use a Web Deployment Package or NuGet package as build artifact in Visual Studio Team Services

I am using Visual Studio Team Services for Continous Integration, Continous Deployment for a ASP .NET Core project. In VSTS when we create a build definition, we are required to provide a repository link from where VSTS will get the code and then build it and we can use the build artifacts in VSTS release definition.
I do not want to link my repository with VSTS build definition. Instead I want the ability to produce a Web Deployment Package or a NuGet package for my project (I wont mind even if I have to do it out of VSTS) and then use that package as build artifact in my release definition.
Is that possible? if yes then how can I acheive this?
Thanks
You can add a package management feed as a release artifact. When choosing an artifact source, change the dropdown from Build to Package Management.
However, you still need to publish your NuGet packages to the feed first.
First, there are many source types of artifact in Release, as Daniel said that you can choose Package Management as release artifact, but you need to push the package to the feed first.
With Build artifact, it needs to be generated through Build and you need to specify the sources (Get sources).
Secondly, you can don’t link any artifacts in release definition, and download/copy the Web Deployment Package or NuGet package from a shared folder, other machine or other ways (e.g. FTP server) through related tasks, such as Copy Files, Windows Machine File Copy, PowerShell (download files programming) etc…

Building Xamarin Android on TFS - how to download Nuget packages

I have a Xamarin Android project that I'm building on a TFS build server. The Nuget packages are not restored, and so the build fails with a bunch of "[filename] could not be found" errors.
I believe the problem is that for the Android build, you specify the .csproj file, rather than the .sln. The field is called "Project" on a Xamarin.Android build step. The automatic Nuget package restore only works if you load the solution file. If you directly build the csproj with MSBuild.exe, the Nuget package restore does not happen.
I expect I can create a PowerShell script step that manually calls Nuget, but it seems this should be supported first-class. Any ideas for me?
The recommended way is to add a NuGet Installer build step before the actually build step. More about this package here

Visual Studio Online build error about NuGet client version (v3.0 or above required)

I am trying to setup a CI build using Visual Studio Online but I am getting the following error about the NuGet client:
The 'System.Net.Http 4.0.0' package requires NuGet client version '3.0' or above, but the current NuGet version is '2.8.60318.667'.
Solution builds and deploys fine directly from my Visual Studio 2015 itself but I am unable to get it to build in VSO. Does anyone if NuGet 3.x is installed on hosted build controllers or if I can supply my own copy along with my solution?
It's hard to guess by the question what build tasks are used. If you use VSBuild/MSBuild, it is only possible to turn "Restore NuGet packages" on, but there's no influence on the NuGet version.
However, if you turn this checkbox off, and instead add another build task called NuGet Installer before the main build step, you'll be able to provide a custom path to NuGet.exe. In the case of hosted build agent, the most obvious option is to commit required version of NuGet.exe to the repo, and then reference it from the build step:
Sounds like a hack, but it might work in your case.

TeamCity - no artifacts generated with Octopus Deploy / Octopack

I have a Visual Studio project, that's set up in TeamCity with a build-task to create artifacts via OctoPack (3.0.43). Next, a deploy-task, that receives the output NuGet-package from the build-task task (on successful build) as a dependency.
I've tried setting up the build-task using both the MsBuild build-runner and the Visual Studio (sln) one, but in both cases no artifacts are created.
I've added the OctoPack NuGet package to my Visual Studio project.
Found this one out myself:
When I added OctoPack NuGet package, all seemed well. Hinted by various posts, I looked to the OctoPack.targets file. Here I stumbled upon the Install.ps1 file, that seemed to be supposed to inject some build-actions in the VS project's .csproj file upon adding the NuGet package to project.
Next up, I removed the NuGet package and tried re-installing, but this time using the Package Management Console (View > Other Windows > Package Management Console) with command:
Install-Package OctoPack
This output the following:
Successfully added 'OctoPack 3.0.43' to MySolution.MyProject. & :
File
C:\somepath\mysolution\packages\OctoPack.3.0.43\tools\Install.ps1
cannot be loaded because running scripts is disabled on this system.
For more information, see about_Execution_Policies at
http://go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3
So, some security stuff was preventing the PowerShell script to do its stuff with the .csproj file.
Solution:
In the same window (Package Management Console) or in an elevated PowerShell, execute
Set-ExecutionPolicy RemoteSigned
Retry NuGet package-installation (still same window or using the NuGet GUI) - now the NuGet package installer should inject whatever your version of OctoPack wants it to. After this, my TeamCity build started generating OctoPack artifacts correctly.