-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostDeployment script with SQLCMD :R is failing build #103
Comments
Hi @rehnerik I'm not able to reproduce this issue. I followed the steps to remove files from build but they are excluded as expected. Could you share a ZIP of a min-repro of your project? Thank you. |
Hi @zijchen My PostDeployment script looks like this
I have the script specified as post depoly in sqlproj as described in the docs: Pre/post-deployment scripts that are specified by the PreDeploy or PostDeploy tags are automatically excluded from build. Like this: |
@zijchen I've updated first comment aswell. |
@rehnerik everything you're describing seems to be correct, I'm not sure why they're still included in the build. Could you share your sqlproj file so I can take a look? |
Here's sqlproj file:
|
I am able to reproduce this now, thanks for all the details. The problem seems to be dotnet build picking up the files that are specified as I tried this in SSDT and it works, so this is specific to the SDK. Looking into this... |
@zijchen Yes it works in SSDT. Thanks for looking into this. |
@zijchen A lot of work went into fixing this in your "sister" project: rr-wfm/MSBuild.Sdk.SqlProj@01929bd |
+1 I'm running into this issue now trying to convert to the SDK as well |
FYI, having a similar issue here. if you need another example. I have those additional scripts setup as though because that's how it was setup by ssdt putting both and does exactly what I would expect coming from a ssdt world (files in the project explorer, build succeeds and the additional scripts included in the "final" PostDeploy.sql file inside the DacPac |
@zijchen Any news on this issue? |
I haven't had a chance to look into this yet, but I'll prioritize this as it appears to be a common issue. |
Actually this is not entirely true. I think there's a bug with our batch parser. It seems to be ignoring any invalid syntax at the beginning of any batch, so the ordering of the included scripts made a difference. At sqlproj build time, any file included by SQLCMD :r are read, parsed, and added to the postdeploy.sql in the DACPAC recursively. If you unzip a dacpac and inspect it, you will notice all the The parsing that happens at this step will generate the errors seen above, @rehnerik the 72008 error from your original post should go away if you add The batch parser error I'm seeing ignores invalid syntax until a valid token, which meant the ordering of the included scripts mattered. This led me to assume there was a bug where root level scripts aren't being parsed correctly. If I have the following T-SQL in an included script, build passes: alsdjflajioewo
CREATE TABLE Table1 (Col1 INT NULL) This also works: USE [$(DatabaseName)]
GO
aweijoawjfoiwao
CREATE TABLE Table1 (Col1 INT NULL)
GO But this generates error (expected): CREATE TABLE Table1 (Col1 INT NULL)
oweiafjiojefaj |
@zijchen Any updates on this issue? |
@NenoLoje Do you have a sample project that reproduces the issue? I believe the original issue was due to misconfigured SQLCMD variables. Also the issue with parser ignoring invalid syntax is incorrect too. The parser treats single-token strings as identifiers, as they could be a stored procedure being executed, hence why no error is thrown. |
A note for anyone reading this thread, you can simplify pre- and post-build script exclusions outlined in the OP with this: <Build Remove="Post-Deployment\*.sql" />
<None Include="Post-Deployment\*.sql" /> Fun fact, if you change the file extension from .dacpac to .zip, you can extract the contents and use BeyondCompare to see if there are discrepancies in the output scripts. |
Steps to Reproduce:
(DacFx/SqlPackage/SSMS/Azure Data Studio)
The text was updated successfully, but these errors were encountered: