Is it possible to use environment variables in dotnet_csproj section
I'm trying to better manage version numbers between the build itself and the assembly info in my dotnet core apps. In order to do so, I was attempting to set an environment variable for the application version, reset the version (using that application version) of the build using Update-AppveyorBuild, and then use that same variable in the patching process for csproj. It came out something like this:
dotnet_csproj:
patch: true
file: '**\*.csproj'
version: '$env:app_version'
package_version: '$env:app_version.{build}'
file_version: '$env:app_version.{build}'
assembly_version: '1.0.0'
But it doesn't seem to be working as I thought it would. I'm not seeing any errors (or the result, for that matter) in the logs, but the builds are failing with several errors that I can only assume are cascading from this (the build was working before this change, so it's not the project), and that it is a result of the assembly patching not succeeding or outputting something invalid:
C:\Users\appveyor\AppData\Local\Temp\1\NuGetScratch\4tbo4y1o.zlv.nugetrestore.targets(131,5): error MSB4018: The "WriteRestoreGraphTask" task failed unexpectedly.
So is it possible to use environment variables in the csproj patching section and how?
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
| ? | Show this help |
|---|---|
| ESC | Blurs the current field |
Comment Form
| r | Focus the comment reply box |
|---|---|
| ^ + ↩ | Submit the comment |
You can use Command ⌘ instead of Control ^ on Mac

1 Posted by Ilya Finkelshte... on 14 Feb, 2018 10:42 PM
You use PowerShell notation. We support the following notations right now:
2 Posted by jstafford on 15 Feb, 2018 12:23 AM
So it would be like this, then?
This seems to exhibit the same failure (not sure if coincedence. I still can't see what those values are resolving to
3 Posted by Ilya Finkelshte... on 15 Feb, 2018 12:31 AM
Try to remove
'', e.g.package_version: ${app_version}.{build}. Generally I would recommend to use UI and then Export YAML button to spend less time wrestling with YAML syntax.4 Posted by jstafford on 15 Feb, 2018 12:41 AM
It seems that the variable is not hydrating. Just to make sure my environment variable was declared correctly, I did as you suggested and used the UI to generate the value:
5 Posted by Ilya Finkelshte... on 15 Feb, 2018 01:03 AM
You found a bug :) https://github.com/appveyor/ci/issues/2078
Use
$(variable) or %variable%.%variable%will require''in YAML.6 Posted by jstafford on 15 Feb, 2018 01:28 AM
Ok thanks. So that resolved the error but now it is not filling in the Build number
I've tried:
and all are naming the nuget package 2.1.0 instead of 2.1.0.410
7 Posted by Ilya Finkelshte... on 15 Feb, 2018 01:55 AM
$(app_version).{build}and'%app_version%.{build}'should work. If not, send the whole YAML and build log.8 Posted by jstafford on 15 Feb, 2018 04:21 PM
Ok I figured it out. I didn't have in the csproj so it was getting skipped, I think. Once I put it in, the versions came out correct. Thanks!
9 Posted by Ilya Finkelshte... on 15 Feb, 2018 07:47 PM
Right, here is issue about it. We finally decided that it is OK if AppVeyor will add
Versionand others if they do not exist.10 Posted by jstafford on 15 Feb, 2018 08:24 PM
Great. Thanks Ilya. You're a superstar.
11 Posted by Ilya Finkelshte... on 15 Feb, 2018 08:34 PM
Shhh, don't tell anyone :)
Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 02:27 AM.