Expand variable in after_test

desautelsj's Avatar

desautelsj

23 Mar, 2015 10:53 PM

What is the proper way to have a variable replaced in my after_test script? I tried the following:
 notice my attempt at using a variable: $(configuration):

after_test:
    - packages\OpenCover.4.5.3723\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"""MyProject.UnitTests\bin\$(configuration)\MyProject.UnitTests.dll""" -output:coverage.xml

but i get the following error message:
Error: The test source file "MyProject.UnitTests\bin\$(configuration)\MyProject.UnitTests.dll" provided was not found.

  1. Support Staff 1 Posted by Feodor Fitsner on 24 Mar, 2015 04:53 AM

    Feodor Fitsner's Avatar

    As there is just a command try this:

    after_test: 
        - packages\OpenCover.4.5.3723\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"MyProject.UnitTests\bin\%configuration%\MyProject.UnitTests.dll" -output:coverage.xml
    
  2. 2 Posted by desautelsj on 24 Mar, 2015 04:18 PM

    desautelsj's Avatar

    Yes it worked. Thank you. The output in the appveyor console shows the %configuration% instead of 'Debug' or 'Release', which is slightly confusing. If you ever have a chance, it would be great to improve the output in the console to display the actual value. Here's an example of the console to illustrate my point:

    Total tests: 40. Passed: 40. Failed: 0. Skipped: 0. 
    Test Run Successful. 
    Test execution time: 5.3747 Seconds 
    packages\OpenCover.4.5.3723\OpenCover.Console.exe -register:user -target:"vstest.console.exe" -targetargs:"""MyProject.UnitTests\bin\%configuration%\MyProject.UnitTests.dll""" -output:coverage.xml
    Executing: C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
    Microsoft (R) Test Execution Command Line Tool Version 12.0.30723.0 
    Copyright (c) Microsoft Corporation.  All rights reserved.
    

    As a follow-up question: when are we supposed to use curly brackets such as {myvariable}? When are we supposed to use the dollar sign and parenthesis such as $(myvariable)? and when are we supposed to use the percent signs (such as %myvariable%)?

  3. Support Staff 3 Posted by Feodor Fitsner on 25 Mar, 2015 10:24 AM

    Feodor Fitsner's Avatar

    If it is a "shell" command line, such as something starting with - use %myvariable%. if it's PS command, starting with - ps: use "$env:myvariable". In all other places should use $(myvariable). {myvariable} is only used in version format and assembly patching and there only two vars: {biuld} and {version}.

  4. 4 Posted by brian.donahue on 17 Jul, 2015 08:16 PM

    brian.donahue's Avatar

    Is the above info on variable usage specified anywhere in docs? Had to search for this - would be very useful to make easier to find! Thanks :)

  5. Ilya Finkelshteyn closed this discussion on 25 Aug, 2018 01:58 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