【问题标题】:Code getting build locally but Getting build erroron TF in build definition代码在本地构建,但在构建定义中的 TF 上出现构建错误
【发布时间】:2016-12-08 07:53:51
【问题描述】:

我编写了一个使用实体框架的项目,并且在本地运行良好。但是当我尝试使用 VSTS 运行自动构建时,我在运行构建定义时出错。我知道它是由实体框架引用引起的,但我无法找到根本原因。这是构建错误以供参考。

2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(4,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieContext.cs(4,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(5,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieContext.cs(5,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(7,29): Error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieContext.cs(7,29): error CS0246: The type or namespace name 'DbContext' could not be found (are you missing a using directive or an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(17,33): Error CS0246: The type or namespace name 'CreateDatabaseIfNotExists' could not be found (are you missing a using directive or an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieContext.cs(17,33): error CS0246: The type or namespace name 'CreateDatabaseIfNotExists' could not be found (are you missing a using directive or an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(40,35): Error CS0246: The type or namespace name 'DbConfiguration' could not be found (are you missing a using directive or an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieContext.cs(40,35): error CS0246: The type or namespace name 'DbConfiguration' could not be found (are you missing a using directive or an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieRepository.cs(3,19): Error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?)
2016-12-08T07:42:52.1197143Z MovieRepository.cs(3,19): error CS0234: The type or namespace name 'Entity' does not exist in the namespace 'System.Data' (are you missing an assembly reference?) [C:\a\1\s\MyMovieDatabase\Movies.Repository\Movies.Repository.csproj]
2016-12-08T07:42:52.1197143Z ##[error]MyMovieDatabase\Movies.Repository\MovieContext.cs(14,12): Error CS0246: The type or namespace name 'DbSet' could not be found (are you missing a using directive or an assembly reference?)

【问题讨论】:

  • 您能否发布您的 Movies.Repositroy.csproj 中引用实体框架 dll 的行
  • @SethuBala ` ..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.dll..\packages\EntityFramework.6.1.1\lib\net45\EntityFramework.SqlServer.dll`
  • 嗨,您能分享一下您在 VSTS 中针对特定构建定义的构建步骤吗?

标签: c# devops build-error azure-pipelines assembly-references


【解决方案1】:

问题出在您在 .csproject 中的引用中,它使用本地引用(它取自硬盘中的 packages 文件夹)。显然,当部署在服务器中时,这将不起作用。将其更改为 nugetpackages 路径。以我在下面给出的格式更改所有引用的提示路径

$(NugetPackagesPath)\EntityFramework.6.1.1\lib\net45\Entity‌​Framework.dll

您可以使用以下定义 NugetPackagesPath 的代码

<PropertyGroup>
    <!-- EnlistmentRoot is the base directory where all of the module root directories reside. --> 
    <EnlistmentRoot>$(MSBuildThisFileDirectory)</EnlistmentRoot>
    <EnlistmentRoot Condition="'$(EnlistmentRoot)' != ''">$([System.IO.Path]::GetFullPath('$(EnlistmentRoot)'))</EnlistmentRoot>
    <EnlistmentRoot Condition="'$(EnlistmentRoot)' != '' and !HasTrailingSlash('$(EnlistmentRoot)')">$(EnlistmentRoot)\</EnlistmentRoot>
</PropertyGroup>
<PropertyGroup>
    <!-- NuGetPackagesPath is the base directory for all nuget packages. --> 
    <NuGetPackagesPath>$(EnlistmentRoot)Ref\Packages</NuGetPackagesPath>
    <NuGetPackagesPath Condition="'$(NuGetPackagesPath)' != ''">$([System.IO.Path]::GetFullPath('$(NuGetPackagesPath)'))</NuGetPackagesPath>
    <NuGetPackagesPath Condition="'$(NuGetPackagesPath)' != '' and !HasTrailingSlash('$(NuGetPackagesPath)')">$(NuGetPackagesPath)\</NuGetPackagesPath>
</PropertyGroup>

【讨论】:

  • 谢谢@SethuBalaThanku。我对 .csproj 文件的结构有一点了解。 $(NugetPackagesPath) 将如何被检索?我需要在某处定义 $(NugetPackagesPath) 吗?
  • @MadhurMaurya 我已经为您的上述查询编辑了答案
猜你喜欢
  • 2020-12-28
  • 2019-02-17
  • 1970-01-01
  • 2021-02-09
  • 2019-05-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-23
相关资源
最近更新 更多