How to get <Version> from .csproj into artifact zipfile's name

T Dahl's Avatar

T Dahl

20 Apr, 2019 08:38 PM

For a .Net Core 3 C# project I have successfully set up a build process with artifact upload via SFTP.
How can I include the <Version> statement in the .csproj file as a part of the zipfile's name that is uploaded? E.g. ""
I know I can specify for example (under Artifacts):
Path: consoleapp1\bin\debug\netcoreapp3.0
But this is Appveyor's version, and not the project version itself.
Is the solution to write a script that manually extracts the <Version> value from the xml file into an environment variable and then refer to that? Or is it a built in appveyor way?

  1. 1 Posted by T Dahl on 21 Apr, 2019 08:17 AM

    T Dahl's Avatar

    To answer myself here I can add that this Before Build PS script works:
    nuget restore
    [xml]$cn = Get-Content consoleapp1\consoleapp1.csproj
    $Env:vn += $cn.Project.PropertyGroup.Version

    I can then create an artifact with the Deployment name file%cn% and %cn% is replaced with the version string from the csproj file.
    However, I wonder if there is a better way?

  2. Support Staff 2 Posted by Ilya Finkelshte... on 22 Apr, 2019 05:01 PM

    Ilya Finkelshteyn's Avatar

    You can do it other way around using .csproj patching.

    Some more details: Variables {version}, {build}, {branch} are shortcuts implemented specifically to use with patching. Use them exactly as described (in {} curly brackets).

    All other environment variables can be used too, but use them using standard environment variable notation -- $(variable).

    But if you are going to bake version in .csproj, we have no solution better than what you already figured out.

  3. Ilya Finkelshteyn closed this discussion on 22 Jun, 2019 09:01 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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