在Azure DevOps上构建sqlproj

时间:2018-11-26 01:47:48

标签: build azure-devops azure-pipelines sqlproj

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

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中构建良好。我已经花了超过一天的时间,无法找到有关此问题的任何信息。

3 个答案:

答案 0 :(得分:2)

感谢Herman Cordes指导我的调查。

问题是所选的构建服务器。 SSDT是仅Windows的软件包,因此我必须使用Windows VM而不是默认的Ubuntu VM,并使用 VSBuild @ 1 任务而不是 DotNetCoreCLI @ 2

azure-pipelines.yml

pool:
  vmImage: 'vs2017-win2016'

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

编辑: MSBuild @ 1 任务也可以使用。

答案 1 :(得分:0)

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

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

我通过使用MSBuild SDK实现了这一目标,该功能能够从一组SQL脚本生成SQL Server数据层应用程序包(import Foundation import Combine import WatchConnectivity class WatchConnectivityModel: ObservableObject { // values used to show/hide UI @Published var appNotInstalled: Bool @Published var complicationNotInstalled: Bool private struct AppNotInstalled { let value: Bool init(_ activationState: WCSessionActivationState, _ appInstalled: Bool) { value = !(activationState == .activated && appInstalled) } } private struct ComplicationNotInstalled { let value: Bool init(_ activationState: WCSessionActivationState, _ appInstalled: Bool, _ complicationInstalled: Bool) { value = activationState == .activated && appInstalled && !complicationInstalled } } private var cancellables: [AnyCancellable] = [] init() { // initilize based on the current values let state = WCSession.default.activationState let appInstalled = WCSession.default.isWatchAppInstalled let complicationInstalled = WCSession.default.isComplicationEnabled appNotInstalled = AppNotInstalled(state, appInstalled).value complicationNotInstalled = ComplicationNotInstalled(state, appInstalled, complicationInstalled).value // set up the publishers let activationStatePublisher = WCSession.default .publisher(for: \.activationState) let isWatchAppInstalledPublisher = WCSession.default .publisher(for: \.isWatchAppInstalled) let isComplicationEnabledPublisher = WCSession.default .publisher(for: \.isComplicationEnabled) // set up assignment of appNotInstalled Publishers.CombineLatest(activationStatePublisher.removeDuplicates(), isWatchAppInstalledPublisher.removeDuplicates()) .map { (state, installed) in return AppNotInstalled(state, installed).value }.receive(on: RunLoop.main) .assign(to: \.appNotInstalled, on: self) .store(in: &cancellables) // set up assignment of complicationNotInstalled Publishers.CombineLatest3(activationStatePublisher.removeDuplicates(), isWatchAppInstalledPublisher.removeDuplicates(), isComplicationEnabledPublisher.removeDuplicates()) .map { (state, appInstalled, complicationInstalled) in return ComplicationNotInstalled(state, appInstalled, complicationInstalled).value }.receive(on: RunLoop.main) .assign(to: \.complicationNotInstalled, on: self) .store(in: &cancellables) } } )。通过将第二个项目添加到解决方案中,我设法继续利用通过Visual Studio上的SQL Server Object Explorer将项目链接到实时数据库的优势。在此answer中,我对自己的实现进行了更详细的说明。

答案 2 :(得分:0)

这里是linux构建代理的解决方案 在 Linux 代理上构建 DacPac 文件的最简单方法是通过 MSBuild.Sdk.SqlProj 转到与 .sqlproj 文件并行的数据库项目目录,在其下创建一个类似 DB.Build 的目录创建 DB.Build.csproj copy.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/'