错误CS0234:类型或名称空间名称'Entity'在名称空间'System.Data'VSTS(DevOps)中不存在

时间:2019-12-02 12:02:19

标签: c# msbuild azure-devops azure-pipelines-build-task

请纠正我在哪里错了,尽管我将路径设置为动态,但仍在构建管道事件中遇到错误:

     <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)..\packages</NuGetPackagesPath>
        <NuGetPackagesPath Condition="'$(NuGetPackagesPath)' != ''">$([System.IO.Path]::GetFullPath('$(NuGetPackagesPath)'))</NuGetPackagesPath>
        <NuGetPackagesPath Condition="'$(NuGetPackagesPath)' != '' and !HasTrailingSlash('$(NuGetPackagesPath)')">$(NuGetPackagesPath)\</NuGetPackagesPath>
      </PropertyGroup>

 <Reference Include="EntityFramework">
      <HintPath>$(NugetPackagesPath)\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServer">
      <HintPath>$(NugetPackagesPath)\EntityFramework.6.1.3\lib\net45\EntityFramework.SqlServer.dll</HintPath>
    </Reference>
    <Reference Include="EntityFramework.SqlServerCompact">
      <HintPath>$(NugetPackagesPath)\EntityFramework.SqlServerCompact.6.1.3\lib\net45\EntityFramework.SqlServerCompact.dll</HintPath>
    </Reference>

1 个答案:

答案 0 :(得分:0)

  

错误CS0234:类型或名称空间名称'Entity'在以下位置不存在   命名空间“ System.Data”

此错误消息表示生成过程无法找到来自还原的nuget程序包的程序集。因此,您应该在构建管道中检查restore task的日志,以确保软件包已成功还原。

1。确保像这样的use nuget任务之前有nuget restorebuild个任务(避免使用与dotnet相关的任务导致项目目标.net framework):

enter image description here

2。如果在nuget restore任务成功的情况下问题仍然存在,请检查nuget restore任务的日志以查找软件包的存储位置:

enter image description here

然后检查build任务的日志,以了解msbuild如何识别$(NugetPackagesPath)\EntityFramework.6.1.3...之类的路径:

enter image description here

我们应该确保包的还原路径(还原任务)和msbuild(构建任务)用于获取程序集的路径相同!为此,您可能会从this issue获得一些帮助。

此外::不确定为什么使用自定义的$(NugetPackagesPath)而不是普通的

    <Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
    </Reference>

对于#2,您还可以将<hintpath>的格式更改为正常方式,以检查问题是否已解决。

希望它会有所帮助,如果我误解了任何内容,请随时纠正我:)

相关问题