还是 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/