I'm trying to package one library after build to publish on my VSTS Packages feed.
But the task Nuget Packager is not working. I've tried lots of combinations of settings, but I could not make it works.
I've tried to package the library using .Net Core and .Net 4.6.2.
I'm getting the following error when trying to pack with .Net Core or .Net 4.6.2:
##[error]The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. d:\a\12\s\myproject.csproj
I'm using the following settings:
Agent: Hosted 2017
Build Number Format: $(date:yyyyMMdd).$(rev:.r).0
The .csproj for .net core is the following:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup Label="Globals">
<SccProjectName>SAK</SccProjectName>
<SccProvider>SAK</SccProvider>
<SccAuxPath>SAK</SccAuxPath>
<SccLocalPath>SAK</SccLocalPath>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>netcoreapp1.1</TargetFramework>
</PropertyGroup>
<Import Project="..\..\myproject.shared.projitems" Label="Shared" />
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.3.0" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.1" />
</ItemGroup>
</Project>
The complete log for .Net Core is:
2017-05-16T12:25:40.4059161Z ##[section]Starting: NuGet Packager
2017-05-16T12:25:40.4069169Z ==============================================================================
2017-05-16T12:25:40.4069169Z Task : NuGet Packager
2017-05-16T12:25:40.4069169Z Description : Creates nupkg outputs from csproj or nuspec files
2017-05-16T12:25:40.4069169Z Version : 0.1.72
2017-05-16T12:25:40.4069169Z Author : Lawrence Gripper
2017-05-16T12:25:40.4069169Z Help : [More Information](https://go.microsoft.com/fwlink/?LinkID=627416)
2017-05-16T12:25:40.4069169Z ==============================================================================
2017-05-16T12:25:42.1843658Z Preparing task execution handler.
2017-05-16T12:25:47.7782379Z Executing the powershell script: d:\a\_tasks\NuGetPackager_333b11bd-d341-40d9-afcf-b32d5ce6f24b\0.1.72\NuGetPackager.ps1
2017-05-16T12:25:48.1582506Z Find-Files -SearchPattern d:\a\12\s\**\*.csproj -RootFolder d:\a\12\s
2017-05-16T12:25:48.1582506Z
2017-05-16T12:25:48.1582506Z
2017-05-16T12:25:48.2452532Z C:\LR\MMS\Services\mms\TaskAgentProvisioner\Tools\agents\2.116.1\externals\nuget\NuGet.exe pack "d:\a\12\s\SpaceNeedle.NetFX\Net4\SpaceNeedle.NetFX.Net4\SpaceNeedle.NetFX.Net4.csproj" -OutputDirectory "d:\a\12\s" -Properties Configuration=release
2017-05-16T12:25:49.5712932Z MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.
2017-05-16T12:25:49.5712932Z Attempting to build package from 'SpaceNeedle.NetFX.Net4.csproj'.
2017-05-16T12:25:50.6143198Z Packing files from 'd:\a\12\s\SpaceNeedle.NetFX\Net4\SpaceNeedle.NetFX.Net4\bin\Release'.
2017-05-16T12:25:50.9343273Z Found packages.config. Using packages listed as dependencies
2017-05-16T12:25:50.9463282Z WARNING: Description was not specified. Using 'Description'.
2017-05-16T12:25:51.0333303Z Successfully created package 'd:\a\12\s\SpaceNeedle.NetFX.Net4.0.1.0.0.nupkg'.
2017-05-16T12:25:51.0763302Z C:\LR\MMS\Services\mms\TaskAgentProvisioner\Tools\agents\2.116.1\externals\nuget\NuGet.exe pack "d:\a\12\s\SpaceNeedle.NetFX\NetFX\SpaceNeedle.NetFX\SpaceNeedle.NetFX.csproj" -OutputDirectory "d:\a\12\s" -Properties Configuration=release
2017-05-16T12:25:51.4743413Z MSBuild auto-detection: using msbuild version '4.0' from 'C:\Windows\Microsoft.NET\Framework\v4.0.30319'.
2017-05-16T12:25:51.4863414Z Attempting to build package from 'SpaceNeedle.NetFX.csproj'.
2017-05-16T12:25:51.5313430Z ##[error]The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the <Project> element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. d:\a\12\s\SpaceNeedle.NetFX\NetFX\SpaceNeedle.NetFX\SpaceNeedle.NetFX.csproj
2017-05-16T12:25:51.5703444Z ##[error]System.Exception: Unexpected exit code 1 returned from tool NuGet.exe
2017-05-16T12:25:51.5703444Z at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeToolCmdlet.ProcessRecord()
2017-05-16T12:25:51.5713439Z at System.Management.Automation.CommandProcessor.ProcessRecord()
2017-05-16T12:25:51.5943443Z ##[error]PowerShell script completed with 1 errors.
2017-05-16T12:25:51.5953445Z ##[section]Finishing: NuGet Packager
Does anyone have idea of what is happening?
Thank you!
The NuGet packer step doesn't work on SDK-based csproj formats (usually .NET Standard or .NET Core projects).
The projects can be packed using a command line step to call dotnet pack or by using the .NET Core build step (which wraps the call to dotnet in a build step). Note that the command selector currently does not list pack, but the field accepts any input:
Related
I have ran into a strange problem and have been trying to fix for a couple of days. Locally, I can build my project just fine with the following nuspec file. The nuspec file is saved in the repo and copied local when built from the c# project and it is under a sub folder called "nugetcreation". Locally, I can run the nuspec file as is and it generates the nuget package.
Folder setup:
project
-project files
-nugetcreation
-readme and nuspec files
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
<metadata>
<id>my.Utility.TraceWriter</id>
<version>1.0.0-beta</version>
<title>my.Utility.TraceWriter</title>
<authors>justme</authors>
<owners>justme</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>custom trace items</description>
<releaseNotes>initial release</releaseNotes>
</metadata>
<files>
<file src="Content\MyReadMes\My.Utility.TraceWriter.md" target="content\net461\MyReadMes\My.Utility.TraceWriter.md" />
<file src="..\My.Utility.TraceWriter.dll" target="lib\net461\My.Utility.TraceWriter.dll" />
<file src="..\My.Utility.TraceWriter.pdb" target="lib\net461\My.Utility.TraceWriter.pdb" />
</files>
</package>
The problem:
When I am building an Azure Pipeline, I tell it to run the nuspec file and I am getting an error
##[error]The nuget command failed with exit code(1) and error(Error NU5019: File not found: '..\My.Utility.TraceWriter.dll'.
But it is absolutely being generated correctly from the vsbuild process
CopyFilesToOutputDirectory:
Copying file from "d:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\obj\Release\My.Utility.TraceWriter.dll" to "d:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\bin\Release\My.Utility.TraceWriter.dll"
The nuget creation step in the azure pipeline is pretty basic, nothing fancy. All of the fancy stuff I am keeping in the nuspec file. I am trying to get this to work on a basic project with the nuspec file because I have much more complicated nuget packaging coming later so this is my test version.
- task: NuGetCommand#2
displayName: 'Creating nuget package'
inputs:
command: 'pack'
packagesToPack: '**/*.nuspec'
versioningScheme: 'off'
arguments: '--configuration $(buildConfiguration)'
So far I have tried using:
**\My.Utility.TraceWriter.dll (no error, but no dlls are in the lib folder. acts as if that line is just skipped)
bin**\My.Utility.TraceWriter.dll
.\My.Utility.TraceWriter.dll
$configuration$\My.Utility.TraceWriter.dll
**\$configuration$\My.Utility.TraceWriter.dll
...nothing works. Does anyone have any ideas about why the azure pipeline doesn't accept the correct (..\My.Utility.TraceWriter.dll) relative path entry on the nuspec file and how to fix it?
My forehead hurts from banging my keyboard against it...
--EDIT--
A little more info. It appears that 2 things are happening when the nuget pack command is ran. The entire output is below but it looks like after the nuget successfully builds it is trying to pack it again and this time can't find the files??
Added file '_rels/.rels'.
Added file 'My.Utility.TraceWriter.nuspec'.
Added file 'content/net461/MyReadMes/My.Utility.TraceWriter.md'.
Added file 'lib/net461/My.Utility.TraceWriter.dll'.
Added file 'lib/net461/My.Utility.TraceWriter.pdb'.
Added file 'package/services/metadata/core-properties/f2a4d059fea6458dac5889de57641f5b.psmdcp'.
Successfully created package 'D:\a\1\a\My.Utility.TraceWriter.1.0.0-beta.nupkg'.
WARNING: NU5128: Some target frameworks declared in the dependencies group of the nuspec and the lib/ref folder do not have exact matches in the other location. Consult the list of actions below:
- Add a dependency group for .NETFramework4.6.1 to the nuspec
Attempting to pack file: D:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\nuget information\My.Utility.TraceWriter.nuspec
C:\hostedtoolcache\windows\NuGet\5.4.0\x64\nuget.exe pack "D:\a\1\s\My.Utility.TraceWriter\My.Utility.MethodTracer\nuget information\My.Utility.TraceWriter.nuspec" -NonInteractive -OutputDirectory D:\a\1\a -Properties Configuration=Release -Verbosity Detailed
Error NU5019: File not found: '..\My.Utility.TraceWriter.dll'.
NuGet Version: 5.4.0.6315
NuGet.Packaging.Core.PackagingException: File not found: '..\My.Utility.TraceWriter.dll'.
Stupid. the packagesToPack: '**/*.nuspec' is pulling both nuspecs: the one in source AND the one copied to the output bin folder.
redefining fixed the issue
I'm trying to build a multi-project solution in Azure DevOps for deployment to Azure. This solution builds fine on my local machine, but I get the following build error in Azure.
##[error]TCGTools.net\Controllers\SettingsController.cs(8,7): Error CS0246: The type or namespace name 'TCGSniperCore' could not be found (are you missing a using directive or an assembly reference?)
TCGSniperCore is a .netcore library in my solution. The MVC project references this library.
After skimming the full log file, I found that the solution is building the .netcore library in release mode, but then looks for the .dll in the debug folder.
Console output when building the library:
CopyFilesToOutputDirectory:
Copying file from "obj\Release\netcoreapp2.2\TCGSniperCore.dll" to
"bin\Release\netcoreapp2.2\TCGSniperCore.dll".
TCGSniperCore ->
D:\a\1\s\tcgsnipercore\bin\Release\netcoreapp2.2\TCGSniperCore.dll
Copying file from "obj\Release\netcoreapp2.2\TCGSniperCore.pdb" to
"bin\Release\netco
Console output when building the MVC project:
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2110,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "TCGSniperCore". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [D:\a\1\s\TCGTools.net\TCGTools.net.csproj]
For SearchPath "{HintPathFromItem}".
Considered "..\tcgsnipercore\bin\Debug\netcoreapp2.2\TCGSniperCore.dll", but it didn't exist.
For SearchPath "{RawFileName}".
Considered treating "TCGSniperCore" as a file name, but it didn't exist.
I have tried the following:
Ensuring both projects target .netcore2.2
Setting the Agent pool to Hosted VS2017 in Azure DevOps
Setting the BuildConfiguration variable to release
Reproducing on my local machine. I cannot. The solution builds fine.
Why is it looking for the assembly in /debug and not /release?
I found that it looks for the .dll based on the file path specified in the .csproj file. Edit the file (I used VS Code) and add/modify the hint path with $(configuration).
Before:
<ItemGroup>
<Reference Include="TCGSniperCore">
<HintPath>..\tcgsnipercore\bin\Debug\netcoreapp2.2\TCGSniperCore.dll</HintPath>
</Reference>
</ItemGroup>
After:
<ItemGroup>
<Reference Include="TCGSniperCore">
<HintPath>..\tcgsnipercore\bin\$(configuration)\netcoreapp2.2\TCGSniperCore.dll</HintPath>
</Reference>
</ItemGroup>
Thanks #D.J.
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.
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.
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'