You must add a reference to assembly System.Runtime

I’m attempting to build a pretty simple netstandard2.0 project using GitLab CI. It builds correctly on my local macOS machine against the dotnet core 2.1 sdk. The local build uses the same scripts that GitLab CI is setup to run and yet the CI build always fails with the following:

error CS0012: The type ‘Attribute’ is defined in an assembly that is not referenced. You must add a reference to assembly ‘System.Runtime, Version=4.0.20.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a’.

Here’s the .csproj for the project that isn’t building:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <NeutralLanguage>en-US</NeutralLanguage>
    <TargetFramework>netstandard2.0</TargetFramework>
    <PackageVersion>0.1.0.0</PackageVersion>
    <PackageId>Foo.Data.Profiles</PackageId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="AWSSDK.DynamoDBv2" Version="3.3.12.1" />
    <PackageReference Include="Bar.Library" Version="1.0.0" />
  </ItemGroup>

</Project>

And the build script:

#!/bin/bash

set -e

cd src/Foo

dotnet build -c Release

And the nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageRestore>
    <add key="enabled" value="true" />
    <add key="automatic" value="true" />
  </packageRestore>

  <packageSources>
    <add key="Bar Stuff" value="https://www.myget.org/F/bar/api/v3/index.json" />
    <add key="Foo Stuff" value="https://www.myget.org/F/foo/api/v3/index.json" />
  </packageSources>
</configuration>

And the .gitlab-di.yml

image: microsoft/dotnet:2.1-sdk

stages:
  - build
  - test
  - deploy

build:
  stage: build
  script:
    - chmod +x ./scripts/build.sh
    - ./scripts/build.sh

test:
  stage: test
  script:
    - chmod +x ./scripts/test.sh
    - ./scripts/test.sh

deploy:
  stage: deploy
  only:
    - master
  script:
    - chmod +x ./scripts/deploy.sh
    - ./scripts.deploy.sh $MYGET_API_KEY

And the offending code that requires System.Runtime:

using System;

using Amazon.DynamoDBv2.DataModel;

namespace Foo.Data.Profiles.Models
{
    [DynamoDBTable("Profiles")]
    public class Profile
    {
        [DynamoDBHashKey]
        public string UserId { get; set; }

        public string FirstName { get; set; }

        public string LastName { get; set; }

        public string Bio { get; set; }

        public string Image { get; set; }

        public DateTime CreatedAt { get; set; }

        public DateTime UpdatedAt { get; set; }
    }
}

I would be eternally grateful for any help on this. I have scoured a lot of boards and tried a lot of possibilities and nothing has worked.

Interesting. I noticed that CI was using dotnet core 2.1.400 and I was using 2.1.302. I upgraded to 2.1.400 locally and now I have this issue.

Modifying the project target from netstandard2.0 to netcoreapp2.1 fixed the build. I’m taking the discussion to the dotnet standard github repo.