找不到Microsoft.Data.Tools.Schema.SqlTask​​s.targets

时间:2018-08-01 20:00:33

标签: c# asp.net-core asp.net-core-mvc integration-testing asp.net-core-2.0

我正在尝试创建集成测试。为此,我想要一个干净的数据库。我还有一个数据库项目,其中包含可以进行全新安装的表和脚本。

因此,我尝试使用Microsoft.Build框架进行构建。这是代码:

var props = new Dictionary<string, string> {
    { "UpdateDatabase", "True" },
    { "PublishScriptFileName", "schema-update.sql" },
    { "SqlPublishProfilePath", "../../../../MyProj.Database/MyProj.Database.publish.xml" }
};

//The relative path starts in the bin folder so I have to go back a few.
var projectPath = "../../../../MyProj.Database/MyProj.Database.sqlproj";

var result = BuildManager.DefaultBuildManager.Build(
    new BuildParameters{ Loggers = new [] { new ConsoleLogger() }}, 
    new BuildRequestData(new ProjectInstance(projectPath, props, null), new [] { "Publish" } )
);

return result.OverallResult == BuildResultCode.Success;

运行此代码时,出现以下错误:

  

导入的项目\“ C:\ Users \ Me \ .nuget \ packages \ microsoft.testplatform.testhost \ 15.8.0 \ lib \ netstandard1.5 \ Microsoft \ VisualStudio \ v11.0 \ SSDT \ Microsoft.Data。找不到Tools.Schema.SqlTask​​s.targets \“。确认声明中的路径正确,并且文件在磁盘上。 C:\ _ websites \ Projects \ MyProj \ MyProj.Database \ MyProj.Database.sqlproj

现在第一个路径不存在。确实有netstandard1.5文件夹,但下面没有Microsoft文件夹。第二个路径,我的项目确实存在,并且列出的内容正确。如果我复制并经过路径,就可以进入项目。

此外,如果我手动发布数据库项目,则没有问题。

我想知道是否可能缺少一个使该工作有效的软件包?我已经安装了Microsoft.BuildMicrosoft.Build.Framework

1 个答案:

答案 0 :(得分:0)

我在尝试构建TFS时收到相同的错误消息。

2019-07-15T12:29:03.3583684Z C:\vsts-agent-win-x64-2.136.1\_work\4\s\Database\ccc.SqlServer.Database\ccc.SqlServer.Database.sqlproj(126,3): error MSB4019: The imported project "C:\vsts-agent-win-x64-2.136.1\_work\_tool\dncs\2.2.203\x64\sdk\2.2.203\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
2019-07-15T12:29:03.9586915Z 
2019-07-15T12:29:03.9588040Z Build FAILED.
2019-07-15T12:29:03.9605507Z 
2019-07-15T12:29:03.9611553Z C:\vsts-agent-win-x64-2.136.1\_work\4\s\Database\ccc.SqlServer.Database\ccc.SqlServer.Database.sqlproj(126,3): error MSB4019: The imported project "C:\vsts-agent-win-x64-2.136.1\_work\_tool\dncs\2.2.203\x64\sdk\2.2.203\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
2019-07-15T12:29:03.9612755Z     0 Warning(s)
2019-07-15T12:29:03.9613175Z     1 Error(s)
2019-07-15T12:29:03.9625235Z 
2019-07-15T12:29:03.9630668Z Time Elapsed 00:00:04.67
2019-07-15T12:29:04.0221095Z ##[error]Error: C:\vsts-agent-win-x64-2.136.1\_work\_tool\dncs\2.2.203\x64\dotnet.exe failed with return code: 1

我的问题最终是用户错误。

已将TFS构建定义设置为仅构建*.csproj文件。但是,其中一个C#项目对.sqlproj项目有不必要的依赖。删除依赖项可使构建成功。

(我想如果我们尝试构建.sqlproj文件,那么this answer会很有用,因为它概述了所有构建代理都需要安装SQL Server数据工具。)