How to ingore a .sql file on build but include it

2019-07-15 11:28发布

问题:

Is there a way to ignore some SQL files in the build of a SQL Server Database Project but include them on the schema compare?

I mean, we have some SQL files that cause failures in the build (they point to a linked server which we have no access). What we want is to exclude it from the build (so the build passes) but include it on schema comparisons (so we can see if it was modified).

Any suggestions?

回答1:

When you deploy use a deployment filter to stop the object being deployed, either write your own or use my one which will let you exclude the object by name, scheme or type:

http://agilesqlclub.codeplex.com/

This will mean you can compare back to your project and still deploy without touching it.

Ed



回答2:

I acknowledge I'm not providing the solution you want, but what you're trying to do is work around SSDT. This can cause more pain than its worth and it's often easier to properly fix the problem - in this case, the script that doesn't build.

I'm assuming the issue you have with the linked server is because it has an unresolved reference - in which case I'd recommend using a SQLCMD variable instead.

The SQLCMD variable will abstract out the linked server name, so SSDT will stop trying to parse it, and should allow you to build. When you deploy the database (using a Publish Profile or sqlpackage.exe) you can specify the SQLCMD value you want to use, and the same for when you do a compare.

Here's an example of using a SQLCMD variable this way: http://ntsblog.homedev.com.au/index.php/2013/03/13/sqlcmd-variables-linked-server-connection-intellisense/

If this doesn't work for you, let me know what sort of object your working with / some sample code or screenshots and I'll try and help you out.