{"id":3204,"date":"2010-03-24T17:07:05","date_gmt":"2010-03-24T17:07:05","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2010\/03\/24\/extending-the-web-publishing-pipeline-to-package-database-project-deployed-sql-file\/"},"modified":"2010-03-24T17:07:05","modified_gmt":"2010-03-24T17:07:05","slug":"extending-the-web-publishing-pipeline-to-package-database-project-deployed-sql-file","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/extending-the-web-publishing-pipeline-to-package-database-project-deployed-sql-file\/","title":{"rendered":"Extending the Web Publishing Pipeline to package database project deployed SQL file"},"content":{"rendered":"<p>A Visual Studio solution file may contain both database project and a web application project.&#160; When deploying (not building) the database project, it can generate a .sql file containing the full sql file or an incremental upgrade file against a database.&#160; This blogs walkthrough one way to package database project generated sql file into the web application project\u2019s package.&#160; This solution works for team build scenario as well.<\/p>\n<p>&#160;<\/p>\n<p>1. Create a Web Application Project<\/p>\n<p>2. Add 2 new \u201cSQL Server 2008 Database Project\u201d to the solution<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_2.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2010\/03\/image_thumb.png\" width=\"546\" height=\"230\" \/><\/a> <\/p>\n<p>3. In each of the database project, add a sample table and make sure build and deploy are successful.&#160; Check the deployed SQL directory %database project dir%sql%configuration% making sure sql file is generated<\/p>\n<p>4. In Web application project\u2019s property page, tab \u201cPackage\/Publish SQL\u201d , Add a new database entry for debug configuration.<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_4.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2010\/03\/image_thumb_1.png\" width=\"744\" height=\"244\" \/><\/a> <\/p>\n<p>5. Select it, and add the two database script files (generated in step 3) to the script list <\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_6.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2010\/03\/image_thumb_2.png\" width=\"628\" height=\"176\" \/><\/a> <\/p>\n<p>6. Add extension pipeline project target file &lt;projectName&gt;.wpp.targets file in the same directory as the web project file.&#160; How &lt;projectName&gt;.wpp.targets works is explained in <a href=\"http:\/\/blogs.msdn.com\/webdevtools\/archive\/2010\/02\/09\/how-to-extend-target-file-to-include-registry-settings-for-web-project-package.aspx\">how to package registry blog<\/a>. For example, in the same directory as test1.vbproj file, add test1.wpp.targets file.&#160; Make its content as following:<\/p>\n<pre class=\"code\"><span style=\"color: blue\">&lt;!--<\/span><span style=\"color: green\">********************************************************************<\/span><span style=\"color: blue\">--&gt;\n&lt;!-- <\/span><span style=\"color: green\">Task dependent db project custom deploy before build <\/span><span style=\"color: blue\">--&gt;\n&lt;!--<\/span><span style=\"color: green\">********************************************************************<\/span><span style=\"color: blue\">--&gt;\n&lt;<\/span><span style=\"color: #a31515\">Project <\/span><span style=\"color: red\">xmlns<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">http:\/\/schemas.microsoft.com\/developer\/msbuild\/2003<\/span>&quot;<span style=\"color: blue\">&gt;\n  &lt;<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">AfterAddContentPathToSourceManifest <\/span><span style=\"color: red\">Condition<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">'$(AfterAddContentPathToSourceManifest)'==''<\/span>&quot;<span style=\"color: blue\">&gt;\n      <\/span>$(AfterAddContentPathToSourceManifest);\n      DeployDbProjBeforePackage;\n    <span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">AfterAddContentPathToSourceManifest<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">PropertyGroup<\/span><span style=\"color: blue\">&gt;\n\n  &lt;!-- <\/span><span style=\"color: green\">Specifies each dependent database project here, its properties will be appended to the target msbuild Properties <\/span><span style=\"color: blue\">--&gt;\n  &lt;<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n    &lt;<\/span><span style=\"color: #a31515\">MyDependentDBProjects <\/span><span style=\"color: red\">Include<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">..Database1Database1.dbproj<\/span>&quot;<span style=\"color: blue\">&gt;\n      &lt;<\/span><span style=\"color: #a31515\">Properties<\/span><span style=\"color: blue\">&gt;<\/span>DeployScriptFilePath=..Database1sql$(Configuration)Database1.sql<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">Properties<\/span><span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">MyDependentDBProjects<\/span><span style=\"color: blue\">&gt;\n\n    &lt;<\/span><span style=\"color: #a31515\">MyDependentDBProjects <\/span><span style=\"color: red\">Include<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">..Database2Database2.dbproj<\/span>&quot;<span style=\"color: blue\">&gt;\n      &lt;<\/span><span style=\"color: #a31515\">Properties<\/span><span style=\"color: blue\">&gt;<\/span>DeployScriptFilePath=..Database2sql$(Configuration)Database2.sql<span style=\"color: blue\">&lt;\/<\/span><span style=\"color: #a31515\">Properties<\/span><span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">MyDependentDBProjects<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">ItemGroup<\/span><span style=\"color: blue\">&gt;\n\n  &lt;<\/span><span style=\"color: #a31515\">Target <\/span><span style=\"color: red\">Name<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">DeployDbProjBeforePackage<\/span>&quot;<span style=\"color: blue\">&gt;\n    &lt;!-- <\/span><span style=\"color: green\">Make sure the corresponding directory exists before build the DB projects, especially useful for team build <\/span><span style=\"color: blue\">--&gt;\n    &lt;<\/span><span style=\"color: #a31515\">Message <\/span><span style=\"color: red\">Text<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Creating directory: %(MyDependentDBProjects.rootdir)%(MyDependentDBProjects.directory)sql$(Configuration)<\/span>&quot; <span style=\"color: blue\">\/&gt;\n    &lt;<\/span><span style=\"color: #a31515\">MakeDir <\/span><span style=\"color: red\">Directories<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">%(MyDependentDBProjects.rootdir)%(MyDependentDBProjects.directory)sql$(Configuration)<\/span>&quot; <span style=\"color: blue\">\/&gt;\n\n    &lt;<\/span><span style=\"color: #a31515\">MSBuild <\/span><span style=\"color: red\">Projects<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">@(MyDependentDBProjects)<\/span>&quot; <span style=\"color: red\">Targets<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Build;Deploy<\/span>&quot; <span style=\"color: red\">Properties<\/span><span style=\"color: blue\">=<\/span>&quot;<span style=\"color: blue\">Configuration=$(Configuration);<\/span>&quot;<span style=\"color: blue\">&gt;\n    &lt;\/<\/span><span style=\"color: #a31515\">MSBuild<\/span><span style=\"color: blue\">&gt;\n  &lt;\/<\/span><span style=\"color: #a31515\">Target<\/span><span style=\"color: blue\">&gt;\n\n&lt;\/<\/span><span style=\"color: #a31515\">Project<\/span><span style=\"color: blue\">&gt;\n\n<\/span><\/pre>\n<p><a href=\"http:\/\/11011.net\/software\/vspaste\"><\/a><\/p>\n<p>7. Save the project and make sure it builds.<\/p>\n<p>8. Test the normal project package from command line, such as:&#160; msbuild test1test1.vbproj \/t:package<\/p>\n<p>9. Test the team build solution package from command line, such as:&#160; msbuild test1.sln \/p:DeployOnBuild=true .&#160; Note: DeployOnBuild parameter file is used exclusively for solution build, which asks web application project to package when build in the solution.<\/p>\n<p>10. Check in to a TFS server and define a new build definition and test it in real team build environment<\/p>\n<p><a href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/image_8.png\"><img decoding=\"async\" style=\"border-bottom: 0px;border-left: 0px;border-top: 0px;border-right: 0px\" title=\"image\" border=\"0\" alt=\"image\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2010\/03\/image_thumb_3.png\" width=\"814\" height=\"490\" \/><\/a> <a href=\"http:\/\/11011.net\/software\/vspaste\"><\/a><\/p>\n<p>Note, the target file works for \u201cBuild Deployment Package\u201d command in Visual Studio UI as well.&#160; Since VS caches the targets file for a project, if you make editions to the targets file, in order for VS UI to use it, you might need to reload the project.<\/p>\n<p><span style=\"color: blue\">\n    <br \/><\/span><span style=\"color: blue\">Xinyang Qiu | Visual Web Developer<\/span><\/p>\n<p><span style=\"color: blue\"><\/span><\/p>\n<p><a href=\"http:\/\/11011.net\/software\/vspaste\"><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A Visual Studio solution file may contain both database project and a web application project.&#160; When deploying (not building) the database project, it can generate a .sql file containing the full sql file or an incremental upgrade file against a database.&#160; This blogs walkthrough one way to package database project generated sql file into the [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[7356,7352,7343,7353,7354,7357,7323,7329],"class_list":["post-3204","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-database-project","tag-package","tag-publish","tag-target-extension","tag-target-file","tag-team-build","tag-visual-studio-2010","tag-web-deployment"],"acf":[],"blog_post_summary":"<p>A Visual Studio solution file may contain both database project and a web application project.&#160; When deploying (not building) the database project, it can generate a .sql file containing the full sql file or an incremental upgrade file against a database.&#160; This blogs walkthrough one way to package database project generated sql file into the [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3204","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=3204"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3204\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=3204"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=3204"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=3204"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}