When adding existing items to a Visual Studio database project, it is sometimes necessary to adjust the item’s properties. This particularly applies when adding pre- & post-deployment scripts.
It is possible to have only a single script in a project with the Build Action set to pre-deployment (likewise for post-deployment). When you want to work with multiple pre-deployment scripts in a project, it is necessary to create a single script with the Build Action set to Pre-deployment. The other scripts that are to be executed before deployment are added as files with their Build Action set to None & are called by the Pre-deployment script.
However, when adding an existing item to a project, the Build Action will be set to Build by default, which will break the build. This can be shown by the following example:
1. Add an existing file to the project.
2. The existing “Test script – not in build.sql” file (which should be called by the Pre-deployment script) has now been added to the project.
3. However this addition breaks the build as the file’s Build Action was not set as needed when we added it.
4. If we check the script file’s properties, we can see that the Build Action is set to Build.
5. By setting the file’s Build Action to None, the problem is solved & the subsequent build succeeds.
This issue applies to both pre- & post-deployment script files (& possibly others) when they are added as existing items to Visual Studio database projects.
Be First to Comment