在Azure DevOps的版本中找不到“ SqlConnection”

时间:2019-03-25 11:37:14

标签: azure-devops azure-pipelines

我有一个引用System.Data.SqlClient library及其依赖项的.NET核心应用程序。在本地构建项目可以正常工作,但是当我在Azure DevOps的管道中构建项目时,它会返回有关该库的许多“未找到”错误。

这些是错误:

Helpers\MicrosoftSQLServerHelper.cs(15,41): error CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]
Helpers\MicrosoftSQLServerHelper.cs(19,42): error CS0246: The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]
Helpers\MicrosoftSQLServerHelper.cs(29,41): error CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]
Helpers\MicrosoftSQLServerHelper.cs(43,42): error CS0246: The type or namespace name 'SqlCommand' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]
Helpers\MicrosoftSQLServerHelper.cs(55,41): error CS0246: The type or namespace name 'SqlConnection' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]
Helpers\MicrosoftSQLServerHelper.cs(59,39): error CS0246: The type or namespace name 'SqlBulkCopy' could not be found (are you missing a using directive or an assembly reference?) [d:\a\1\s\src\Visyon.ETLs.Executors\Visyon.ETLs.Executors.csproj]

我已经检查了Azure DevOps将启动什么命令来构建项目("C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\src\Visyon.ETLs\Visyon.ETLs.csproj --configuration Release),并且已经在本地计算机上启动了。在本地,它可以工作。

此外,我使用Azure DevOps提供的默认.NET Core构建模板,并在代理“ VS2017”上运行该构建。

有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

  在Azure DevOps的版本中找不到

'SqlConnection'

根据错误消息,似乎在使用Azure DevOps进行构建时缺少参考System.Data.SqlClient。您应该添加两个nuget任务来还原软件包System.Data.SqlClient

NuGet Tool Installer task

Restore NuGet packages

当我们在本地计算机上构建项目/解决方案时,下载的软件包存储在\packages文件夹中,提交我们的源代码时,此文件夹将被源代码管理忽略(建议这样做),因此当我们在Azure DevOps上构建项目/解决方案时,需要在构建nuget包之前添加nuget restore任务来还原nuget包:

enter image description here

enter image description here

希望这会有所帮助。