We're running into a problem with our NuGet pipelines on GitHub. We have it set to run a step to build the project, and NuGet pack it with a specific version (the RC version generally something like 1.0.0-rc.1) this works fine, and we can then pass the artifact to the RC step and upload it to where it needs to go using NuGet push.
The problem comes in when we're trying to then move that package from RC into GA (the desired flow being: build > RC > GA), we want to take the same exact package and modify the version so it no longer has the RC tag (stripping it down to 1.0.0), however I haven't been able to find a clean way to do this. The current workaround is to take the exact same commit and rebuild it with the GA version but we would much rather just modify the RC version to have the correct version number.
Is there a NuGet command or something that I'm missing to accomplish this? I considered downloading the nupkg file, installing it to an output directory and then repacking it with the correct version but I was hoping there may be a better way.
Few options using Action Update Helpers,
the diff. is helpful depending on what you are publishing, nuget libs you are publishing vs. custom libs - since you did not share your sample yaml/code, I am sharing both.
Option 1: use the Release Tag Updater helper lib. from here or a newer one here from Github or Market Place
Helpful for your own, i.e if you publish NUGET libs
In your yaml configuration file for github actions, in the stage that you want to rename you can use the tag option with passed in values
# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: YourProject/YourProject.csproj
# NuGet package id, used for version detection & defaults to project name
# PACKAGE_NAME: YourProject
# API key to authenticate with NuGet server
NUGET_KEY: ${{secrets.NUGET_API_KEY}}
# NuGet server uri hosting the packages, defaults to https://api.nuget.org
# NUGET_SOURCE: https://api.nuget.org
# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props
# Regex pattern to extract version info in a capturing group
# VERSION_REGEX: <Version>(.*)<\/Version>
# Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX
# VERSION_STATIC: 1.0.0
# Flag to toggle git tagging, enabled by default
# TAG_COMMIT: true
# Format of the git tag, [*] gets replaced with actual version
# TAG_FORMAT: v*
Option 2: Modify/roll your own yaml properties file
IMHO for your Custom Libs, i.e. if you need something beyond the standard yaml properties and you need some more.
For e.g. in your final release stage, use the yaml deploy section to name it what you want using this lib.
# your previous yaml code ... there should be a section with the below tage configured and it will look for it an update.
The main differences is one targets the major and minor release of the tag names and helpful for Nuget packages.
The second one allows you to create something beyond and custom as a tag.
Related
I have created a branch on tfs2012 right next to the folder containing the main solution. Everything is identical.
I also have a working TeamCity build configuration for the main solution. But when I clone the build configuration and change only the source file path in the build step, i get the following error:
The 'System.Net.NameResolution 4.0.0' package requires NuGet client
version '2.12' or above, but the current NuGet version is
'2.8.60717.93'.
NuGet's docs have a page dedicated to nuget.config, which has a large sample at the end.
For tooling support, if you have installed the .NET Core SDK, you can use dotnet new nugetconfig on the command line to create a file from a template. Tooling to modify this file isn't yet in the dotnet cli, so you'll need to download nuget.exe from nuget.org, then you can use commands like "nuget sources add" or "nuget config" to change values, just be sure to use the -ConfigFile paramater, as nuget.exe defaults to your user profile nuget.config, even when there's a nuget.config file in the current directory.
Ultimately it's just an XML file, so I feel like most people just edit it directly using samples online or the nuget.config reference I linked to as a guide.
Note
If there is an easier way to create prerelease packages please let me know!
I am using Visual Studio Team Services and have setup a nuget pack and publish step.
I have a build variable called $(BuildSuffix) that allows me to tag build-specific variables onto the end of the build number format like so
$(Build.DefinitionName)_1.0.$(date:yyyy)$(date:MM)$(date:dd)$(rev:.r)$(BuildSuffix)
The idea then is that I can set $(BuildSuffix) to -beta so that my final build version might be Build_1.0.20170119.2-beta.
According to the nuget documentation here, appending -beta to a build number will create a prerelease package. The build in VSTS comes out with -beta appended but the nuget pack stage never seems to contain it. It always comes out as the exact version number but without the -beta tag.
My nuspec files look like this:
<package >
<metadata>
<id>MyCompany.Data</id>
<version>$version$</version>
My NuGet package step looks like this:
After some research and bashing my head against a brick wall I figured out how. You have to:
Configure a local Build Agent
Install Nuget CLI
On Nuget Packager Task set Path To NuGet.exe to the NuGet CLI
Set NuGet Arguments on the same screen to -suffix beta
With new NuGet task(version 2) you can specify Additional build properties and there you can pass your custom build number directly instead of using -suffix NuGet argument. Additional build properties are substituting $token$ with supplied value in nuspec and you are free to change whatever you want in there.
I also see it on your screenshot, but I never tried to use it like this with older NuGet tasks as those are deprecated now.
Maybe it will be helpful to try import NuGet Packaging Task Group definition I am using on my private projects. Check it out Here.
I've got a build running in VSTS which is restoring NuGet packages from both nuget.org and a custom feed in VSTS. The custom feed is in the solutions NuGet.config as a <packageSource>, along with the user name and password in <packageSourceCredentials>
The build, including the restore, is working Ok, but there is a warning ...
2016-10-12T16:18:57.6589001Z ##[warning]To connect to NuGet feeds
hosted in your Team Services account/TFS project collection with
NuGet 3.1 or below, edit your build definition to specify a path
to a NuGet.config containing the package sources you wish to use.
How can I remove this?
Based on my test, that warning remains even through using higher version of nugget (e.g. 3.3) or do not restore package from VSTS feed. (Hosted build agent has the same result).
You can’t remove it unless you custom a build task to restore package through command line.
I submit a issue here.
Update:
The issue has been updated.
I see the issue in the code coming from our transition from depending
on assets coming with the agent to being deployed with the task. You
can get around this for now until we get an official change out by
either (1) choosing to use the Nuget 3.5 version radio button in the
task config or (2) supplying a path to your nuget.config.
So, you can use Nuget 3.5 version or specify nuget.config file.
I have a build step in TeamCity 9.1 to push a .nupkg file to a hosted feed on myget.org, but it doesn't work with wildcards.
The build step is as follows:
mono /opt/NuGet2/NuGet.exe push %srcDir%/bin/release/Foo.1.0.0.nupkg -Source https://www.myget.org/F/<org_name>/api/v2/package
This works, but I don't want to explicitly set the version number in a build step because this will be incremented over time.
I tried adding a wildcard to the statement like this:
mono /opt/NuGet2/NuGet.exe push %srcDir%/bin/release/Foo.*.nupkg -Source https://www.myget.org/F/<org_name>/api/v2/package
But the wildcard (instead of 1.0.0) seems to break the TeamCity build agent and it gets stuck in a loop until I kill it manually.
How can I create the build step in TeamCity such that I don't need to hard-code a version number in it? Is there a way to omit the version number from the .nupkg file name or allow TeamCity to work with wildcard file names?
You can simply use the "NuGet Publish" runner type and in the "Packages" setting specify a wildcard for where the packages reside (For example: ManualTests/Artifacts/*.nupkg).
I have my build number format specified as :
$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)
This creates build Numbers in the format of "BuildDefinitionName_2015.11.11.1"
Where revision seems to be the number of times the build has run for that day.
I would like to be able to use this value in further build steps.
For example I am creating a nuget package with the nuget packager step and am using the option "Use build number to version the package"
This creates me packages similar to this "PackageName.2015.11.11.1.nupkg"
I then want to use the nuget publisher build step to publish this, but the problem is that over time you get more than one package in the package folder and the nuget publisher step uses a pattern for matching packages to publish.
ie
"PackageName.2015.11.11.1.nupkg"
"PackageName.2015.11.11.2.nupkg"
"PackageName.2015.11.11.3.nupkg"
Without being explicit about the file to publish, the publisher step will publish all these files.
I don't want this, I just want it to publish the file which matches the current build number.
So I would like to be able to set the build number parts in the pattern.
ie PackageName.$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r).nupkg
But it appears that these variables do not get substituted in the search path and come through as a literal match.
It seems strange that in the nuget package step it gives you the option to create packages by build number, but then does not allow you to match this in the nuget publish build step.
Nuget Packager step use PowerShell script to get the build number. The source code is here: https://github.com/Microsoft/vso-agent-tasks/blob/84746169f19b7c3e3f67c0efa1a546c4107055fa/Tasks/NugetPackager/NuGetPackager.ps1
If you do want to transfer the build number to Nuget Publish, you can add a PowerShell step in your build process to get the build version number. Refer to the build version related code in the Source Code for details.
And in the end of the PowerShell script, add code:
Write-Host "##vso[task.setvariable variable=bversion;]$NewVersion"
This code create a variable “bversion” with build version number filled. Then you can use variable $(bversion) in your Nuget Publish step.
I would suggest to do a clean checkout of the source code in each build, which will solve the problem of having old package files lying around in subsequent builds.
Otherwise there's the $(build.buildnumber) variable which contains the expanded value of the build number, but as long as you have additionally the $(BuildDefinitionName) in the build number you won't be able to use it for the file name. See here for a list of available predefined variables.