rr-wfm / MSBuild.Sdk.SqlProj

An MSBuild SDK that provides similar functionality to SQL Server Data Tools (.sqlproj) projects
MIT License
379 stars 42 forks source link

SQLPackage publish is not working in linux, dacpac built with sqlproject have absolute path to referenced dacpacs #550

Open JLLange opened 3 months ago

JLLange commented 3 months ago

Hello,

I am trying to use sqlpackage publish to deploy a dacpac created by MSBuild.Sdk.SqlProj and having issues with the absolute path. details...

I have a csProj sql project that references another DACPAC as a nuget.

this is the nuget reference line from the project

<PackageReference Include="SomeDBDacpacPackageName" Version="5.84.0" DacpacName="SomeDB"></PackageReference> I copy the two dacpacs from the bin folder after building the cs project file.

The files are coppied into a docker linux session and I cd to that directory and call sqlpackage.

/tmp/sqlpackage/sqlpackage /Action:Publish /TargetServerName:localhost /TargetDatabaseName:SomeDB /TargetUser:TargetUser /TargetPassword:TargetPassword /SourceFile:My.DatabaseDacpac.dacpac /p:ScriptDatabaseOptions=false /TargetTrustServerCertificate:true /rp:/tmp/dacpacs/EDB/Libraries/SomeDb.dacpac

I have tried with and without /rp, doesn't help.

9 14.12 Initializing deployment (Start)

9 14.82 *** No file was supplied for reference SomeDB.dacpac; deployment might fail. When package was created, the original referenced file was located C:\Users\UserName.nuget\packages\SomeDBDacpacPackageName\5.84.0/tools/SomeDB.dacpac.

9 14.82 Initializing deployment (Failed)

9 15.83 *** An error occurred during deployment plan generation. Deployment cannot continue.

9 15.83 Error SQL0: The reference to external elements from the source named 'SomeDB.dacpac' could not be resolved, because no such source is loaded. fail. When package was created, the original referenced file was located C:\Users\UserName.nuget\packages\SomeDBDacpacPackageName\5.84.0/tools/SomeDB.dacpac.

9 14.02 Initializing deployment (Failed)

9 15.24 *** An error occurred during deployment plan generation. Deployment cannot continue.

9 15.24 Error SQL0: The refere

Is there anyway to get the csproj to build with relative paths? has anyone successfully deployed in linux with a dacpac that references another dacpac? If so how?

Thanks for your time

JLLange commented 3 months ago

I added /Diagnostics and found that using rp does direct sqlpackage publish to the folder containing the dacpac, however it is appending part of the nuget path to the file name... Searching for file 5.84.0/tools/SomeDB.dacpac using reference path /tmp/dacpacs/EDB/Libraries

JLLange commented 3 months ago

this appears to be a behavior difference in the execution of sqlpackage between windows and linux, When executed in linux the file name includes the path from the nuget reference.

linux Microsoft.Data.Tools.Diagnostics.Tracer Information: 0 : 2024-04-02T16:20:58 : Searching for file 5.84.0/tools/TCEnterpriseDB.dacpac using relative path /tmp/dacpacs/EDB/Libraries

windows Microsoft.Data.Tools.Diagnostics.Tracer Information: 0 : 2024-04-02T16:43:15 : Searching for file TCEnterpriseDB.dacpac using reference path C:\Users\Jeremy.Lange_temp\Libraries

ErikEJ commented 1 day ago

@JLLange Are you able to provide a repro of this, then I will investigate