未找到Microsoft.Data.Tools.Schema.SqlTasks.targets

问题描述 投票:0回答:2

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

因此,我尝试使用 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 .8.0\lib etstandard1.5\Microsoft\VisualStudio 11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets\" 未找到。请确认声明中的路径正确,并且该文件存在于磁盘上。C:\_websites \Projects\MyProj\MyProj.Database\MyProj.Database.sqlproj

现在第一条路径不存在。确实有

netstandard1.5
文件夹,但其下没有
Microsoft
文件夹。第二条路径,即我的项目的路径确实存在,并且它列出的内容是正确的。如果我复制并通过路径,我就会到达我的项目。

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

我想知道我是否缺少一个软件包来完成这项工作?我安装了

Microsoft.Build
Microsoft.Build.Framework

c# asp.net-core asp.net-core-mvc integration-testing asp.net-core-2.0
2个回答
1
投票

我在尝试在 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
文件,那么 这个答案 会很有用,它概述了需要在所有构建代理上安装 SQL Server 数据工具。)


0
投票

似乎是 Dotnet 核心的问题

不支持运行SQL项目

在这里找到了一些解决方案https://gordonbeeming.com/blog/msb4019-microsoft-data-tools-schema-sqltasks-targets-was-not-found

我能够通过使用 msbuild 而不是 dotnet build 来克服它 有关如何使 msbuild 工作的指南请参见此处 => 如何使用 Windows SDK 7.1 从命令行运行 msbuild?

© www.soinside.com 2019 - 2024. All rights reserved.