c# - Travis-CI 构建失败 "The type or namespace name ' 扩展在命名空间中不存在”

标签 c# .net .net-core travis-ci

还是 Travis-CI 的新手,想看看它是否是我正在做的事情。我在 Travis-CI 中遇到构建错误,但不是在本地。

示例 .NET Core 2.0 应用程序。通过构建,我收到以下错误:

error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

error CS0246: The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?)

这是配置和作业日志的链接:

https://travis-ci.org/ovation22/DapperRepository/jobs/273068340

最佳答案

错误上方有警告:

/usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.Extensions.Configuration.Abstractions". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/home/travis/build/ovation22/DapperRepository/Example.Repository/Example.Repository.csproj]

DapperRepository.cs(7,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [/home/travis/build/ovation22/DapperRepository/Example.Repository/Example.Repository.csproj]

DapperRepository.cs(16,33): error CS0246: The type or namespace name 'IConfiguration' could not be found (are you missing a using directive or an assembly reference?) [/home/travis/build/ovation22/DapperRepository/Example.Repository/Example.Repository.csproj]

让我们看看Example.Repository.csproj :

<ItemGroup>
  <PackageReference Include="Dapper" Version="1.50.2" />
</ItemGroup>

看起来不错。但是 Microsoft.Extensions.Configuration.Abstractions 在哪里?让我们往下看:

<Reference Include="Microsoft.Extensions.Configuration.Abstractions">
  <HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration.abstractions\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.Abstractions.dll</HintPath>
</Reference>

所以您告诉 msbuild 它在 C:\Program Files 中可用。 Travis 正在 Linux 中运行它,而这条路径显然不存在。

尝试在该 csproj 中添加一个 PackageReference 就像 Dapper 一样。这应该可以解决这个问题。

关于c# - Travis-CI 构建失败 "The type or namespace name ' 扩展在命名空间中不存在”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46122829/

相关文章:

c# - 如何从 Expression<Func<T>> 构建 Expression<Func<T,bool>>

c# - 如何使用反射动态获取对象属性的实例

c# - 使静态类中的字典成为线程安全的?

c# - 动态添加属性到 <head> 标签 ASP.NET

c# - 在 c# .net 中验证 Firebase JWT

c# - StructureMap 通用 Ctor 命名实例

.NET 核心运行时

asp.net-core - 是否可以将 ffmpeg 命令的输出流式传输到具有 dot net core 的客户端?

c# - 如何在派生类中序列化具有不同名称的基类变量

c# - 将新列表发送到 C# 列表中的 LINQ 查询结果