nuget tfs build 2015 - nuget

I am trying to use NuGet to package and publish the package with TFS Build 2015 to local NuGet Server. I am getting error , I am not sure what am i missing. Thanks for Help.
Here is Error
Starting task: NuGet Packager
Set workingFolder to default: C:\Lucky\agent\tasks\NuGetPackager\0.1.58
Executing the powershell script: C:\Lucky\agent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
Checking pattern is specified
No Pattern found in solution parameter.
Found files: 1
--File: "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter"
The property DirectoryName does not exist or was not found.
Creating Nuget Arguments:
--ARGS: pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
Invoking nuget with pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release on
C:\Lucky\agent\agent\worker\tools\NuGet.exe pack "C:\Lucky\agent_work\1\s\Dev\FabrikamFiber.CallCenter" -OutputDirectory "C:\Lucky\agent_work\1\s" -Properties Configuration=Release
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
Please specify a nuspec or project file to use.
Unexpected exit code 1 returned from tool NuGet.exe
Finishing task: NuGetPackager
Task NuGetPackager failed. This caused the job to fail. Look at the logs for the task for more details.

According to the error info:
Please specify a nuspec or project file to use. Unexpected exit code 1
returned from tool NuGet.exe
You may specified a wrong argument in nuget package task ,please double check you have followed below requirements:
Specify .csproj files (for example, **\*.csproj) for simple projects. In this case:
The packager compiles the .csproj files for packaging.
You must specify Configuration to Package (see below).
You do not have to check in a .nuspec file. If you do check one in, the packager honors its settings and replaces tokens such as $id$ and
$description$.
Specify .nuspec files (for example, **\*.nuspec) for more complex projects, such as multi-platform scenarios in which you need to
compile and package in separate steps. In this case:
The packager does not compile the .csproj files for packaging.
Each project is packaged only if it has a .nuspec file checked in.
The packager does not replace tokens in the .nuspec file (except the element, see Use build number to version package,
below). You must supply values for elements such as and
. The most common way to do this is to hardcode the
values in the .nuspec file.
Please double check your arguments , more details please refer this tutorial-- Pack NuGet packages.
Besides you could also enable verbose debug mode by adding system.debug=true to get a more detail build log info for troubleshooting.

Related

Nuget Packager Error - Access is denied

Using TFS 2015.3 I am trying to create nuget packages to share internally with TFS out-of-the-box Nuget Packager Task. However, it does not create packages and errors out complaining "Access is denied". Inline are its log
2017-04-12T20:46:59.3533843Z Set workingFolder to default: C:\Downloads\TFS Agent installer\agent\tasks\NuGetPackager\0.1.58
2017-04-12T20:46:59.3846316Z Executing the powershell script: C:\Downloads\TFS Agent installer\agent\tasks\NuGetPackager\0.1.58\NuGetPackager.ps1
2017-04-12T20:46:59.6033861Z Getting version number from build
2017-04-12T20:46:59.6033861Z BUILD_BUILDNUMBER: 0.1.0.12
2017-04-12T20:46:59.6346370Z Version: 0.1.0.12
2017-04-12T20:46:59.6346370Z Checking pattern is specified
2017-04-12T20:46:59.6502638Z No Pattern found in solution parameter.
2017-04-12T20:46:59.6502638Z Found files: 1
2017-04-12T20:46:59.6502638Z --File: "E:\WebWork\10\s\Dev\DDS\DDSCommon\DDSCommon.csproj"
2017-04-12T20:46:59.6502638Z Creating Nuget Arguments:
2017-04-12T20:46:59.6658895Z --ARGS: pack "E:\WebWork\10\s\Dev\DDS\DDSCommon\DDSCommon.csproj" -OutputDirectory "\\Server\Nuget\DDS\" -Properties Configuration=Release -version 0.1.0.12
2017-04-12T20:46:59.6658895Z Invoking nuget with pack "E:\WebWork\10\s\Dev\DDS\DDSCommon\DDSCommon.csproj" -OutputDirectory "\\Server\Nuget\DDS\" -Properties Configuration=Release -version 0.1.0.12 on E:\WebWork\10\s\Dev\DDS\DDSCommon
2017-04-12T20:46:59.6658895Z \\Server\nuget\ pack "E:\WebWork\10\s\Dev\DDS\DDSCommon\DDSCommon.csproj" -OutputDirectory "\\Server\Nuget\DDS\" -Properties Configuration=Release -version 0.1.0.12
2017-04-12T20:46:59.6815141Z ##[error]Access is denied
we are using Internal NuGet Repo which is just a shared directory on our server.
On research could not find any posts related to it. Any suggestions please.
Update from OP
Issue fixed by leave blank of Path to Nuget.exe field.
Path to NuGet.exe
(Optional) Path to your own instance of NuGet.exe. If you specify
this argument, you must have your own strategy to handle
authentication.
According to the error info Access is denied. Please make sure your build service account have enough permission to access \\Server\Nuget\DDS\
Package Folder
(Optional) Specify the folder where you want to put the packages. You
can use a variable such as $(Build.StagingDirectory)\packages
If you leave it empty, the package will be created in the same
directory that contains the .csproj or .nuspec file.
You could also give a try with some other variable or leave it empty of the package folder in the nuget package task. To narrow down if the issue is related to shared directory \\Server\Nuget\DDS\ on your server.

Restore nuget packages in msbuild 15 project

I'd like to restore the nuget packages from a private feed (vsts internal feed) in a solution consisting of msbuild 15 projects, and subsequently build (and pack) the projects.
I'm using the VS 2017 hosted agent which I need to build.
I've tried restoring with msbuild with (the deprecated) package restore enabled. This results in no packages being restored. The relevant part of the logs:
2017-04-03T12:21:23.5543508Z ##[warning]The 'Restore NuGet Packages' option is deprecated. To restore NuGet packages in your build, add a NuGet Installer task to your build definition.
2017-04-03T12:21:23.5803410Z ##[command]"C:\LR\MMS\Services\mms\TaskAgentProvisioner\Tools\agents\2.115.0\externals\nuget\NuGet.exe" restore "C:\a\1\s\mysolution.sln" -NonInteractive
2017-04-03T12:21:24.5231560Z MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.
I've tried restoring with the nuget installer task. This fails with
2017-04-03T12:21:05.3231625Z [command]C:\a_tasks\NuGetInstaller_333b11bd-d341-40d9-afcf-b32d5ce6f23b\0.2.29\node_modules\nuget-task-common\NuGet\3.5.0\NuGet.exe restore -NonInteractive C:\a\1\s\mysolution.sln -Verbosity Detailed -msbuildversion 15
2017-04-03T12:21:07.5100892Z NuGet Version: 3.5.0.1938
2017-04-03T12:21:07.8293660Z System.AggregateException: One or more errors occurred.
---> NuGet.CommandLine.CommandLineException: Failed to load msbuild Toolset
---> System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
note that I pass in msbuildversion -15 as additional argument, but it seems nuget tries to load msbuild 14.
I've tried restoring with the dontnet cli dotnet restore. This fails with
2017-04-03T12:21:08.3424716Z [command]C:\Program Files\dotnet\dotnet.exe restore C:\a\1\s\path\to\my\csproj
2017-04-03T12:21:12.8146350Z Restoring packages for C:\a\1\s\path\to\my\csproj...
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Unable to load the service index for source https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json. [C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8146350Z C:\Program Files\dotnet\sdk\1.0.0\NuGet.targets(97,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\a\1\s\path\to\my\csproj]
2017-04-03T12:21:12.8176375Z ##[error]Dotnet command failed with non-zero exit code: 1.
The nuget.config in my solution directory is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<add key="VSTS Tools Feed" value="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" />
</packageSources>
<apikeys>
<add key="https://myvstsaccount.pkgs.visualstudio.com/_packaging/Toolsfeed/nuget/v3/index.json" value="<A PAT generated from an account with access to the feed>" />
</apikeys>
</configuration>
and the logs of the tasks show that the config is used.
Locally package restore works fine from VS, or with the nuget cli of nuget 4.0.
What task should I use to restore packages for msbuild 15 projects, and how can I configure authentication?
Restoring nuget packages defined as PackageReference elements in csproj project definitions requires nuget 4.0, which isn't included on the hosted build agents.
You can work around this restriction by including the nuget 4.0 binary in your source control tree, and referring to that binary within the package restore task as a custom NuGet version.
For example, when you include the nuget 4.0 binary in a file called nuget4.0.exe in the root directory of your source tree, you can specify the path as $(Build.SourcesDirectory)/nuget4.0.exe.
And there is a relate question here for you to refer.

VSTS Automated Build NuGet Packager/Publisher

My package builds successfully and is uploaded to the Packages feed in VSTS however I can't seem to figure out how to edit the Description and Author of the package so that my set values show in the Package feed.
From what I read I put my content in the NuGet Packager under additional build properties and when I look at the log file I see this:
...NuGet.exe pack "...csproj" -OutputDirectory "..." -Properties Configuration=release;Description="My Description";Authors="Me";Owners="My Company"
From the documentation I believe I did this right(but clearly I did not). It does seem a bit confusing as to what goes in "Additional build properties" vs NuGet Arguments.
Again my goal is get the Description and Author that I set to be viewable from the NuGet Package Manager within Visual Studio.
You could create a package according to the .nuspec file.
Steps:
Generate .nuspec file for your project (command: nugget spec).
For example: (Include author and description token)
<?xml version="1.0"?>
<package >
<metadata>
<id>CommLib1</id>
<version>1.0.0.6</version>
<title>CommLib1</title>
<authors>$author$</authors>
<owners>$author$</owners>
<licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
<projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
<iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>$description$</description>
<releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
<copyright>Copyright 2016</copyright>
<tags>Tag1 Tag2</tags>
</metadata>
</package>
Include this file to source control
Specify Nuget Arguments (token in step 1) of Nuget Packager build step
Update1:
In general, you just need to update AssemblyInfo.cs file of your project (Author=>AssemblyCompany; Description=>AssemblyDescription; Version=>AssemblyVersion), it creates package according to this data unless it can't retrieve metadata from your assembly (I have a project has this issue).
So, steps:
Make sure nuget could retrieve necessary metadata by creating package through nuget.exe command directly in your local/build machine (nuget pack [XX].csproj)
Create a build definition (1. Visual Studio Build 2. Nuget Packager with default value 3. Nuget Publisher)
If it's building the package then there are no problems with your NuGet Packager build step. Two things need to change though.
In order to specify properties like you are doing there MUST be a tokenized *.nuspec file in the same directory as the solution file with the same name and of course the *.nuspec file needs to be checked in to VSTS/TFS.
The token name for description can't be Description.
For more details on the *.nuspec file please see the solution here:
Nuget.exe pack WARNING: Description was not specified. Using 'Description'

VSO using Nuget packager build agent fails with invalid properites

I'm using VSO to package a simple DLL and the publish it to an internal feed, unfortunately during the packaging stage build it reports success but I get no artifact to publish
In the log file on for the publish it states the packing includes invalid arguments (Log 2016-02-27T09:07:35.8808468Z) as a result the publisher can't file any .nupkg file to publish.
I'm not sure where I'm going wrong. Its as if the nuget.exe is the wrong version or do it need to include anything in my solution
this is just a basic .enter image description herecsproj library with one static function for testing the process.
packager log
2016-02-27T09:07:35.2714664Z Set workingFolder to default: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\NuGetPackager\0.1.57
2016-02-27T09:07:35.2714664Z Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\tasks\NuGetPackager\0.1.57\NuGetPackager.ps1
2016-02-27T09:07:35.4277177Z Checking pattern is specified
2016-02-27T09:07:35.4433431Z No Pattern found in solution parameter.
2016-02-27T09:07:35.4433431Z Found files: 1
2016-02-27T09:07:35.4589718Z --File: "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj"
2016-02-27T09:07:35.4589718Z Creating Nuget Arguments:
2016-02-27T09:07:35.4589718Z --ARGS: pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu
2016-02-27T09:07:35.4589718Z Invoking nuget with pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu on C:\a\1\s\NugetTestLibrary
2016-02-27T09:07:35.4747124Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\default\agent\worker\tools\NuGet.exe pack "C:\a\1\s\NugetTestLibrary\NugetTestLibrary.csproj" -OutputDirectory "C:\a\1\a" -Properties Configuration=${BuildConfiguration};Platform any cpu
2016-02-27T09:07:35.8808468Z pack: invalid arguments.
2016-02-27T09:07:35.8964722Z usage: nuget pack <nuspec | project> [options]
2016-02-27T09:07:35.8964722Z Creates a NuGet package based on the specified nuspec or project file.
2016-02-27T09:07:35.8964722Z Specify the location of the nuspec or project file to create a package.
2016-02-27T09:07:35.8964722Z options:
2016-02-27T09:07:35.8964722Z -OutputDirectory Specifies the directory for the created NuGet package file. If not specified, uses the current directory.
2016-02-27T09:07:35.8964722Z -BasePath The base path of the files defined in the nuspec file.
2016-02-27T09:07:35.8964722Z -Verbose Shows verbose output for package building.
2016-02-27T09:07:35.8964722Z -Version Overrides the version number from the nuspec file.
2016-02-27T09:07:35.9120964Z -Exclude + Specifies one or more wildcard patterns to exclude when creating a package.
2016-02-27T09:07:35.9120964Z -Symbols Determines if a package containing sources and symbols should be created. When specified with a nuspec, creates a regular NuGet package file and the corresponding symbols package.
2016-02-27T09:07:35.9120964Z -Tool Determines if the output files of the project should be in the tool folder.
2016-02-27T09:07:35.9120964Z -Build Determines if the project should be built before building the package.
2016-02-27T09:07:35.9120964Z -NoDefaultExcludes Prevent default exclusion of NuGet package files and files and folders starting with a dot e.g. .svn.
2016-02-27T09:07:35.9120964Z -NoPackageAnalysis Specify if the command should not run package analysis after building the package.
2016-02-27T09:07:35.9120964Z -ExcludeEmptyDirectories Prevent inclusion of empty directories when building the package.
2016-02-27T09:07:35.9120964Z -IncludeReferencedProjects Include referenced projects either as dependencies or as part of the package.
2016-02-27T09:07:35.9120964Z -Properties + Provides the ability to specify a semicolon ";" delimited list of properties when creating a package.
2016-02-27T09:07:35.9120964Z -MinClientVersion Set the minClientVersion attribute for the created package.
2016-02-27T09:07:35.9120964Z -MSBuildVersion Specifies the version of MSBuild to be used with this command. Supported values are 4, 12, 14. By default the MSBuild in your path is picked, otherwise it defaults to the highest installed version of MSBuild.
2016-02-27T09:07:35.9120964Z -Help (?) help
2016-02-27T09:07:35.9120964Z -Verbosity Display this amount of details in the output: normal, quiet, detailed.
2016-02-27T09:07:35.9120964Z -NonInteractive Do not prompt for user input or confirmations.
2016-02-27T09:07:35.9120964Z For more information, visit http://docs.nuget.org/docs/reference/command-line-reference
Unfortunately I copied the Configuration=${BuildConfiguration} parameter incorrectly (use {} instead of ()), I also had to make other changes , I didn't require the platform parameter. I was also packaging to the incorrect folder.

Nuget pack csproj with dependencies on other csproj

I have two projects
A.csproj
B.csproj
where B references A (reference to project in solution)
I want to automate creation of packages, where package B will contain dependecy to package A
I've generated nuspec using nuget spec A.csproj and created package using nuget pack A.csproj. The same for project B.
however B.nuspec does not contain dependecy to nuget package A?
I want to automate creation of nuget packages on TFS build server, where assembly version is determined at build time.
In package B, how to add dependency to package A with correct version?
Firstly, to add the referenced projects as part of the package, you need to use the IncludeReferencedProjects option.
The command line is something like "nuget pack A.csproj -IncludeReferencedProjects"
Secondly, as you want to create NuGet packages during TFS build process, you need to create one PowerShell script which is similar to the followings, and include the PowerShell script in the Pre-build script (Assume you're using TFS2013 or TFS2015).
$projectFile = "project.csproj"
$nugetPath = “NuGet.exe"
$version = $Env:TF_BUILD_BUILDNUMBER
Write-Host ("packing $projectFile...")
& $nugetPath pack "$projectFile" -Version $version -Symbols -IncludeReferencedProjects