Travis NUnit Run fails - github

i have a github project which i'm trying to intergrate in to Travis CI. i'm really new to this. so on my travis.yml i have added like this
language: csharp
solution: MigrationRunner.sln
install:
- nuget restore MigrationRunner.sln
- nuget install NUnit.Runners -Version 3.4.1 -OutputDirectory $TRAVIS_BUILD_DIR/libs
script:
- xbuild /p:Configuration=Release MigrationRunner.sln
- mono $TRAVIS_BUILD_DIR/libs/NUnit.Runners.3.4.1/tools/nunit-console.exe $TRAVIS_BUILD_DIR/libs/MigrationRunner.Test/bin/Debug/MigrationRunner.Test.dll
deploy:
provider: releases
api_key: "79bd0a7b6294145bde09c390b2f5c03680c589b1"
file: "MigrationRunner"
skip_cleanup: true
on:
tags: true
and then tried to run travis but it gets error saying
Cannot open assembly
'/home/travis/build/gayan85/MigrationRunner/libs/NUnit.Runners.3.4.1/tools/nunit-console.exe':
No such file or directory.
what was the wrong?

Related

GitHub Actions dotnet build Unable to find package

I have a .NET CI ins GitHub Actions. Before added Dapper.FluentMap to the project, the GitHub Action was working without any errors.
GitHub Actions fails on:
- name: Build with dotnet
run: dotnet build --configuration Release
How can I build on GitHub actions using a NuGet Dapper.FluentMap dependency ?
I am now getting an error in GitBub Actions:
D:\a\esta-uploadmanagement\esta-uploadmanagement\BLL\BLL.csproj : error NU1101: Unable to find package Dapper.FluentMap. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\esta-uploadmanagement\esta-uploadmanagement\esta-uploadmanagement.sln]
D:\a\esta-uploadmanagement\esta-uploadmanagement\WebApp\WebApp.csproj : error NU1101: Unable to find package Dapper.FluentMap. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\esta-uploadmanagement\esta-uploadmanagement\esta-uploadmanagement.sln]
Failed to restore D:\a\esta-uploadmanagement\esta-uploadmanagement\WebApp\WebApp.csproj (in 316 ms).
Failed to restore D:\a\esta-uploadmanagement\esta-uploadmanagement\BLL\BLL.csproj (in 313 ms).
D:\a\esta-uploadmanagement\esta-uploadmanagement\DAL\DAL.csproj : error NU1101: Unable to find package Dapper.FluentMap. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages [D:\a\esta-uploadmanagement\esta-uploadmanagement\esta-uploadmanagement.sln]
Failed to restore D:\a\esta-uploadmanagement\esta-uploadmanagement\DAL\DAL.csproj (in 1 ms).
My Yaml file
on:
push:
branches:
- main
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '5.0.x'
- name: Build with dotnet
run: dotnet build --configuration Release
- name: dotnet publish
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp
This seems to be a recent bug / issue, as reported here and here on GitHub.
You can work around this issue by manually adding the nuget.org as source in a step:
[...]
- name: Set up .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: '5.0.x'
# new step
- name: Add nuget.org as nuget package source
run: dotnet nuget add source https://api.nuget.org/v3/index.json --name nuget.org
- name: Build with dotnet
run: dotnet build --configuration Release
[...]

Incorrect Path and No API errors when trying to publish to GitHub packages via GitHubActions

been stuck on this for a long time now, seems to be one problem after the other, just trying to get GitHub Actions to publish a nuGet package to GitHub packages, documentations is really hard to find and doesnt seem to give any clear examples
This was my previous question (just for context incase it helps)
I cant get gitHub actions to publish my package build to nuget.pkg.github
but now, I am getting the following:
Run dotnet nuget push "bin/Release/Project.1.0.0.nupkg" --source "github"
warn : No API Key was provided and no API Key could be found for 'https://nuget.pkg.github.com/name'. To save an API Key for a source use the 'setApiKey' command.
error: Could not find a part of the path '/home/runner/work/project/project/bin/Release'.
Here is my full yml
name: .NET Core
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.200
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-restore --verbosity normal
- name: nuGet publish
run: dotnet nuget add source https://nuget.pkg.github.com/name/index.json -n github -u uname -p password123 --store-password-in-clear-text
- name: nuGet pack
run: dotnet pack --configuration Release
- name: publish
run: dotnet nuget push "bin/Release/EurekaShared.1.0.0.nupkg" --source "github"
this is the build result:
dotnet nuget sadly doesn't always work as expected, and also has a habit of returning misleading error messages. It's infuriating.
Try adding a nuget/setup-nuget#v1 step to your workflow and use nuget.exe push instead of dotnet nuget push. That might either fix the problem or at least give you a more helpful error message.
I think the error is related with the part of the path to nupkg file, or file name. It could be issue of case, since Linux is case-sensitive.
Moreover, this workflow file is to publish just one package, i.e., EurekaShared.1.0.0.nupkg it won't work if your package is EurekaShared.1.0.2.nupkg
Perhaps you can give it a try by updating the last line in your YML file by using wildcard ** as follows:
run: dotnet nuget push /**/*.nupkg --source "github"
I also suggest that you secure your username and password in workflow file with GitHub encrypted secrets https://docs.github.com/en/free-pro-team#latest/actions/reference/encrypted-secrets

Gitlab CI/CD yml file to build, package and deploy .net standard class library as nuget to nexus repository

I have a .net Standard (.Net Standard 2.0) class library which I want to deploy to nexus as nuget package. The private nexus repository is ready and I'm using Gitlab for code management.
In Gitlab I added the gitlab-ci.yml file which will trigger the build and the deployment but still without enough steps:
stages:
- build
- package
- deploy
build_image:
stage: build
only:
- master
script:
- echo "Restoring NuGet Packages…"
- RUN dotnet restore
- echo "Building solution…"
- RUN dotnet build --no-restore -c Release -o
package_dev:
stage: package
script:
-
deploy_dev:
stage: deploy
environment:
name: development
only:
- master
script:
-
My question is how to configure this file to trigger a build then perform packaging and deploy/push to nexus repo?
I don't know if I described it well as i'm totally new to this topic. I found some examples using MAVEN image but we are not using it.
Thanks in advance!
If I understand your question correctly, you want to create a nuget package out of your project and upload it to Nexus Repo. You can do it one step.
build-and-upload:
image: <dot-net image>
stage: build-and-upload
environment:
name: dev/test/prod
only:
- master
before_script:
- aws commands if you need to assume a deploy role.
script:
- ./scripts/nuget_publish.sh
And this is how your nuget_publish.sh will look like
dotnet build
dotnet pack
NEXUS_SOURCE=<Nexus_Source_Repo_Url>
NEXUS_API_KEY=<Nexus_Source_Repo_Api_Key>
dotnet nuget push <ProjectName>/bin/Debug/*.nupkg --source $NEXUS_SOURCE --api-key $NEXUS_API_KEY
I found a solution which works fine for me. Here is the script in case anybody faces the same issue/requirement:
In ci.yml on deploy stage:
stages:
- deploy
before_script:
- nuget restore mysolution.sln
deploy_mysolution:
stage: deploy
image:
name: crunchtime/dotnetcore-nuget-msbuild-docker
script:
- dotnet msbuild mysolution.sln /t:Clean,ReBuild /p:Configuration=Release;Platform="Any CPU"
- dotnet pack "mysolution/myproject.csproj" /p:Configuration=Release;Platform="Any CPU"
- PKGPATH=$(find myproject/bin/Release/*.nupkg)
- dotnet nuget push $PKGPATH -k $NUGET_PUSH_KEY -s https://nexus.xyz.com/repository/nuget/
only:
- master
where $NUGET_PUSH_KEY is the api key which is saved as an env variable which is applied to environments via the runner.

How do I deploy nuget packages in Travis CI?

I have a nuget package that runs Travis CI for its builds. Here is my yml:
language: csharp
solution: TreasureGen.sln
install:
- nuget restore TreasureGen.sln
- nuget install NUnit.Runners -OutputDirectory testrunner
script:
- xbuild TreasureGen.sln /p:TargetFrameworkVersion="v4.5" /p:Configuration=Stress
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Unit/bin/Stress/TreasureGen.Tests.Unit.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.IoC/bin/Stress/TreasureGen.Tests.Integration.IoC.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Tables/bin/Stress/TreasureGen.Tests.Integration.Tables.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Stress/bin/Stress/TreasureGen.Tests.Integration.Stress.dll
Ideally, when this runs on the master branch, if it is successful, it would then deploy the nuget packages as needed. There are already Nuget projects in the solution, which contain Package.nuspec and NuGet.config files for each package. I have tried getting it to deploy myself and have not had much success - typically I run into problems with the authentication, but not exclusively. I was wondering if anyone here has deployed nuget packages like this in Travis and how they did it.
After much fiddling and experimentation, I finally found a solution.
.travis.yml
language: csharp
solution: TreasureGen.sln
install:
- nuget restore TreasureGen.sln
- nuget install NUnit.Runners -OutputDirectory testrunner
script:
- xbuild TreasureGen.sln /p:TargetFrameworkVersion="v4.5" /p:Configuration=Stress
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Unit/bin/Stress/TreasureGen.Tests.Unit.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.IoC/bin/Stress/TreasureGen.Tests.Integration.IoC.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Tables/bin/Stress/TreasureGen.Tests.Integration.Tables.dll
- mono ./testrunner/NUnit.ConsoleRunner.*/tools/nunit3-console.exe ./TreasureGen.Tests.Integration.Stress/bin/Stress/TreasureGen.Tests.Integration.Stress.dll
deploy:
skip_cleanup: true
provider: script
script: chmod +x ./deploy/deploy.sh && ./deploy/deploy.sh $NUGET_API_KEY $NUGET_SOURCE
on:
branch: master
deploy.sh
ApiKey=$1
Source=$2
nuget pack ./TreasureGen/TreasureGen.nuspec -Verbosity detailed
nuget pack ./TreasureGen.Domain/TreasureGen.Domain.nuspec -Verbosity detailed
nuget push ./DnDGen.TreasureGen.*.nupkg -Verbosity detailed -ApiKey $ApiKey -Source $Source
nuget push ./DnDGen.TreasureGen.Domain.*.nupkg -Verbosity detailed -ApiKey $ApiKey -Source $Source
Here are some of the key things to remember:
Do not forget the skip_cleanup: true - this allows you to reuse
your previous build command results for your nuget package
The chmod +x ./deploy/deploy.sh allows for the script to be executable
Place your API Key and Source as Travis environment variables. Especially for the API Key, make sure they are marked to not show in the output
Your build may differ (not using nunit for tests, only 1 package to publish, etc.), but the deployment process should be similar.
My .travis.yml is as below, it deploys correctly to nuget and only does the deploy from master branch. The NUGET_API environment variable is setup to only apply to master branch and not be visible in the build.
language: csharp
mono: none
dotnet: 3.1
before_install:
- sudo apt-get -y install libpam0g-dev
install:
- dotnet restore
script:
- dotnet build -c Release
after_success:
- ./test/setup_test_account.sh
- sudo dotnet test test/Npam.Tests/Npam.Tests.csproj
before_deploy:
- dotnet pack -c Release
deploy:
skip_cleanup: true
provider: script
script: dotnet nuget push ./src/Npam/bin/Release/Npam.*.nupkg -k $NUGET_API -s https://api.nuget.org/v3/index.json
on:
branch: master
https://github.com/CamW/npam/blob/master/.travis.yml
Accepted answer didn't work for me (I don't know why). Following is what worked.
language: csharp
solution: [SolutionName].sln
install:
- curl -L -o nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe
- mono nuget.exe restore [SolutionName].sln
script:
- xbuild /p:Configuration=Release [SolutionName].sln
- mono nuget.exe pack ./[NuspecName].nuspec
- mono nuget.exe setApiKey $NUGET_API_KEY -Source $NUGET_SOURCE -Verbosity quiet
- mono nuget.exe push [SolutionName].*.nupkg -Source $NUGET_SOURCE
$NUGET_SOURCE, $NUGET_API_KEY are environment variables defined in Travis.
I was trying to solve the .travis.yml problem with an aspnetcore web site. The dotnet CLI now supports commands for nuget push and executing unit testing. I also determined that the approach of having .travis.yml just call an external bash script makes things a like lot easier:
.travis.yml
language: csharp
solution: ./SolutionName.sln
mono: none
dotnet: 3.1
script:
- chmod +x ./deploy.sh
- ./deploy.sh
deploy.sh
#!/bin/bash
set -ev
dotnet build -c $BUILD_CONFIG ./SolutionName.sln
if [ $? -eq 0 ]
then
if [ "$BUILD_CONFIG" = "debug" ];
then
dotnet test ./TestProject/TestProject.csproj -v normal --no-build
else
echo Skip testing on non-debug build
fi
fi
if [ $? -eq 0 ]
then
if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "master" ];
then
dotnet nuget push ./NugetProject/bin/$BUILD_CONFIG/NugetProject.*.nupkg --api-key $NUGET_API_KEY --source $NUGET_SOURCE --skip-duplicate
else
echo Skip nuget for non-master build
fi
fi
Hope this helps someone using .NET Core 2.2 and higher.

How to publish beta nuget packages out of AppVeyor

Here is the behavior I'm trying to achieve in AppVeyor
Build the code (stamp AssemblyInfo with 1.2.3.{build})
Test the code
Create the nuget package if the tests passed
Publish the beta package if the package created successfully (1.2.3-beta-{build})
Also make the package available in artifacts.
Ideally when publishing a nuget package it would be published as prerelease. In NuGet, this is done by adding alpha characters to the end of the package version. It is also considered bad practice to overwrite an existing package (indeed, many nuget implementations do not allow this).
AppVeyor does a good job of building and testing software out of github, but I don't seem to be able to control the nuget package version.
Given:
A package with the next semantic version of 1.2.3
I would expect the AppVeyor {version} variable to equate to 1.2.3.{build}
I would expect the nuget package version to equate to 1.2.3-beta-{build}
The first thing I tried was using variables in the {version} box. Apparently this is not allowed. AppVeyor seems to only do variable substitution for {branch} and {build} as part of the {version}. This means I'll have to maintain a separate variable for the semantic version.
The next challenge I ran into is that there's no way to set the nuget package version through the UI. It wants to default to be the same as the AppVeyor build version.
I decided to try creating the package using Powershell after the tests run. This works, but the Nuget Publish step wants to run before the package is created and there doesn't seem to be a way to control the execution order.
I think I'm on the wrong track. I need a conceptual reset.
Here is my appveyor.yml in its current (incorrect) state:
version: 0.1.0.{build}
configuration: Release
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '{version}'
assembly_file_version: '{version}'
assembly_informational_version: '{version}'
environment:
packageVersion: 0.1.0
nuget:
account_feed: true
project_feed: true
disable_publish_on_pr: true
before_build:
- ps: nuget restore
build:
verbosity: minimal
artifacts:
- path: '*.nupkg'
name: nuget package
deploy:
- provider: NuGet
api_key:
secure: blahblahblah
artifact: '*.nupkg'
on:
branch: master
on_success:
- ps: >-
$releaseVersion= $env:packageVersion
$buildNumber = $env:APPVEYOR_BUILD_NUMBER
$betaVersion= "$releaseVersion-beta-$buildNumber"
nuget pack Odin.nuspec -version $betaVersion
Get-ChildItem .\*.nupkg | % { Push-AppveyorArtifact $_.FullName -FileName $_.Name }
How do I fix this? Can I get the behavior I want?
You can use PowerShell and AppVeyor API to control version number. I would try composing appveyor.yml as following:
version: 0.1.0.{build}
environment:
packageVersion: 0.1.0
init:
- ps: $env:buildVersion = "$env:packageVersion.$env:appveyor_build_number"
- ps: $env:nugetVersion = "$env:packageVersion-beta-$env:appveyor_build_number"
- ps: Update-AppveyorBuild -Version $env:buildVersion
assembly_info:
patch: true
file: '**\AssemblyInfo.*'
assembly_version: '$(buildVersion)'
assembly_file_version: '$(buildVersion)'
assembly_informational_version: '$(nugetVersion)'
configuration: Release
nuget:
account_feed: true
project_feed: true
disable_publish_on_pr: true
before_build:
- nuget restore
build:
verbosity: minimal
after_build:
- nuget pack Odin.nuspec
artifacts:
- path: '*.nupkg'
deploy:
- provider: NuGet
api_key:
secure: blahblahblah
artifact: '*.nupkg'
on:
branch: master