How to interpolate strings in appveyor.yml

bradphelan's Avatar

bradphelan

24 Apr, 2014 01:09 PM

If I have set the configuration as suggested in reference yml file as so

build Configuration, i.e. Debug, Release, etc.

configuration: Release

I would then like to create an env variable available to my scripts like so

environment:
MSBUILD_CONFIGURATION: $(configuration)

which I would expect to work because it's the same as in the "artifacts" section of the reference yaml

#---------------------------------#
#      artifacts configuration    #
#---------------------------------#

artifacts:

  # pushing a single file with environment variable in path and "Deployment name" specified
  - path: MyProject\bin\$(configuration)
    name: myapp

but the interpolation does not work. I get

onfiguration : The term 'configuration' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try

5+ [System.Environment]::SetEnvironmentVariable("MSBUILD_CONFIGURATION", "$(configu ...
6+                                                                          ~~~~~~~
7    + CategoryInfo          : ObjectNotFound: (configuration:String) [], CommandNotFoundException
8    + FullyQualifiedErrorId : CommandNotFoundException
9

Is there a general string interpolation process happening with appveyor to allow DRY configuration setup. The reference yml is a bit vauge on this.

  1. Support Staff 1 Posted by Feodor Fitsner on 24 Apr, 2014 03:38 PM

    Feodor Fitsner's Avatar

    Hi Brad,

    Interpolation doesn't work in environment variables section, but you can use $(msbuild_configuration) directly in artifact path.

    - Feodor

  2. 2 Posted by bradphelan on 24 Apr, 2014 04:36 PM

    bradphelan's Avatar

    That explains my confusion. Your documentation says to interpolate
    $(configuration) instead of $(msbuild_configuration). With the wrong var
    there is no error or warning, the artifact just fails to build.

    You also write 'environment variable' when you mean yaml string
    interpolation which confused me.

    Hopefully I'll get it working tomorrow.

    However I'm generally impressed and I like it more than microsofts visual
    studio online product.

    Thanks for the help

    Brad.

  3. Support Staff 3 Posted by Feodor Fitsner on 24 Apr, 2014 05:05 PM

    Feodor Fitsner's Avatar

    I'm glad you like the service!

    Sure, let me know if you have any questions!

  4. 4 Posted by bradphelan on 25 Apr, 2014 05:16 AM

    bradphelan's Avatar

    The documentation still says as of this morning

    # pushing a single file with environment variable in path and "Deployment name" specified - path: MyProject\bin\$(configuration) name: myapp

    rather than

    # pushing a single file with environment variable in path and "Deployment name" specified - path: MyProject\bin\$(msbuild_configuration) name: myapp

  5. Support Staff 5 Posted by Feodor Fitsner on 25 Apr, 2014 06:19 AM

    Feodor Fitsner's Avatar

    But I thought msbuild_configuration is your custom variable, no?

    configuration in docs is just an example - you can replace any valid environment variable.

  6. 6 Posted by bradphelan on 25 Apr, 2014 06:39 AM

    bradphelan's Avatar

    Now you have me confused. I now have in my appveyor.yml

    #---------------------------------#
    #      artifacts configuration    #
    #---------------------------------#
    
    artifacts:
        - path: WeinCad.Net\bin\$(msbuild_configuration)\app.publish
          name: clickonce
    

    and I do not define msbuild_configuration anywhere. However my artifact was correctly built.

    https://ci.appveyor.com/project/BradPhelan/weincad-net/build/0.0.24...

    I also note more inconsistent string interpolation syntax. Below you use "{}" to interpolate the build and version whereas in the artifacts section you use "$()".

    # enable patching of AssemblyInfo.* files
    assembly_info:
      patch: true
      file: AssemblyInfo.*
      assembly_version: "2.2.{build}"
      assembly_file_version: "{version}"
      assembly_informational_version: "{version}"
    
  7. Support Staff 7 Posted by Feodor Fitsner on 25 Apr, 2014 06:57 AM

    Feodor Fitsner's Avatar

    Try to output this variable to see its value, something like:

    before_build:
      - ps: $env:msbuild_configuration
    

    That {version} syntax was left for assembly patching only for compatibility with AppVeyor V1.

  8. 8 Posted by bradphelan on 25 Apr, 2014 07:11 AM

    bradphelan's Avatar

    Sorry for wasting your time. My bad! I had from the begining in upper case

    environment:
        MSBUILD_CONFIGURATION: Release
    

    Perhapps it would be better if the information

    # build platform, i.e. x86, x64, AnyCPU. This setting is optional.
    platform: AnyCPU
    
    # build Configuration, i.e. Debug, Release, etc.
    configuration: Release
    

    is by default made available as environment variables for custom build_scripts. If I make my own custom build script do you do anything with the above settings such as generate a configuration file that msbuild automagically picks up from the build directory?

  9. Support Staff 9 Posted by Feodor Fitsner on 25 Apr, 2014 05:15 PM

    Feodor Fitsner's Avatar

    Both "platform" and "configuration" are set as environment variables with the same names, but only for "MSBuild" build mode. Do you think it makes sense to set them for custom scripts too?

  10. 10 Posted by bradphelan on 25 Apr, 2014 05:27 PM

    bradphelan's Avatar

    The reason I need them is you don't seem to provide a way to produce a
    oneclick build for exe distribution. I have to patch the csproj file
    myself to get the versioning correct and supply different flags to the
    build.

    A well thought out oneclick builder for appveyor would help me a great
    deal. Once I get it working you can have my scripts and figure out how to
    integrate it. Some people are still delivering desktop apps these days :)

  11. Support Staff 11 Posted by Feodor Fitsner on 25 Apr, 2014 05:34 PM

    Feodor Fitsner's Avatar

    Desktop apps are cool - AppVeyor was started as a "deployment tool" written in WPF :)

    OK, I'll change build worker service to always set these env variables for all build modes, but only if they are explicitly set on UI on in appveyor.yml.

    Setting them to AnyCPU/Release may cause "configuration not found" on many projects - I'd prefer developers decide themselves which configuration is default in solution/project files.

  12. bradphelan closed this discussion on 30 Apr, 2014 05:24 AM.

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

Recent Discussions

18 Jun, 2025 08:45 PM
18 Jun, 2025 04:23 PM
13 Jun, 2025 04:36 PM
13 Jun, 2025 04:27 PM
13 Jun, 2025 07:20 AM

 

10 Jun, 2025 01:56 AM
09 Jun, 2025 07:11 PM
04 Jun, 2025 04:08 PM
27 May, 2025 05:48 PM
27 May, 2025 06:37 AM
27 May, 2025 06:31 AM