MSBuild.Sdk.SqlProj
MSBuild.Sdk.SqlProj copied to clipboard
Build failure with master.db.dacpac....
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 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.
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....
@jeffrosenberg If I remember correctly you've done this, right? Any idea what's going on here?
@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.dacpacpackage isn't being resolved because the versioning isn't matching - The
master.dacpacpackage isn't being resolved because it's been built but not pushed to your local NuGet repository (dotnet packthendotnet nuget push) - The
master.dacpacpackage isn't being resolved because the structure is incorrect (the dacpac file isn't in thetools/folder, for example
So, plenty of avenues here for debugging, but that's as far as I can go without more details.
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 I'd like to see the full output when you run dotnet build <yourproject>.csproj
Screenshot of project structure build project output
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?
yep....

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.
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.
@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
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.
This is not something the team plans to implement, and master.dacpac nuget packages are coming sometime soon.