{"id":16049,"date":"2015-07-28T20:32:00","date_gmt":"2015-07-29T03:32:00","guid":{"rendered":"https:\/\/devwww.3cloudsolutions.com\/post\/applying-configurations-to-the-tabular-model-with-ms-build-2\/"},"modified":"2023-10-09T14:12:30","modified_gmt":"2023-10-09T21:12:30","slug":"applying-configurations-to-the-tabular-model-with-ms-build","status":"publish","type":"post","link":"https:\/\/3cloudsolutions.com\/resources\/applying-configurations-to-the-tabular-model-with-ms-build\/","title":{"rendered":"Applying Configurations to the Tabular Model with MS Build"},"content":{"rendered":"<p>In SQL Server Data Tools for SQL Server 2012, Tabular projects are not configuration aware. Through the UI, you have static sources and target databases. However, with some MS Build extensions and some XML and PowerShell knowledge, you can roll your own configuration-aware tabular projects. Many thanks goes to Cathy Dumas\u2019 Blog entry: <a href=\"http:\/\/blogs.msdn.com\/b\/cathyk\/archive\/2011\/08\/10\/deploying-tabular-projects-using-a-custom-msbuild-task.aspx\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/blogs.msdn.com\/b\/cathyk\/archive\/2011\/08\/10\/deploying-tabular-projects-using-a-custom-msbuild-task.aspx<\/a><\/p>\n<p><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><span class=\"hs_cos_wrapper hs_cos_wrapper_meta_field hs_cos_wrapper_type_rich_text\" data-hs-cos-general-type=\"meta_field\" data-hs-cos-type=\"rich_text\"><!--more--><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/span><\/p>\n<h3>Requirements<\/h3>\n<ul>\n<li>An Analysis Services Tabular Project<\/li>\n<li>SQL Server Data Tools<\/li>\n<li>MS Build Extension Pack <a href=\"http:\/\/www.msbuildextensionpack.com\/\">http:\/\/www.msbuildextensionpack.com\/<\/a>\n<ul>\n<li>Install the .NET 4.0 32-bit version to its default location.<\/li>\n<\/ul>\n<\/li>\n<li>Custom targets file: custom_post_build.targets<\/li>\n<li>This article uses the following assumptions:\n<ul>\n<li>The project uses Windows authentication to the SSAS Tabular instance.<\/li>\n<li>One connection to a source database is shared among all tables in the model.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h3>Features<\/h3>\n<p>If you add this MS Build targets file to your SSAS tabular project, selecting the build option will accomplish the following:<\/p>\n<ul>\n<li>The tabular model will be built.<\/li>\n<li>The tabular model will be deployed to a server and database based on the selected configuration.<\/li>\n<li>The source connection string will be altered based on the selected configuration.<\/li>\n<li>The model will be processed immediately upon being deployed.<\/li>\n<\/ul>\n<h3>Setting up the Project<\/h3>\n<ol>\n<li>\nIn the project, set the database name for the deployment server. By default, the various configurations will add suffixes to this base name.<\/li>\n<li>Set up some configurations. Only names are needed. With a Tabular project, SSDT does not actually store different settings based upon the configuration.<\/li>\n<li>Save and close the project.<\/li>\n<li>Copy the custom_post_build.targets file to the project directory.<\/li>\n<li>Open the .smproj file in your favorite XML editor.<\/li>\n<li>Add the highlighted line to the end of the file:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 389px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/tabularmodel.png\" alt=\"Text Example\" width=\"389\" height=\"45\" data-constrained=\"true\" \/><\/li>\n<li>Save and close the .smproj file.<\/li>\n<li>Open the custom_post_build.targets file in your favorite XML editor.<\/li>\n<li>In the file, navigate to the if\u2026else\u00a0block:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 559px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/Screen_Shot_2015-07-29_at_9.38.29_AM.png\" alt=\"Text Example\" width=\"559\" height=\"308\" data-constrained=\"true\" \/><\/li>\n<li>Copy the elseIf block as necessary to account for all configurations. See the highlighted comment in step 7. Ideally the else block will not be necessary.<\/li>\n<li>Change the connection string variables to the proper values for each configuration.\n<ol style=\"list-style-type: lower-alpha;\">\n<li>$DBName \u2013 By default, the code adds a suffix rather than renaming the database. If you want to rename the database, change the += to an = character:<br \/>\n$DBName = &#8220;ThisIsANewDBName&#8221;;<\/li>\n<li>$TabularName \u2013 Set this to the servernameInstance. You may need to use the DNS name for servername.<\/li>\n<li>$ConnectionString \u2013 This is the connection string for the source database. All connection strings must use the same type of source, e.g. ODBC, OLE DB connections, file connections, etc.<\/li>\n<\/ol>\n<\/li>\n<li>Save and close the custom_post_build.targets file.<\/li>\n<li>Open the project again.<\/li>\n<li>Select a build configuration.<\/li>\n<li>Select Build \u2192 Build to build\/deploy\/process the model.<\/li>\n<\/ol>\n<h3>Detailed Walkthrough<\/h3>\n<ol>\n<li>The MS Build Extension Pack is installed:<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/ms_build_extension_pack.png\" alt=\"MS Build Extension Pack is Installed\" width=\"581\" height=\"181\" data-constrained=\"true\" \/><\/li>\n<li>Create a Tabular Project<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/tabular_project.png\" alt=\"Tablar Project\" width=\"581\" height=\"295\" data-constrained=\"true\" \/><\/li>\n<li>Open the project properties and set the base name of the database.\u00a0 In our case, we use TabularProject as the base name:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/project_properties.png\" alt=\"Open the project properties\" width=\"581\" height=\"318\" data-constrained=\"true\" \/><\/li>\n<li>Create the data model<\/li>\n<li>Open the configuration manager:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/configuration_manager.png\" alt=\"Open the configuration manager\" width=\"581\" height=\"242\" data-constrained=\"true\" \/><\/li>\n<li>Select new configuration:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 518px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/new_configuration.png\" alt=\"select new configuration\" width=\"518\" height=\"328\" data-constrained=\"true\" \/><\/li>\n<li>Name the new configuration:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 519px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/name_the_new_configuration.png\" alt=\"name the new configuration\" width=\"519\" height=\"328\" data-constrained=\"true\" \/><\/li>\n<li>Create any configurations needed.Here we&#8217;re using Development, Test, and QA:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 517px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/create_configurations_needed.png\" alt=\"Creater any configurations needed. Here we're using Development,Test, and QA\" width=\"517\" height=\"327\" data-constrained=\"true\" \/><\/li>\n<li>Click Save All once you&#8217;ve created your model:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 391px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/save_all.png\" alt=\"Click Save\" width=\"391\" height=\"341\" data-constrained=\"true\" \/><\/li>\n<li>Close the project:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 369px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/close_the_project.png\" alt=\"Close the project\" width=\"369\" height=\"367\" data-constrained=\"true\" \/><\/li>\n<li>Copy the targets file to the project directory:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/copy_targets_file.png\" alt=\"Copy the targets file to the project directory\" width=\"581\" height=\"218\" data-constrained=\"true\" \/><\/li>\n<li>Open the .smproj file in an XML editor:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/smproj_file.png\" alt=\"XML editor\" width=\"581\" height=\"255\" data-constrained=\"true\" \/><\/li>\n<li>Add the tag at the end of the file:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 510px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/add_tag.png\" alt=\"Add the tag\" width=\"510\" height=\"267\" data-constrained=\"true\" \/><\/li>\n<li>Save and close the .smproj file<\/li>\n<li>Open the custom_post_build.targets file in the XML editor:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/open_custom.png\" alt=\"Open the custom post\" width=\"581\" height=\"256\" data-constrained=\"true\" \/><\/li>\n<li>Find the per-configuration if&#8230;elseIf&#8230;else block:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/else.png\" alt=\"Find the per-configuration\" width=\"581\" height=\"401\" data-constrained=\"true\" \/><\/li>\n<li>We have Development and Test blocks already. We need to add a QA block for our example:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/development.png\" alt=\"Development and Test blocks already\" width=\"581\" height=\"403\" data-constrained=\"true\" \/><\/li>\n<li>Now we have to alter the variables for each configuration.\n<ol style=\"list-style-type: lower-alpha;\">\n<li>For Test we change the connection string:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 504px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/test_connection.png\" alt=\"Text Example\" width=\"504\" height=\"110\" data-constrained=\"true\" \/><\/li>\n<li>For QA we change the database name and the tabular server. Note the change of the += to + for $DBName:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 352px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/database_name.png\" alt=\"Text Example\" width=\"352\" height=\"119\" data-constrained=\"true\" \/><\/li>\n<\/ol>\n<\/li>\n<li>Save and cloe the custom_post_build.targets file<\/li>\n<li>Open the tabular project again<\/li>\n<li>Select a configuration. Here, we&#8217;re using Development:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 569px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/select_configuration.png\" alt=\"Select a Configuration\" width=\"569\" height=\"164\" data-constrained=\"true\" \/><\/li>\n<li>Select\u00a0Build\u2192Build<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 573px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/project_name.png\" alt=\"Select Build\" width=\"573\" height=\"116\" data-constrained=\"true\" \/><\/li>\n<li>Look for build succeeded in the lower left hand corner (circled in red here):<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/red.png\" alt=\"Look for build succeeded\" width=\"581\" height=\"299\" data-constrained=\"true\" \/><\/li>\n<li>Open SSMS<\/li>\n<li>Connect to the SSAS Server. In our case, localhostTABULAR:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 430px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/ssas.png\" alt=\"SSAS Server\" width=\"430\" height=\"326\" data-constrained=\"true\" \/><\/li>\n<li>Verify that the database exists with the correct name:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 408px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/correct_name.png\" alt=\"Verify that the database exists\" width=\"408\" height=\"243\" data-constrained=\"true\" \/><\/li>\n<li>Open a new MDX query to verify that processing succeeded.\u00a0 You can use MDX or DAX in the query window:<br \/>\n<img loading=\"lazy\" decoding=\"async\" style=\"width: 581px;\" src=\"https:\/\/3cloudsolutions.com\/wp-content\/uploads\/2022\/11\/mdx.png\" alt=\"MDX Query\" width=\"581\" height=\"244\" data-constrained=\"true\" \/><\/li>\n<li>Congratulations!\u00a0You have a tabular project that is configuration-aware, self-deploys, and self-processes.<\/li>\n<\/ol>\n<h3>Conclusion<\/h3>\n<p>Again, this method is an extension of the method used by Cathy Dumas. With a bit of XML knowledge, you can extend and improve this method to accomplish any number of things. It can be modified to use multiple data sources, changing the data source type, or adjusting the authentication to the Analysis Services instance. An enterprising sort might even be able to use it to hide or remove tables completely from the model. With this method, you can have quite a bit more control over deployment versus using the default.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>With some MS Build extensions and some XML and PowerShell knowledge, you can roll your own configuration-aware tabular projects.<\/p>\n","protected":false},"author":21,"featured_media":14883,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"content-type":"","footnotes":""},"categories":[297],"tags":[304,347],"class_list":["post-16049","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-data-platform","tag-modern-data-platform","tag-ssas","topics-blog"],"acf":[],"_links":{"self":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/16049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/comments?post=16049"}],"version-history":[{"count":0,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/posts\/16049\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media\/14883"}],"wp:attachment":[{"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/media?parent=16049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/categories?post=16049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/3cloudsolutions.com\/wp-json\/wp\/v2\/tags?post=16049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}