One Repo, multiple projects, 2 nugets and appveyor

keith.barrows's Avatar

keith.barrows

04 Sep, 2018 07:47 PM

I am brand new to appveyor, fairly new to github (have not been active at https://github.com/KeithBarrows/sol3) and I am trying to learn the ropes of CI builds. I currently have several old projects that I will eventually update to .NET Core, a couple of library projects already in Core and a test CLI project. No SLN files.

I created my appveyor project based on the root of this github and am now trying to figure out how to add an [somename].appveyor.yml to each project so that they run specific tasks. i.e.:
* Sol3.Infrastructure - restore nuget references, build release version, pack as nuget, publish to VSTS
* Sol3.Infrastructure.IoT - restore nuget references, build release version, pack as nuget, publish to VSTS
* Sol3.TestCli - restore nuget references, build release version

I will also be adding a new Core Web App that I would like to run in Docker.
* Sol3.net (web app) - restore nuget references, build release version, publish to docker container, publish to my docker hub repository

This last one will have dependencies on the first 2 projects via nuget so needs to be built last.

With that in mind, the only quasi-success I've had is to try to do everything from the settings page for my project on appveyor and I am running into several problems.

It seems that appveyor does not have a mechanism to "login" to VSTS nuget feeds:

C:\Program Files\dotnet\sdk\2.1.401\NuGet.targets(114,5): error : Unable to load the service index for source https://keithbarrows.pkgs.visualstudio.com/_packaging/packages/nuge.... [C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj]

My next question is how can I, via the settings page, let appveyor know that each project has its own appveyor.yml file?
* Sol3.Infrastructure\Sol3.Infrastructure.AppVeyor.yml
* Sol3.Infrastructure.Iot\Sol3.Infrastructure.Iot.AppVeyor.yml
* Sol3.TestCli\Sol3.TestCli.AppVeyor.yml

My first attempt at writing a project level yml file looks like:

version: '0.0.{build}'
image: Visual Studio 2017
configuration: Release
notifications:
- provider: Email
  to:
  - [my email]
  subject: CI build for Sol3.Infrastructure v0.0.{build} failed!
  on_build_success: false
  on_build_failure: true
  on_build_status_changed: false
init:
  # Best practice (Windows line endings different to Unix/Linux)
  - cmd: git config --global core.autocrlf true
before_build:
- pwsh: >-
    dotnet --version
    dotnet restore Sol3.Infrastructure/Sol3.Infrastructure.csproj --verbosity m
build:
  project: Sol3.Infrastructure/Sol3.Infrastructure.csproj
  verbosity: normal
before_package:
- pwsh: dotnet --version  # place holder
after_build:
- pwsh: >-
    dotnet --version  # place holder
    # pack this one nuget
    # publish nuget to VSTS

And I am sure I will have many more questions as well.

TIA

  1. 1 Posted by keith.barrows on 04 Sep, 2018 09:18 PM

    keith.barrows's Avatar

    I am getting closer. Added some before/after build scripts. Now it is complaining about NuGet not being restored! Here is the yml file:

    version: 0.0.{build}
    branches:
      only:
      - master
    image: Visual Studio 2017
    configuration: Release
    clone_folder: C:\sol3
    environment:
      matrix:
      - project_name: Sol3.Infrastructure
      - project_name: Sol3.Infrastructure.IoT
    before_build:
    - pwsh: "Write-Host "---==[ BEFORE BUILD SCRIPT ]==---"  \nWrite-Host $Env:project_name\ndotnet --version  \ndotnet restore $env:project_name/$env:project_name.csproj"
    build:
      project: '%project_name%\%project_name%.csproj'
      publish_nuget: true
      verbosity: normal
    before_package:
    - pwsh: Write-Host "---==[ BEFORE PACKAGING SCRIPT ]==---"
    after_build:
    - pwsh: "Write-Host "---==[ AFTER BUILD SCRIPT ]==---"  \nWrite-Host $Env:project_name\nif($env:project_name -ieq "sol3.infrastructure")  \n{  \n    Write-Host "HERE IS WHERE WE PACK AND PUBLISH THE " + $env:project_name + " NUGET"  \n}\nif($env:project_name -ieq "sol3.infrastructure.iot")  \n{  \n    Write-Host "HERE IS WHERE WE PACK AND PUBLISH THE " + $env:project_name + " NUGET"  \n}"
    

    Here is the logs:

    Build started
    git clone -q --branch=master https://github.com/KeithBarrows/sol3.git C:\sol3
    git checkout -qf d1f3ca4456c1f7d2755b236f8fe02f6760d5a14f
    Write-Host "---==[ BEFORE BUILD SCRIPT ]==---"
    Write-Host $Env:project_name dotnet --version
    dotnet restore $env:project_name/$env:project_name.csproj ---==[ BEFORE BUILD SCRIPT ]==--- Sol3.Infrastructure 2.1.401 Restoring packages for C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj... C:\Program Files\dotnet\sdk\2.1.401\NuGet.targets(114,5): error : Unable to load the service index for source https://keithbarrows.pkgs.visualstudio.com/_packaging/packages/nuget/v3/index.json. [C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj] C:\Program Files\dotnet\sdk\2.1.401\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj] msbuild "C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj" /verbosity:normal /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /p:GeneratePackageOnBuild=false Microsoft (R) Build Engine version 15.8.168+ga8fba1ebd7 for .NET Framework Copyright (C) Microsoft Corporation. All rights reserved. Build started 9/4/2018 2:13:16 PM. Project "C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj" on node 1 (default targets). PrepareForBuild: Creating directory "bin\Release\netcoreapp2.1". Creating directory "obj\Release\netcoreapp2.1". C:\Program Files\dotnet\sdk\2.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1004: Assets file 'C:\sol3\Sol3.Infrastructure\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj] Done Building Project "C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj" (default targets) -- FAILED. Build FAILED. "C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj" (default target) (1) -> (ResolvePackageAssets target) -> C:\Program Files\dotnet\sdk\2.1.401\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198,5): error NETSDK1004: Assets file 'C:\sol3\Sol3.Infrastructure\obj\project.assets.json' not found. Run a NuGet package restore to generate this file. [C:\sol3\Sol3.Infrastructure\Sol3.Infrastructure.csproj] 0 Warning(s) 1 Error(s) Time Elapsed 00:00:11.00 Command exited with code 1

    Any ideas on why the nuget restore, which works, is not recognized when the build happens?

  2. Support Staff 2 Posted by Ilya Finkelshte... on 04 Sep, 2018 10:19 PM

    Ilya Finkelshteyn's Avatar

    It is private nuget feed, correct? In this case you have to add a nuget source before using it with nuget sources add command. Otherwise nuget/dotnet restore unable to authenticate against it. Secret you pass to this command can be store as a secure variable.

  3. 3 Posted by keith.barrows on 05 Sep, 2018 06:24 PM

    keith.barrows's Avatar

    I've gotten a lot further. Dropped trying to write project level appveyor.yml files, started using the Environment matrix in the settings page, writing my own build script in PSCore.

    In the build matrix I list each project I want to build. Then, I run this build script for .NET Core 2.x:

    Write-Host "---==[ BEFORE BUILD" $env:project_name "SCRIPT ]==---"  
    Set-Location .\$env:project_name
    dotnet restore ###$env:project_name/$env:project_name.csproj
    Write-Host ""
    Write-Host "---==[ BUILD" $env:project_name "SCRIPT ]==---"  
    dotnet build ###$env:project_name/$env:project_name.csproj -c Release
    Write-Host ""
    Write-Host "---==[ AFTER BUILD" $env:project_name "SCRIPT ]==---"  
    if($env:project_name -ilike "sol3.infrastructure*")  
    {  
        dotnet pack --no-build /p:PackageVersion=$env:APPVEYOR_BUILD_VERSION
        nuget push .\bin\release\$env:project_name.$env:APPVEYOR_BUILD_VERSION.nupkg -ApiKey [myKey] -Source https://ci.appveyor.com/nuget/keithbarrows/api/v2/package
    }
    Set-Location ..
    

    Everything seems to now work, the builds build correctly, the packages push to my account nuget feed on AppVeyor. However, I cannot access the account nuget feed. Maybe it is just temporary?

  4. 4 Posted by keith.barrows on 06 Sep, 2018 06:11 PM

    keith.barrows's Avatar

    This can be closed. I got it all working except for being able to access the nugets after build is done.

    https://help.appveyor.com/discussions/questions/25682-how-do-you-ac...

  5. Support Staff 5 Posted by Ilya Finkelshte... on 06 Sep, 2018 06:34 PM

    Ilya Finkelshteyn's Avatar

    Great, we will help with another ticket shortly.

  6. Ilya Finkelshteyn closed this discussion on 06 Sep, 2018 06:34 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