multiple solutions; can second solution access the artifacts of the previous solution?

Henry Schmitt's Avatar

Henry Schmitt

06 Mar, 2019 10:45 PM

Hello, I'm setting up a project w/ Appveyor for the first time. For this project, I want to build a dll, then build a test project that references the dll and run tests. I'm currently setting it up in this way:

version: 1.0.{build}
image: Visual Studio 2017

environment:
  matrix:
    - projectname_solution: ProjectName/ProjectName.sln
    - projectname_solution: UnitTests/UnitTests.sln

build_script:
    - cmd: msbuild %projectname_solution%

after_build:
    - ps: $root = Resolve-Path .\ProjectName\ProjectName\bin\Debug; [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % { Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName to-publish }

before_build:
    - nuget restore %projectname_solution%

cache:
    - ProjectName\ProjectName\bin\Debug

The library builds fine, but the UnitTest project which builds right after cannot find the namespace of the library.
I've tried adding the output Debug directory to the build cache, and it seems to be updating, but somehow the UnitTest project still doesn't see it.
Does anyone have an idea of how to do what I'm trying to do?

Thank you

  1. Support Staff 1 Posted by Owen McDonnell on 07 Mar, 2019 05:41 AM

    Owen McDonnell's Avatar

    Here is a script for sharing artifacts between jobs.

    Let us know if you need some guidance adapting it to your particular project.

  2. 2 Posted by Henry Schmitt on 07 Mar, 2019 06:42 PM

    Henry Schmitt's Avatar

    Thanks! How do I get the secure: version of the API key to put in the script?
    I see there's an API key for NuGet packages under the project, and one for the account. Should I use one of these? Will these work for all artifacts, or just NuGet packages? (I need to include the dll generated by the first build, which isn't in a NuGet package)

  3. Support Staff 3 Posted by Owen McDonnell on 07 Mar, 2019 08:28 PM

    Owen McDonnell's Avatar

    Go to Account settings -> Encrypt YAML and encrypt your api key.
    Should work for any artifact.

  4. 4 Posted by Henry Schmitt on 07 Mar, 2019 09:25 PM

    Henry Schmitt's Avatar

    Thanks. Now I'm getting this error from the first if statement:
    While scanning a simple key, could not find expected ':'.

  5. 5 Posted by Henry Schmitt on 07 Mar, 2019 10:41 PM

    Henry Schmitt's Avatar

    hmm so that turned out to be a weird yaml error which was fixed when I just changed the order of the blocks :S

    now the build script is running, but I'm getting this error when it reaches the Invoke-RestMethod

    Invoke-RestMethod : {"message":"User must be logged in to access account resources."}
    At line:16 char:16
    + ...  $project = Invoke-RestMethod -Uri "https://ci.appveyor.com/api/proje ...
    +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    

    I think I am logged in? Maybe I need a different API key?

  6. 6 Posted by Henry Schmitt on 08 Mar, 2019 12:47 AM

    Henry Schmitt's Avatar

    hmm so I found the right API key and it seems to be connecting, but I'm getting a 401 not authorized error.

    Start-FileDownloadInternal : Error downloading remote file: One or more errors occurred. Inner Exception: Remote server returned 401: Unauthorized At C:\Program Files\AppVeyor\BuildAgent\Modules\build-worker-api\build-worker-api.psm1:242 char:2 + Start-FileDownloadInternal -Url $Url -FileName $FileName -Timeout ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Start-FileDownloadInternal], Exception + FullyQualifiedErrorId : System.Exception,Appveyor.BuildAgent.Api.Utils.StartFileDownloadInternalCmdlet

  7. Support Staff 7 Posted by Owen McDonnell on 08 Mar, 2019 04:29 PM

    Owen McDonnell's Avatar

    Can you share your configuration in yaml format.

  8. 8 Posted by Henry Schmitt on 08 Mar, 2019 07:20 PM

    Henry Schmitt's Avatar

    Here it is

  9. 9 Posted by Henry Schmitt on 08 Mar, 2019 07:23 PM

    Henry Schmitt's Avatar

    oops, was on another branch; here's the right one

  10. Support Staff 10 Posted by Owen McDonnell on 09 Mar, 2019 07:13 AM

    Owen McDonnell's Avatar

    The Start-Filedownload cmdlet parameter looks wrong. I think it needs to have $jobToWaitId variable in it.
    As per the example given...

    Start-FileDownload  https://ci.appveyor.com/api/buildjobs/$jobToWaitId/artifacts/<path-to-your-artifact>
    
  11. 11 Posted by Henry Schmitt on 12 Mar, 2019 12:02 AM

    Henry Schmitt's Avatar

    I get the same unauthorized error with that.

  12. 12 Posted by Henry Schmitt on 12 Mar, 2019 12:29 AM

    Henry Schmitt's Avatar

    The API key I'm using is the one from under My Profile, when I set the dropdown to my unique user name. Is that the API key to use for this?

  13. Support Staff 13 Posted by Owen McDonnell on 12 Mar, 2019 03:51 AM

    Owen McDonnell's Avatar

    Sorry, I should have noticed... Start-FileDownload cmdlet won't work here since you are trying to access a private repo.

    You'll need to translate that call into another api call with a header containing your key.
    Everything else looks good.

  14. 14 Posted by Henry Schmitt on 12 Mar, 2019 06:26 PM

    Henry Schmitt's Avatar

    Yay thanks, finally got both parts of the build working today!

    The last thing I need to do is get the unit tests actually logging. I tried adding a vstest.console line under test_script:; I'm not getting any errors right now, but I'm also not seeing any logs appear in the Tests tab for the project.
    Could you tell me if there's anything I'm doing wrong here?

  15. Support Staff 15 Posted by Owen McDonnell on 12 Mar, 2019 07:37 PM

    Owen McDonnell's Avatar

    Since you are using test_script instead of automatic testing, you should output test results to xml and upload that file. You can read about that approach here.

  16. 16 Posted by Henry Schmitt on 13 Mar, 2019 09:26 PM

    Henry Schmitt's Avatar

    hmm so it turned out I had some other stuff in that yaml that was preventing the build from working correctly. I fixed that, and it currently seems like:
    1. The build artifacts (dll) gets created
    2. It gets downloaded to the second project
    3. The second project fails to find the dll and its build fails

    at the moment, I think the issue might be that the dll needs to be in a specific path to be seen by the second project? Do you have any ideas for what might be going wrong?

  17. 17 Posted by Henry Schmitt on 13 Mar, 2019 09:40 PM

    Henry Schmitt's Avatar

    Is it possible that there's a better way of doing this? Could I just have both projects build in the same environment?

  18. Support Staff 18 Posted by Owen McDonnell on 14 Mar, 2019 04:09 AM

    Owen McDonnell's Avatar

    Yeah, you could build both solutions in one project. Just abandon the build matrix you've made and call msbuild on each one in turn.
    Seems easier to me...

  19. 19 Posted by Henry Schmitt on 14 Mar, 2019 06:25 PM

    Henry Schmitt's Avatar

    Hmm ok I simplified it a bunch so they're both building in one project. Maybe this will work better.

    However now I'm getting an error on the UnitTests project with "_TemporaryKey.pfx' not found". Do you know what causes this?

  20. 20 Posted by Henry Schmitt on 14 Mar, 2019 06:35 PM

    Henry Schmitt's Avatar

    hmm I found another thread that showed how to encrypt the pfx and restore it in the appveyor yml file...
    Trying to figure out where to encrypt the file now...

  21. 21 Posted by Henry Schmitt on 14 Mar, 2019 06:42 PM

    Henry Schmitt's Avatar

    hmm I found this page: https://www.appveyor.com/docs/how-to/secure-files/
    but not sure what the secret is that I should use to encrypt the file, so that it decrypts correctly...

  22. 22 Posted by Henry Schmitt on 14 Mar, 2019 07:52 PM

    Henry Schmitt's Avatar

    omg I got it working!

    Hmmm although, I'm not seeing it actually show me test results in the Tests tab.
    I get this console output though:
    Discovering tests...OK
    Build success

  23. 23 Posted by Henry Schmitt on 14 Mar, 2019 08:22 PM

    Henry Schmitt's Avatar

    if you're using an appveyor.yaml file, are you required to do something special to trigger your tests? atm I'm not putting anything test-related in the yaml file, but I'm not seeing any tests show up in the console

  24. Support Staff 24 Posted by Owen McDonnell on 14 Mar, 2019 08:38 PM

    Owen McDonnell's Avatar

    Looks like you gave your assembly a strong name and (perhaps wisely) did not check the key file into your repository.
    Maybe take a look here and decide if you really need the test assembly to have a strong name.

  25. Support Staff 25 Posted by Owen McDonnell on 14 Mar, 2019 09:00 PM

    Owen McDonnell's Avatar

    You can run your own custom test scripts as you did in the previous appveyor.yml that you attached.
    But you should also be able to run tests in auto mode by pointing to the test assemblies as documented here.

  26. Ilya Finkelshteyn closed this discussion on 14 May, 2019 09:00 PM.

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