11

我正在尝试使用 Azure DevOps Pipelines 从 GitHub 构建我的 .NET Core 2.1 解决方案。它包括一个 SQL 项目,其 TargetFrameworkVersion 为v4.6.2. 这个项目总是无法构建。

Build FAILED.

/home/vsts/work/1/s/MySolution/MyDatabase/MyDatabase.sqlproj : warning NU1503: Skipping restore for project '/home/vsts/work/1/s/MySolution/MyDatabase/MyDatabase.sqlproj'. The project file may be invalid or missing targets required for restore. [/home/vsts/work/1/s/MySolution/MySolution.sln]
/home/vsts/work/1/s/MySolution/MyDatabase/MyDatabase.sqlproj(57,3): error MSB4019: The imported project "/usr/share/dotnet/sdk/2.1.403/Microsoft/VisualStudio/v15.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.
1 Warning(s)
1 Error(s)

如何为构建服务器引用或包含这些目标?它在 VS2017 中构建良好。我已经花了一天多的时间寻找,但找不到有关此问题的任何信息。

4

3 回答 3

10

感谢Herman Cordes指导我的调查。

问题出在所选的构建服务器上。SSDT 是一个仅限 Windows 的包,所以我不得不使用 Windows VM 而不是默认的 Ubuntu VM,并使用VSBuild@1任务而不是DotNetCoreCLI@2

天蓝色管道.yml

pool:
  vmImage: 'vs2017-win2016'

steps:
- task: VSBuild@1
  displayName: 'vsbuild $(buildConfiguration)'
  inputs:
    configuration: $(buildConfiguration)

编辑:MSBuild@1任务也有效。

于 2018-11-27T05:24:11.873 回答
1

这是 linux 构建代理的解决方案 在 linux 代理 上构建 DacPac 文件的最简单方法是通过MSBuild.Sdk.SqlProj完成 转到与 .sqlproj 文件并行的数据库项目目录 在其DB.Build下创建一个目录 create DB.Build.csprojcopy.pase 内容如下

<Project Sdk="MSBuild.Sdk.SqlProj/1.1.0"> <!-- This will pull in the required tools and dependencies to build a .dacpac with .NET Core -->
    <PropertyGroup>
        <TargetFramework>netstandard2.0</TargetFramework>
    </PropertyGroup>
    <ItemGroup>
        <Content Include="..\src\DB\masterdata\**\*.sql" /> <!-- link in the new .csproj to the .sql scripts in your existing database project -->
    </ItemGroup>
</Project>

运行后你会看到 dacpac 文件出现在DB.Build/bin/Release/netstandard2.0/DB.Build.dacpac

这是我的构建代理输出(Azure devops 上的 Ubuntu 代理)

Starting: SQL DB build Release
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.187.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
/opt/hostedtoolcache/dotnet/dotnet build /home/vsts/work/1/s/src/RecommenderAPI.DB/RecommenderAPI.DB/RecommenderAPI.DB.Build/RecommenderAPI.DB.Build.csproj -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.187.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.187.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" --configuration Release /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=/home/vsts/work/1/recommender-service-cicd/DacPac/
Microsoft (R) Build Engine version 16.5.0+d4cbfca49 for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 51.72 ms for /home/vsts/work/1/s/src/RecommenderAPI.DB/RecommenderAPI.DB/RecommenderAPI.DB.Build/RecommenderAPI.DB.Build.csproj.
  Using package name RecommenderAPI.DB.Build and version 1.0.0
  Using SQL Server version Sql150
  Deleting existing file /home/vsts/work/1/s/src/RecommenderAPI.DB/RecommenderAPI.DB/RecommenderAPI.DB.Build/obj/Release/netstandard2.0/RecommenderAPI.DB.Build.dacpac
  Writing model to /home/vsts/work/1/s/src/RecommenderAPI.DB/RecommenderAPI.DB/RecommenderAPI.DB.Build/obj/Release/netstandard2.0/RecommenderAPI.DB.Build.dacpac
  RecommenderAPI.DB.Build -> /home/vsts/work/1/s/src/RecommenderAPI.DB/RecommenderAPI.DB/RecommenderAPI.DB.Build/bin/Release/netstandard2.0/RecommenderAPI.DB.Build.dacpac

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.71

Finishing: SQL DB build Release

注意:确保在构建之前的步骤中恢复 NuGet 包

您的 ADO 管道清单应如下所示:

...

- task: DotNetCoreCLI@2
  displayName: 'Restore SQL Project'
  inputs:
    command: 'restore'
    projects: '**/*DB*/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'db-feed'

...


- task: DotNetCoreCLI@2
  displayName: 'SQL DB build $(buildConfiguration)'
  inputs:
    command: build
    projects: '**/*DB*/*.csproj'
    platform: '$(buildPlatform)'
    arguments: '--configuration $(buildConfiguration) /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(Pipeline.Workspace)/$(pipelineArtifactName)/DacPac/'

于 2021-07-07T15:16:33.010 回答
1

我在 Azure DevOps CI/CD 管道上构建 SQL Server 项目时遇到了完全相同的问题。没有任何预先构建的构建任务对我有用!

我通过避免将 SQL Server 项目添加到解决方案来解决了这个问题。

我通过使用MSBuild SDK.dacpac实现了这一点,该 SDK 能够从一组 SQL 脚本生成 SQL Server 数据层应用程序包 ( )。通过将第二个项目添加到解决方案中,我设法继续利用通过 Visual Studio 上的 SQL Server 对象资源管理器将项目链接到实时数据库的优势。我在这个答案中给出了关于我的实现的更详细的解释。

于 2020-04-18T17:14:13.300 回答