【问题标题】:Error when building System.ValueTuple in .NetStandard 2.0 project在 .NetStandard 2.0 项目中构建 System.ValueTuple 时出错
【发布时间】:2018-09-30 20:45:30
【问题描述】:

我有一个使用 System.ValueTuple 的 .NetStandard 项目。

无论我是否包含 System.ValueTuple nuget 包,它都能在 Visual Studio 中正常构建。

但是,当我在 team-city 上构建它并出现错误时,它会失败:

error CS8137: Cannot define a class or member that utilizes tuples because the compiler required type 'System.Runtime.CompilerServices.TupleElementNamesAttribute' cannot be found. Are you missing a reference?

Teamcity 托管在具有最新 .Net Core SDK 和最新 .NetFramework SDK 的环境中。

当我将目标框架更改为 .NetCoreApp2.0 时,它构建得很好。

对可能发生的事情有任何想法吗?

供参考,这是我的 csproj:

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

<PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <Version>$(VersionSuffix)</Version>
    <Authors>**********</Authors>
    <Product>**********</Product>
    <Description>**********</Description>
    <PackageTags>**********</PackageTags>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
    <Copyright>**********</Copyright>
    <PackageProjectUrl>http://**********</PackageProjectUrl>
    <PackageLicenseUrl>http://**********</PackageLicenseUrl>
    <PackageIconUrl>http://**********</PackageIconUrl>
</PropertyGroup>

<ItemGroup>
    <PackageReference Include="Google.Protobuf" Version="3.4.1" />
    <PackageReference Include="RabbitMQ.Client" Version="5.0.1" />
</ItemGroup>

<ItemGroup>
  <Folder Include="**********" />
</ItemGroup>

<ItemGroup>
  <ProjectReference Include="..\**********" />
</ItemGroup>

【问题讨论】:

    标签: c# .net-framework-version .net-standard-2.0 valuetuple


    【解决方案1】:

    当我开始使用 DotNet Restore 而不是 Nuget Restore 时,该错误消失了。

    我不知道为什么。

    【讨论】:

      【解决方案2】:

      您很可能需要添加对 System.ValueTuple.dll 的引用。您可以通过从 nuget 安装 System.ValueTuple 包来做到这一点。

      【讨论】:

      • 感谢您的回答。但是,正如我在问题中所说,无论我是否添加包,它都无法构建
      • 我也遇到过这类问题,我通过手动将 System.ValueTuple 放置在项目“Bin”文件夹中解决了这个问题
      猜你喜欢
      • 1970-01-01
      • 2020-04-22
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      • 1970-01-01
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多