Hi, i'm trying to use the GitVersion provide variables within the NugetPackager task, but it seems that the variable name is passed as an argument to the task?
You can pass the following to the NuGet Arguments in the Advanced section of the NuGet Packager task:
-Version $(GitVersion.NuGetVersion)
It is not working, i got the following error message in the Nuget Packager log:
##[error]'$(GitVersion.NuGetVersion)' is not a valid version string.
##[error]Parameter name: version
##[error]Unexpected exit code 1 returned from tool NuGet.exe
This is my Advanced argument line:
-BasePath $(Build.SourcesDirectory)\bin\$(BuildConfiguration) -Version $(GitVersion.NuGetVersion)
It seems that the variable is not resolved
2015-10-05T12:40:19.9426002Z Creating Nuget Arguments:
2015-10-05T12:40:19.9546014Z --ARGS: pack C:\TfsData\Build\_work\bd47983a\Datacoll.HeaderFooter\SAPATG.Datacoll.HeaderFooter\NuGetPackageSupport\SAPATG.Datacoll.HeaderFooter.TF.nuspec -OutputDirectory C:\TfsData\Build\_work\bd47983a\Artifacts\staging -Properties Configuration= -BasePath C:\TfsData\Build\_work\bd47983a\Datacoll.HeaderFooter\bin\debug -Version $(GitVersion.NuGetVersion)
How are you running GitVersion and which version?
You need to use the GitVersion VSO task to make this work, and which obviously needs to run before the NuGet Packager task (there's some documentation available here)
GitVersion VSO Task 3.1.2 and GitVersion Step is before Nuget Packager Step
Looks fine to me...
What's the output of the GitVersion Task?
Are you on the hosted build agent or on a private agent?
I'm running on TF2015. Here is the output fro the GitVersion task
2015-10-05T12:40:06.2292290Z Executing the following commandline. (workingFolder = C:\Program Files\Microsoft Team Foundation Server 14.0\Build\tasks\GitVersion\3.1.2)
2015-10-05T12:40:06.2292290Z C:\Program Files\Microsoft Team Foundation Server 14.0\Build\tasks\GitVersion\3.1.2\GitVersion.exe "C:\TfsData\Build\_work\bd47983a\Datacoll.HeaderFooter" /output buildserver /updateAssemblyInfo true /nofetch
2015-10-05T12:40:06.2302291Z Error message highlight pattern:
2015-10-05T12:40:06.2302291Z Warning message highlight pattern:
2015-10-05T12:40:06.3002361Z INFO [10/05/15 14:40:06:29] Working directory: C:\TfsData\Build\_work\bd47983a\Datacoll.HeaderFooter
2015-10-05T12:40:06.3042365Z INFO [10/05/15 14:40:06:30] Applicable build agent found: 'VsoAgent'.
2015-10-05T12:40:06.3052366Z INFO [10/05/15 14:40:06:30] Branch from build environment: refs/heads/develop
2015-10-05T12:40:06.3782439Z INFO [10/05/15 14:40:06:37] One remote found (origin -> 'http://xxxx/tfs/DefaultCollection/_git/Datacoll.HeaderFooter').
2015-10-05T12:40:06.3802441Z INFO [10/05/15 14:40:06:37] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2015-10-05T12:40:06.4282489Z INFO [10/05/15 14:40:06:42] Creating local branch refs/heads/develop
2015-10-05T12:40:06.4972558Z INFO [10/05/15 14:40:06:49] Skipping update of 'refs/remotes/origin/develop' as it already matches the remote ref.
2015-10-05T12:40:06.5062567Z INFO [10/05/15 14:40:06:49] Skipping update of 'refs/remotes/origin/master' as it already matches the remote ref.
2015-10-05T12:40:06.5072568Z INFO [10/05/15 14:40:06:49] HEAD points at branch 'refs/heads/develop'.
2015-10-05T12:40:06.5072568Z INFO [10/05/15 14:40:06:49] Project root is: C:\TfsData\Build\_work\bd47983a\Datacoll.HeaderFooter
2015-10-05T12:40:06.5162577Z INFO [10/05/15 14:40:06:51] Using latest commit on specified branch
2015-10-05T12:40:06.5432604Z INFO [10/05/15 14:40:06:54] Running against branch: develop (878cd6abedc664f1919e9915db8d573b18949690)
2015-10-05T12:40:06.5552616Z INFO [10/05/15 14:40:06:55] Begin: Calculating base versions
2015-10-05T12:40:06.5922653Z INFO [10/05/15 14:40:06:59] Fallback base version: 0.1.0 with commit count source 3c2d4f739cff930d2f3b57ca8a8e19822605bf26
2015-10-05T12:40:06.6742735Z INFO [10/05/15 14:40:06:67] Git tag '1.0.13217.101': 1.0.13217+101 with commit count source 85d1a2986ddfa20f1a82ff6285082253e6126749
2015-10-05T12:40:06.6892750Z INFO [10/05/15 14:40:06:68] Git tag '1.0.13149.2': 1.0.13149+2 with commit count source dd2212216a3d65e38529684e047cb5d2bc84be3b
2015-10-05T12:40:06.7032764Z INFO [10/05/15 14:40:06:70] Git tag '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7272788Z INFO [10/05/15 14:40:06:72] Merge target tagged '1.0.13217.101': 1.0.13217+101 with commit count source 85d1a2986ddfa20f1a82ff6285082253e6126749
2015-10-05T12:40:06.7462807Z INFO [10/05/15 14:40:06:74] Merge target tagged '1.0.13149.2': 1.0.13149+2 with commit count source dd2212216a3d65e38529684e047cb5d2bc84be3b
2015-10-05T12:40:06.7582819Z INFO [10/05/15 14:40:06:75] Merge target tagged '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] Found multiple base versions which will produce the same SemVer (1.1.0), taking oldest source for commit counting (Git tag '1.0.0.0')
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] Base version used: Merge target tagged '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] End: Calculating base versions (Took: 234.02ms)
2015-10-05T12:40:06.8172878Z INFO [10/05/15 14:40:06:81] 59 commits found between b872ed08bd02ba97e474a89f93f605aa274ff910 and 878cd6abedc664f1919e9915db8d573b18949690
2015-10-05T12:40:06.8332894Z INFO [10/05/15 14:40:06:83] Applicable build agent found: 'VsoAgent'.
2015-10-05T12:40:06.8332894Z Executing GenerateSetVersionMessage for 'VsoAgent'.
2015-10-05T12:40:06.8342895Z Executing GenerateBuildLogOutput for 'VsoAgent'.
2015-10-05T12:40:06.8412902Z Updating assembly info files
The agent that ships with TFS2015 won’t support the set variable feature necessary for this to work.
From: Pitt [mailto:[email protected]]
Sent: Monday, October 5, 2015 9:31 AM
To: Microsoft/vso-agent-tasks [email protected]
Subject: Re: [vso-agent-tasks] Nuget Packager - how to specify GitVersion variables? (#613)
I'm running on TF2015. Here is the output fro the GitVersion task
2015-10-05T12:40:06.2292290Z Executing the following commandline. (workingFolder = C:\Program Files\Microsoft Team Foundation Server 14.0\Build\tasks\GitVersion\3.1.2)
2015-10-05T12:40:06.2292290Z C:\Program Files\Microsoft Team Foundation Server 14.0\Build\tasks\GitVersion\3.1.2\GitVersion.exe "C:\TfsData\Build_work\bd47983a\Datacoll.HeaderFooter" /output buildserver /updateAssemblyInfo true /nofetch
2015-10-05T12:40:06.2302291Z Error message highlight pattern:
2015-10-05T12:40:06.2302291Z Warning message highlight pattern:
2015-10-05T12:40:06.3002361Z INFO [10/05/15 14:40:06:29] Working directory: C:\TfsData\Build_work\bd47983a\Datacoll.HeaderFooter
2015-10-05T12:40:06.3042365Z INFO [10/05/15 14:40:06:30] Applicable build agent found: 'VsoAgent'.
2015-10-05T12:40:06.3052366Z INFO [10/05/15 14:40:06:30] Branch from build environment: refs/heads/develop
2015-10-05T12:40:06.3782439Z INFO [10/05/15 14:40:06:37] One remote found (origin -> 'http://xxxx/tfs/DefaultCollection/_git/Datacoll.HeaderFooter').
2015-10-05T12:40:06.3802441Z INFO [10/05/15 14:40:06:37] Skipping fetching, if GitVersion does not calculate your version as expected you might need to allow fetching or use dynamic repositories
2015-10-05T12:40:06.4282489Z INFO [10/05/15 14:40:06:42] Creating local branch refs/heads/develop
2015-10-05T12:40:06.4972558Z INFO [10/05/15 14:40:06:49] Skipping update of 'refs/remotes/origin/develop' as it already matches the remote ref.
2015-10-05T12:40:06.5062567Z INFO [10/05/15 14:40:06:49] Skipping update of 'refs/remotes/origin/master' as it already matches the remote ref.
2015-10-05T12:40:06.5072568Z INFO [10/05/15 14:40:06:49] HEAD points at branch 'refs/heads/develop'.
2015-10-05T12:40:06.5072568Z INFO [10/05/15 14:40:06:49] Project root is: C:\TfsData\Build_work\bd47983a\Datacoll.HeaderFooter
2015-10-05T12:40:06.5162577Z INFO [10/05/15 14:40:06:51] Using latest commit on specified branch
2015-10-05T12:40:06.5432604Z INFO [10/05/15 14:40:06:54] Running against branch: develop (878cd6abedc664f1919e9915db8d573b18949690)
2015-10-05T12:40:06.5552616Z INFO [10/05/15 14:40:06:55] Begin: Calculating base versions
2015-10-05T12:40:06.5922653Z INFO [10/05/15 14:40:06:59] Fallback base version: 0.1.0 with commit count source 3c2d4f739cff930d2f3b57ca8a8e19822605bf26
2015-10-05T12:40:06.6742735Z INFO [10/05/15 14:40:06:67] Git tag '1.0.13217.101': 1.0.13217+101 with commit count source 85d1a2986ddfa20f1a82ff6285082253e6126749
2015-10-05T12:40:06.6892750Z INFO [10/05/15 14:40:06:68] Git tag '1.0.13149.2': 1.0.13149+2 with commit count source dd2212216a3d65e38529684e047cb5d2bc84be3b
2015-10-05T12:40:06.7032764Z INFO [10/05/15 14:40:06:70] Git tag '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7272788Z INFO [10/05/15 14:40:06:72] Merge target tagged '1.0.13217.101': 1.0.13217+101 with commit count source 85d1a2986ddfa20f1a82ff6285082253e6126749
2015-10-05T12:40:06.7462807Z INFO [10/05/15 14:40:06:74] Merge target tagged '1.0.13149.2': 1.0.13149+2 with commit count source dd2212216a3d65e38529684e047cb5d2bc84be3b
2015-10-05T12:40:06.7582819Z INFO [10/05/15 14:40:06:75] Merge target tagged '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] Found multiple base versions which will produce the same SemVer (1.1.0), taking oldest source for commit counting (Git tag '1.0.0.0')
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] Base version used: Merge target tagged '1.0.0.0': 1.0.0+0 with commit count source b872ed08bd02ba97e474a89f93f605aa274ff910
2015-10-05T12:40:06.7892850Z INFO [10/05/15 14:40:06:78] End: Calculating base versions (Took: 234.02ms)
2015-10-05T12:40:06.8172878Z INFO [10/05/15 14:40:06:81] 59 commits found between b872ed08bd02ba97e474a89f93f605aa274ff910 and 878cd6abedc664f1919e9915db8d573b18949690
2015-10-05T12:40:06.8332894Z INFO [10/05/15 14:40:06:83] Applicable build agent found: 'VsoAgent'.
2015-10-05T12:40:06.8332894Z Executing GenerateSetVersionMessage for 'VsoAgent'.
2015-10-05T12:40:06.8342895Z Executing GenerateBuildLogOutput for 'VsoAgent'.
2015-10-05T12:40:06.8412902Z Updating assembly info files
—
Reply to this email directly or view it on GitHubhttps://na01.safelinks.protection.outlook.com/?url=https%3a%2f%2fgithub.com%2fMicrosoft%2fvso-agent-tasks%2fissues%2f613%23issuecomment-145528045&data=01%7c01%7cChris.Patterson%40microsoft.com%7cef798581317540bbf94508d2cd8930d8%7c72f988bf86f141af91ab2d7cd011db47%7c1&sdata=f4YJm%2b%2fIB36AsGMcQ1mA3082EeG8gFfG%2fOwviZFq8CI%3d.
This won't work on TFS2015 on prem as mentioned by @chrisrpatterson due to limitation in the agent. There was a note in the GitVersion documentation about this, which was removed since this is implemented now in VSO, but might be a good idea to add it back for the On-Prem case.
As a workaround you can use environment variables. The GitVersion task also writes environment variables which you can use in a custom script later to call ´NuGet.exe pack´ directly without using the NuGet Packager task
I added a note about this to the GitVersion documentation (GitTools/GitVersion#667)
I'll try the workaround. Is there any way to update the OnPrem agent, or do i need to wait for the next release?
@Pitterling You can download an agent from a VSO instance and manually update your on-premise agents. (Paste the files over the top).
You don't want to be downloading agents from one instance (like VSO) and applying it to other instances (on-prem etc...). The agent should be downloaded from the instance of TFS it is serving.
@Pitterling @RDalziel that is not a supported option. It is very likely that the agent we have in VSO will not work with the on-prem server. You must use the version of the agent that ships with your server.
Apologies chaps, what issues do you see here? I've already took this route as the workarounds for things like GitVersion were not ideal.
The behavior is undefined/untested. It may work, may not. The design is for agents to get pulled forward via an auto update process downloaded from your service. The auto update process may alter configs/layout on disk, whatever. That future agent might call REST apis that don't exist, etc... The primary focus for agents is on forward compat so they can lazily get upgraded (via task minimum agent demand, on restart or eventually a scheduled job)
Thanks Bryan, cheers for the additional info! I haven't had any issues to report yet but i'll know to revert back to the in-the-box on premise version should they occur.
@Pitterling is this resolved for you? We're investigating some work to make versioning NuGet packages easier. In the meantime this thread has the best practices.
Yes, On TFS i'm using the workaround and on VSTS the "set variable feature" thx.
Are there any updates on versioning nuget packages easier ?
Bruno
@brunobertechini the "NuGet Packager" has been enhanced .. see screenshot
I'm using the GitVersion task to create the Environment variable which is used here:

@Pitterling are you saying this works for you? I have a similar setup on VSO and get the following error
2016-09-30T01:01:56.2152237Z ##[error]Missing option value for: '-version'

Edit: to get it to work i had to add -version $(GitVersion.NuGetVersion) to the nuget arguments section.
@robbihun I think environment variables are called GitVersion_NuGetVersion (with _ instead of .)
Since you are using the GitVersion VSTS task you can also just pass the following argument in the NuGet Arguments field: -Version $(GitVersion.NuGetVersion).
This will pass the VSTS variable which was set by the GitVersion VSTS task to NuGet.
@robbihun @pascalberger thats right. haven't checked for a long time ... GitVersion_NuGetVersion works for me.
Also using the Environment Variable Build.BuildNumber (which is updated by GitVersion) is passed as empty...
Most helpful comment
@robbihun I think environment variables are called GitVersion_NuGetVersion (with _ instead of .)
Since you are using the GitVersion VSTS task you can also just pass the following argument in the NuGet Arguments field:
-Version $(GitVersion.NuGetVersion).This will pass the VSTS variable which was set by the GitVersion VSTS task to NuGet.