MSBuild.Sdk.SqlProj icon indicating copy to clipboard operation
MSBuild.Sdk.SqlProj copied to clipboard

Build failure with master.db.dacpac....

Open MHacker9404 opened this issue 4 years ago • 13 comments

So I've gone thru the steps to create a master-db dacpac, and reference it in my build project - but I'm still getting unresolved references, and an additional error in the build project itself. my build project: <Project Sdk="MSBuild.Sdk.SqlProj/1.11.1"> <PropertyGroup> <TargetFramework>netstandard2.1</TargetFramework> <!--<TargetFramework>net5.0</TargetFramework>--> <SqlServerVersion>Sql140</SqlServerVersion> <BackupDatabaseBeforeChanges>True</BackupDatabaseBeforeChanges> <BlockOnPossibleDataLoss>True</BlockOnPossibleDataLoss> </PropertyGroup> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'"> <OutputPath>.\..\..\dist\cloud-key\db\</OutputPath> </PropertyGroup> <ItemGroup> <PostDeploy Include="..\Scripts\Script.PostDeployment.sql" /> </ItemGroup> <ItemGroup> <Content Include="..\dbo\**\*.sql" /> </ItemGroup> <ItemGroup> <PackageReference Include="master.dacpac" Version="14.0.1" /> </ItemGroup> </Project> I've attached the build error messages themselves in the text file.

Any ideas? build-failure.txt

MHacker9404 avatar Jan 29 '21 15:01 MHacker9404

@MHacker9404 I think you'll need to add DatabaseVariableLiteralValue="master" to the PackageReference element to mark it as an external database reference. Right now it assumes that the master objects are going to be part of the same database.

jmezach avatar Jan 29 '21 15:01 jmezach

That didn't help any - still same errors....

If I remove the view that's referencing the system tables - then it builds fine.....it's a hacky work-around....

MHacker9404 avatar Jan 29 '21 17:01 MHacker9404

@jeffrosenberg If I remember correctly you've done this, right? Any idea what's going on here?

jmezach avatar Jan 29 '21 17:01 jmezach

@jmezach that's all I've had to do in the past. I have a few thoughts, but it's hard to know for sure what's going on without some further information. @MHacker9404 can you please provide the full build outputs, rather than just the error logs? It's unclear to me whether the master database reference is being resolved successfully, or if the issue is in the view itself.

Based on the information provided, I can think of a few possible explanations. In no particular order:

  • The view itself has an error, and the joins in it really are ambiguous. Can you successfully create the view outside of MSBuild?
  • The master.dacpac package isn't being resolved because the versioning isn't matching
  • The master.dacpac package isn't being resolved because it's been built but not pushed to your local NuGet repository (dotnet pack then dotnet nuget push)
  • The master.dacpac package isn't being resolved because the structure is incorrect (the dacpac file isn't in the tools/ folder, for example

So, plenty of avenues here for debugging, but that's as far as I can go without more details.

jeffrosenberg avatar Jan 30 '21 00:01 jeffrosenberg

If I do a VS build on the sqlproj with a master.dacpac reference - it builds fine with the view. The problem is in the .Build csproj... I just checked the nuget file - the dacpac is in a tools folder

What screenshots/code snips can I provide to answer the above?

MHacker9404 avatar Feb 03 '21 20:02 MHacker9404

@MHacker9404 I'd like to see the full output when you run dotnet build <yourproject>.csproj

jeffrosenberg avatar Feb 03 '21 21:02 jeffrosenberg

Screenshot of project structure build project output

project-snippy CloudKey.Build.csproj.txt cloud-key-db-build.txt

MHacker9404 avatar Feb 03 '21 21:02 MHacker9404

It certainly looks to me like your master.dacpac dependency isn't being resolved. If it were, I'd expect to see that in the outputs.

In the image you posted, is that master.dacpac.14.0.1.nupkg the project you're trying to reference? Having it as part of your main project isn't what you want, it should be built separately and pushed to your local NuGet repository. When you look in $HOME/.nuget/packages, do you see a copy of master.dacpac there?

jeffrosenberg avatar Feb 03 '21 23:02 jeffrosenberg

yep.... folder-snippy

MHacker9404 avatar Feb 04 '21 00:02 MHacker9404

That looks alright to me, but looking at the build output it somehow doesn't seem to include the reference to the master.dacpac. Could you try running dotnet build <your-project-file>.csproj -v detailed? That should give us some additional output that will help us figure out what's going wrong here.

jmezach avatar Feb 04 '21 07:02 jmezach

Quick update - got this working with Azure Data Studio (from scratch), pivoted a little. I should be able to get back and try this again early this week.

MHacker9404 avatar Feb 06 '21 14:02 MHacker9404

@jmezach now that we have support for project references would it be possible to reference a master.dacpac "directly" (e.q C:\Shared\master.dacpac)?

Without a nuget package?

br

rizi avatar Dec 20 '21 09:12 rizi

I guess that you could create a separate master.csproj that would copy the master.dacpac to its output folder and then add a project reference to it and it would work. Still a bit cumbersome though.

Of course it wouldn't be too hard to allow referencing a .dacpac from some location on disk (for example using a regular <Reference>), but that would require that .dacpac to always be available on that location. That is particularly problematic for CI scenarios. If somebody is willing to implement it I'd gladly have a look at it it, but I currently don't have time to implement it myself.

jmezach avatar Dec 27 '21 08:12 jmezach

This is not something the team plans to implement, and master.dacpac nuget packages are coming sometime soon.

ErikEJ avatar Nov 22 '22 14:11 ErikEJ