.NET Core sdk installed on every build

Hello,

when building with .NET Core using multiple steps, Travis-CI reinstalls the .NET Core sdk every time.
Secondly it does seem to ignore the flags DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 and DOTNET_CLI_TELEMETRY_OPTOUT=1.

There was originally an issue on github that has been closed but I didn’t seem to find it here.

Any help would be very much appreciated since this is causing the build time to be quite long.

Kind regards,
Sami

1 Like

Hello,
I’ve seen the same issue.
First build on travis, 2min just for a dotnet build… it’s pretty long! :smile:

As we’re not able to add env var for the installation, we even can’t test or workaround it.
Or, well, we can workaround it by pulling mcr.microsoft.com/dotnet/core/sdk:2.2-alpine docker image and running scripts in it, but I don’t know if it’s as easy to do with Travis as in Gitlab CI.

Ayust

1 Like

Yeah I thought about that too but I’d prefer not to do so. I can live with the build-time, just thought there might be a way to improve it that I don’t know of (yet).

Kind regards,
Sami

Hi,

cc @Joshua-Anderson

It’s been a while now.
Any workaroung to fix this?

Regards,
Ayust

Travis-CI spins up a fresh virtual machine on every build, so we have to re-install .Net Core every time.
Short of pre-installing C# on the virtual machine image, which isn’t possible right now (Travis-CI tries to minimize the amount of software preinstalled on the image), I don’t think there’s much we can do.

My guess is that sudo is not preserving the exported variables set on lines 131 and 134.

It looks like it should be a simple fix, but I don’t have the time to set up a build environment to fix and test it.

Well, the alpha Windows builds have some of this pre-installed already. Might be useful … :wink:
https://docs.travis-ci.com/user/reference/windows/#pre-installed-chocolatey-packages

Would you elaborate how you would fix it? Maybe I could try it myself doing so and creating a PR.

Oh no… please no windows :slight_smile:

1 Like

The straightforward solution would be to set the environment variable directly in the command that needs it (and the exports wouldn’t be needed). Line 152:

  sh.cmd "sudo DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 DOTNET_CLI_TELEMETRY_OPTOUT=1 apt-get install -qq dotnet-#{dotnet_package_prefix}-#{dotnet_package_version}", timing: true, assert: true

The other solution would be to update the sudoers file with env_keep options for the required variables. Without trying it, I’m not sure whether that would work, because it might require the user session to log out to apply sudoers changes.

I haven’t tested it, but here’s the first proposed solution as a commit: https://github.com/joel0/travis-build/commit/bd6465c14d877561fafab42062c6c676481c90ed If someone can test it, I can submit a PR if wanted. In theory, it should work as desired.

cc @joshua-anderson Thoughts on this change to speed up the install/setup of .net?

I haven’t been able to build FluentMigrator CI pull requests on GitHub due to the enormous increase in build time.
Would it be faster to use Docker and just install docker-ce via apt and pull down the dotnet sdk image form the Docker Registry than build mono from scratch?

I had the need to use .NET-Core preview and found this post

Using snap is some what faster. Snap is installed once but for each step dotnet is installed. For releases I am saving around two minutes.

Here a sample with multiple steps

sudo: required
dist: bionic
language: csharp
solution: Etdb.ServiceBase.AspNetCore.sln
mono: none
addons:
  snaps:
    - name: dotnet-sdk
      classic: true
      channel: latest/beta
stages:
  - build
  - test
  - publish
jobs:
  include:
    - stage: build
      name: build solution
      before_script:
        - sudo snap alias dotnet-sdk.dotnet dotnet
      script: dotnet restore && dotnet build
    - stage: test
      name: run-tests
      services: mongodb
      before_script:
        - sudo snap alias dotnet-sdk.dotnet dotnet
        - sh install_link_libgdiplus.sh
        - sh setup-mongodb-user.sh "$MONGODB_USERNAME" "$MONGODB_PASSWORD"
      script: ./run-tests.sh
    - stage: publish
      name: publish-packages
      if: tag IS present
      before_script:
        - sudo snap alias dotnet-sdk.dotnet dotnet
      script: ./publish-packages.sh "$NUGET_SOURCE" "$ETDB_NUGET_APIKEY" "$TRAVIS_TAG"
Imprint