<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Code Smart Not Hard</title>
    <link>http://www.codesmartnothard.com/</link>
    <description>Continuous Learning and Sharing of Team Foundation Server and Application Lifecycle Management</description>
    <language>en-us</language>
    <copyright>Mike Douglas</copyright>
    <lastBuildDate>Tue, 13 Dec 2011 09:33:00 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>mikedouglasdev@gmail.com</managingEditor>
    <webMaster>mikedouglasdev@gmail.com</webMaster>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=ad951488-68b8-4077-a918-c0f456233e07</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,ad951488-68b8-4077-a918-c0f456233e07.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,ad951488-68b8-4077-a918-c0f456233e07.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=ad951488-68b8-4077-a918-c0f456233e07</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Team Foundation Server 2010 provides functionality for testing applications with built
in support for test plan and test case management    In our Agile/Scrum
projects, we define all of the Test Cases in our planning meeting to define done for
each User Story.  When starting new projects, team members often ask is how to
format the Test Cases so they are clear.  One way we have found to be very useful
is to use the same format as found in <a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank">Behavior
Driven Development</a>(BDD).  BDD uses a format for communicating Test Cases
called Gherkin.  The Gherkin format follows the pattern below:
</p>
        <p align="center">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_thumb.png" width="240" height="124" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 1 – Given, When, and Then definition</strong>
        </p>
        <p>
Just like the User Story format (As a [user], I want to be able to do [business process],
so that [business value]), we have found the Gherkin format is very useful for teams
learning Agile.  In fact, these Test Cases can be written for Acceptance/Functional
tests and for Unit Tests.  When we work with customers and our own projects we
install our customized Deliveron Agile Process Template as part of the Deliveron Agile
Delivery Process.  The Deliveron Agile Process Template is a slightly customized
version of the MSF for Agile 5.0 process template.  In the Test Case work item,
we have added fields for Given, When, and Then.  The “Then” should also match
the expected result in the test steps.
</p>
        <p align="center">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/SNAGHTML3f2b686e.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML3f2b686e" border="0" alt="SNAGHTML3f2b686e" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/SNAGHTML3f2b686e_thumb.png" width="640" height="158" />
          </a>
          <br />
          <strong>Figure 2 – BDD additions for TFS Test Case Work Item</strong>
        </p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_thumb_1.png" width="644" height="37" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 3 – Expected result matches the “Then”</strong>
        </p>
        <p align="left">
Customizing the TFS Test Case Work Item Templates (WIT)  to add these fields
is straight forward.  Follow the steps in this <a href="http://www.codesmartnothard.com/2009/11/27/StepsToModifyAWorkItemTemplateInTeamFoundationServer2008.aspx" target="_blank">post</a> I
did a couple years ago.  It was for TFS 2008 but the steps are the same in TFS
2010.
</p>
        <p align="left">
In summary, use Test Cases to define done of the User Story and use BDD and Gherkin
for the language of the Test Case.  Feel free to contact us if you have any questions
about these changes or about the Deliveron Agile Delivery Process.
</p>
        <p>
This has also be cross posted at <a title="http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx" href="http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx">http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx</a></p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=ad951488-68b8-4077-a918-c0f456233e07" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Adding BDD to TFS 2010 Test Cases</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,ad951488-68b8-4077-a918-c0f456233e07.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/12/13/AddingBDDToTFS2010TestCases.aspx</link>
      <pubDate>Tue, 13 Dec 2011 09:33:00 GMT</pubDate>
      <description>&lt;p&gt;
Team Foundation Server 2010 provides functionality for testing applications with built
in support for test plan and test case management&amp;nbsp;&amp;nbsp;&amp;nbsp; In our Agile/Scrum
projects, we define all of the Test Cases in our planning meeting to define done for
each User Story.&amp;nbsp; When starting new projects, team members often ask is how to
format the Test Cases so they are clear.&amp;nbsp; One way we have found to be very useful
is to use the same format as found in &lt;a href="http://en.wikipedia.org/wiki/Behavior_Driven_Development" target="_blank"&gt;Behavior
Driven Development&lt;/a&gt;(BDD).&amp;nbsp; BDD uses a format for communicating Test Cases
called Gherkin.&amp;nbsp; The Gherkin format follows the pattern below:
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_thumb.png" width="240" height="124"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 1 – Given, When, and Then definition&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Just like the User Story format (As a [user], I want to be able to do [business process],
so that [business value]), we have found the Gherkin format is very useful for teams
learning Agile.&amp;nbsp; In fact, these Test Cases can be written for Acceptance/Functional
tests and for Unit Tests.&amp;nbsp; When we work with customers and our own projects we
install our customized Deliveron Agile Process Template as part of the Deliveron Agile
Delivery Process.&amp;nbsp; The Deliveron Agile Process Template is a slightly customized
version of the MSF for Agile 5.0 process template.&amp;nbsp; In the Test Case work item,
we have added fields for Given, When, and Then.&amp;nbsp; The “Then” should also match
the expected result in the test steps.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/SNAGHTML3f2b686e.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML3f2b686e" border="0" alt="SNAGHTML3f2b686e" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/SNAGHTML3f2b686e_thumb.png" width="640" height="158"&gt;&lt;/a&gt; 
&lt;br&gt;
&lt;strong&gt;Figure 2 – BDD additions for TFS Test Case Work Item&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Adding-a-little-BDD-to-TFS-Test-Case_CFAB/image_thumb_1.png" width="644" height="37"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 3 – Expected result matches the “Then”&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
Customizing the TFS Test Case Work Item Templates (WIT)&amp;nbsp; to add these fields
is straight forward.&amp;nbsp; Follow the steps in this &lt;a href="http://www.codesmartnothard.com/2009/11/27/StepsToModifyAWorkItemTemplateInTeamFoundationServer2008.aspx" target="_blank"&gt;post&lt;/a&gt; I
did a couple years ago.&amp;nbsp; It was for TFS 2008 but the steps are the same in TFS
2010.
&lt;/p&gt;
&lt;p align="left"&gt;
In summary, use Test Cases to define done of the User Story and use BDD and Gherkin
for the language of the Test Case.&amp;nbsp; Feel free to contact us if you have any questions
about these changes or about the Deliveron Agile Delivery Process.
&lt;/p&gt;
&lt;p&gt;
This has also be cross posted at &lt;a title="http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx" href="http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx"&gt;http://www.deliveron.com/blog/post/Adding-BDD-to-the-TFS-2010-Test-Case.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=ad951488-68b8-4077-a918-c0f456233e07" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,ad951488-68b8-4077-a918-c0f456233e07.aspx</comments>
      <category>Agile</category>
      <category>ALM</category>
      <category>Test Case Management</category>
      <category>TFS 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=3448c757-600c-476a-9b69-2bf87b8d74aa</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,3448c757-600c-476a-9b69-2bf87b8d74aa.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,3448c757-600c-476a-9b69-2bf87b8d74aa.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=3448c757-600c-476a-9b69-2bf87b8d74aa</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">I recently worked with a client to create a fairly comprehensive solution
for implementing Continuous Integration and Delivery for SQL Server Databases using
Visual Studio 2010 Database Projects.  I had the opportunity to give a talk on
the project at SQL Saturday in Omaha.  The presentation is <a href="http://www.sqlsaturday.com/viewsession.aspx?sat=91&amp;sessionid=5537" target="_blank">here</a> if
you want the slides.  I think there is some context missing with the slides alone
so I wanted to do this post to further explain the solution.</font>
        </p>
        <p>
          <font size="2">Before talking about the solution, let me describe three different
continuous processes.  Continuous Integration (CI) is most familiar and is often
used to describe all three of these processes.  I think the differences between
these three processes is more clear by using these terms.</font>
        </p>
        <p>
 
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb.png" width="240" height="90" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 1 – Continuous Processes</strong>
        </p>
        <p>
          <font size="2">
            <strong>Continuous Integration</strong> – Verifying code quality by
compiling and running unit tests on the build server when a developer checks in changes. 
Often abbreviated as CI.</font>
        </p>
        <p>
          <font size="2">
            <strong>Continuous Delivery</strong> – Adds the deployment of the application
and database to an isolated test environment where additional integrated and UI automated
tests can be run.  </font>
        </p>
        <p>
          <font size="2">
            <strong>Continuous Deployment</strong> – Includes automated deployment
of the application through each environment through production.</font>
        </p>
        <p>
          <font size="2">In this post I will primary review our solution for CI and Continuous
Delivery.  This works lays the foundation for the deployment into Staging and
Production but I will discuss this in a future post.</font>
        </p>
        <h3>Database Projects
</h3>
        <p>
          <font size="2">Database tools in the past have been different than the tools used
application code development.  These database tools have been difficult to implement
change management practices and Application Lifecycle Management (ALM) practices. 
Today there is an increasingly amount of application developers managing database
changes.   These are some of the reasons that have led to need for a tool
like Visual Studio Database Projects (DBPro for short).  This tool is part of
Visual Studio 2010 (Premium and higher).  To create a Visual Studio Database
Project, select SQL Server from the process template menu and then choose SQL Server
2008 Wizard or SQL Server 2008 Database Project. </font>
        </p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_28.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_13.png" width="504" height="350" />
          </a>
        </p>
        <p align="center">
          <strong>
            <font size="1">Figure 2 – SQL Server Database Project Templates in Visual
Studio 2010</font>
          </strong>
        </p>
        <p>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2">The primary purpose of the Database Projects are to manage the the
version control of database objects in SQL Server databases. The solution we established
utilizes this and many of the features of DBPro including TFS Build Integration, Data
Generation, Database Unit Testing, Static Code Analysis, and Database and Data Deployments. 
In this post I’m not going to cover how to use all of these features but focus on
how to implement the features for Continuous Integration, Delivery and Deployment
processes.  For more information, please take a look at the Visual Studio ALM
Rangers </font>
          <a href="http://vsdatabaseguide.codeplex.com/" target="_blank">
            <font size="2">Visual
Studio Database Guide</font>
          </a>
          <font size="2">.  This solution is complimentary
to the guide and goes into more more specifics for CI.</font>
        </p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_1.png" width="450" height="306" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 3 – Visual Studio Database Guide</strong>
        </p>
        <h4 align="left">Challenges
</h4>
        <p align="left">
          <font size="2">Visual Studio Database Projects are a great tool and I highly recommend
teams utilize these for managing version control for the SQL Server Databases. 
However, successfully using Database Projects can be challenging.</font>
          <font size="2"> 
I believe the benefits greatly out weigh the challenges but it is important for the
team to be aware of these for a successful implementation.</font>
        </p>
        <p align="left">
          <font size="2">
            <strong>Visual Studio</strong> – Visual Studio probably seems like
an odd challenge considering this is the tool to use for the solution, however Visual
Studio is a beast.  Visual Studio has become everything development.  Developers
are used to Visual Studio and I have seen DBAs and other database professions get
frustrated using it when they first start.  Stay with it.  It will get easier
and is the future direction of Microsoft in SQL Server 2012.  From what I have
seen SQL Server Management Studio 2012 is based on Visual Studio.</font>
        </p>
        <p align="left">
          <font size="2">
            <strong>“Truth Center” Shift</strong> – Development teams have been
used to using a shared database server and making changes directly on server since
the stone age.  Managing source control of the database in DBPro essentially
changes the “truth center” of the database project to DBPro.  Changes to the
schema should be made in DBPro and then executed or deployed from DBPro to the shared
server.  Development can also be done in local sandbox called offline schema
development where the developer can make the changes locally and check them in. 
Changes made directly to the shared SQL Server database risk being overwritten by
the next deployment from DBPro.</font>
        </p>
        <p align="left">
          <font size="2">
            <strong>Permissions</strong> – I have found DBPro does a great job
managing almost all of the artifacts for databases.  The biggest challenge and
frustration has been permissions.  The problem is that the database project holds
the specific version of the database.  For permissions this doesn’t work in most
real world examples because permissions change in each environment.  For examples,
developers need different permissions in development versus what they need in production. 
In addition, many enterprises use a separate domain for each environment.  As
shown in <strong>Figure 4</strong> below, Database Roles for the most part are consistent
between environments and primarily the users and their role membership in those roles
will vary.  The best method I found for handling these permission differences
is to exclude them altogether.  Use the following steps to handle permissions
when importing the schema and adding new objects to the project.  One advantage
of removing the users is that that they are normally connected to a login and the
login lives outside of the database in the Master database.  Including the users
and logins in the project requires an additional project called SQL Server Server
Project that contains the Master database.  This solution does not require a
SQL Server Server Project.</font>
        </p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_14.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_6.png" width="404" height="209" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 4 – Managing Permissions Across Environments</strong>
        </p>
        <p align="left">
          <strong>
            <font size="2">Importing Databases </font>
          </strong>
        </p>
        <p align="left">
          <font size="2">When using the importing the schema and objects into your project,
make sure you perform the following steps to first import all of the permissions and
the remove those that will change in different events.</font>
        </p>
        <ul>
          <li>
            <div align="left">
              <font size="2">Enable Import permissions in the Import Wizard to
import all of the permissions including Roles, Users, and Role Membership.</font>
            </div>
          </li>
          <li>
            <div align="left">
              <font size="2">After Import has completed:</font>
            </div>
            <ul>
              <li>
                <div align="left">
                  <font size="2">Role permissions are to be kept in the .sqlpermissions
file. </font>
                </div>
              </li>
              <li>
                <div align="left">
                  <font size="2">Schema Users (without login) are to be kept. </font>
                </div>
              </li>
              <li>
                <div align="left">
                  <font size="2">The other users must be removed</font>
                </div>
                <ul>
                  <li>
                    <div align="left">
                      <font size="2">from sqlpermissions </font>
                    </div>
                  </li>
                  <li>
                    <div align="left">
                      <font size="2">From Security\Users </font>
                    </div>
                  </li>
                  <li>
                    <div align="left">
                      <font size="2">From RoleMemberships </font>
                    </div>
                  </li>
                </ul>
              </li>
            </ul>
          </li>
        </ul>
        <p align="left">
          <font size="2">
            <strong>Adding New Objects</strong>
          </font>
        </p>
        <p align="left">
          <font size="2">When adding new objects in the Database Project </font>
        </p>
        <ul>
          <li>
            <div align="left">
              <font size="2">Use Schema View</font>
            </div>
          </li>
          <li>
            <div align="left">
              <font size="2">Manually modify the Properties\Database.sqlpermissions
and add the new permission</font>
            </div>
            <ul>
              <li>
                <div align="left">
                  <font size="2">EX: Grant Execute to Role for Stored Procedures 
<permissionstatement action="GRANT"><permission>
EXECUTE
</permission><grantee>
TestRole
</grantee></permissionstatement></font>
                </div>
              </li>
            </ul>
          </li>
        </ul>
        <blockquote>
          <pre class="csharpcode">
            <span class="kwrd">&lt;</span>
            <span class="html">PermissionStatement</span>
            <span class="attr">Action</span>
            <span class="kwrd">="GRANT"</span>
            <span class="kwrd">&gt;</span>
            <span class="kwrd">&lt;</span>
            <span class="html">Permission</span>
            <span class="kwrd">&gt;</span>EXECUTE<span class="kwrd">&lt;/</span><span class="html">Permission</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">Grantee</span><span class="kwrd">&gt;</span>TestRole<span class="kwrd">&lt;/</span><span class="html">Grantee</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;</span><span class="html">Object</span><span class="attr">Name</span><span class="kwrd">="spTestFromSSMS2"</span><span class="attr">Schema</span><span class="kwrd">="dbo"</span><span class="attr">Type</span><span class="kwrd">="OBJECT"</span><span class="kwrd">/&gt;</span><span class="kwrd">&lt;</span><span class="html">Grantor</span><span class="kwrd">&gt;</span>dbo<span class="kwrd">&lt;/</span><span class="html">Grantor</span><span class="kwrd">&gt;</span><span class="kwrd">&lt;/</span><span class="html">PermissionStatement</span><span class="kwrd">&gt;</span></pre>
        </blockquote>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <h4 align="left">
          <font size="2">Permission Scripts</font>
        </h4>
        <p align="left">
          <font size="2">By removing the permissions from the project, there needs to be a place
to account for these.  This solution accomplishes this by creating a script in
the Scripts folder for environment that essentially creates the logins, users, and
assigns the role membership for each user.  This allows the flexibility to store
any variations between the environments and still store these in the database project
and in source control.  Do not set the Build Action to PostDeploy because you
can only have one for each project and it will be combined with the Deployment script.  
Instead set the “Copy to Output Directory” property on the script to “Copy Always”. 
This will create an Scripts folder and the permission files in the build output directory
so it can be called by the deployment scripts.</font>
        </p>
        <h4 align="left">Source Control
</h4>
        <p align="left">
          <font size="2">The primary benefit for using the Database Projects is that all of
the database changes can be managed in source control.  There are a lot of ways
to organize your source control and with branching and merging this can become complex
to manage.  I like to take a pragmatic approach to source control and keep things
simple but allow for complexity if needed in the future.  The <a href="http://tfsbranchingguideiii.codeplex.com/" target="_blank">Visual
Studio TFS Branching Build 2010</a> is a great reference for adopting branching and
merging strategy.  For this post I want to simply show the relationships between
Production, Development, and Work Orders.  The main points is that the database
projects should be branched and merged along side the application source control with
some sort of release branch that has the current production version.  The Work
Order branch is for production support changes that will be made into production. 
Development teams should do downward merges often to always have any work order changes
incorporated early.  When the application and database changes are deployed to
production, the development branch should be merged up to the Production branch. 
The diagrams below show how this is organized from a logic view and physical view.</font>
        </p>
        <p align="left">
          <font size="2">
            <strong>Logical View</strong>
          </font>
        </p>
        <p align="center">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_30.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_14.png" width="400" height="238" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 5 – Logical View of the Database Project Source Control Branches</strong>
        </p>
        <p align="left">
 
</p>
        <p align="left">
          <strong>
            <font size="2">Physical view</font>
          </strong>
        </p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_32.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_15.png" width="400" height="248" />
          </a>
        </p>
        <h3 align="left">
        </h3>
        <p align="center">
          <strong>Figure 6 – Physical View of the Database Project Source Control Branches</strong>
        </p>
        <h4 align="left">Continuous Integration (CI)
</h4>
        <p align="left">
          <font size="2">To setup the most basic CI process for your Database projects, you
can simply add the Solutions containing the database projects to your CI build that
is building your application code.  The benefit of this is that it will build
your database projects and validate that there are no schema errors and can validate
any static code analysis rules.</font>
        </p>
        <h4 align="left">Continuous Delivery
</h4>
        <p align="left">
          <font size="2">For Continuous Delivery, we want to expand the process to include deploying
the database, insert any test data we need, and then run the database unit tests. 
This adds validation that the schema in source control can correctly build the database
and that stored procedures can pass any number of validations with the unit tests. 
These steps would look like the following:</font>
        </p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_6.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_2.png" width="200" height="262" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 7 – Simple Continuous Delivery Process</strong>
        </p>
        <p align="left">
          <font size="2">Visual Studio Database projects make implementing this process very
simple and only requires a couple simple settings.  The dialog below shows the
out of the box settings.  To open this dialog, select Test &gt; Test Configuration
from the menu.   The sections are slightly out of order.  To start
we want to set the Deployment database project to the project we want to deploy. 
Next choose the configuration.  The configuration settings in the database project
will specify the target connection string and other deployment properties.  Next,
the Database state setting will generate the test data for the unit tests by running
one of the data generation plans.</font>
        </p>
        <p align="left">
 
</p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_8.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_3.png" width="454" height="569" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 8 – Database Test Settings</strong>
        </p>
        <h4 align="left">Types of Continuous Delivery
</h4>
        <p align="left">
          <font size="2">The example above basically deploys the current version of the schema
to the target but doesn’t is not a good practice run into production.  
It basically deploys the changes from the last deployment.  My goal of the Continuous
Delivery process should be a practice run into production and essentially deploy the
application and database the way it will be done for the production deployment.  
There are two types of delivery based on whether or not the application is already
in production.  For new systems that haven’t been deployed to production, the
deployment will be to deploy all of the schema.  This is referred to as <strong>Greenfield</strong>. 
For existing systems, the schema will the difference of what is currently in production
with what has been developed.  This is referred to as <strong>Brownfield</strong> deployments.</font>
        </p>
        <p align="left">
          <font size="2">From a Visual Studio Database Project standpoint, Greenfield deployments
are a simple using the deploy option.  This will drop the database and execute
the full schema script to create the database.</font>
        </p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_10.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_4.png" width="404" height="82" />
          </a>
        </p>
        <p align="center">
          <strong>
            <font size="1">Figure 9 – Greenfield Process</font>
          </strong>
        </p>
        <p align="left">
          <font size="2">For Brownfield deployments in Visual Studio Database Projects, the
process is accomplished in two steps using Production and Development versions of
the database projects.  The first step is to use the Production version of the
Database Project to create the full CREATE script.  Next, use the compare feature
to compare the Production and Development versions to create the DELTA script. 
Again, the key is not to compare the development against the live production database
but to use the version of the Database Project that was created either from the production
database or from the Release branch in source control.  Once you have these two
database scripts, run the CREATE script to drop the database and create the database
to the production level.  Then execute DELTA script to bring it to the current
development level.  From there you can follow the similar steps to execute the
data generation plan and automated tests to complete.  See below to see how this
fits together </font>
        </p>
        <p align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_12.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_5.png" width="404" height="212" />
          </a>
        </p>
        <p align="center">
          <strong>
            <font size="1">Figure 10 – Brownfield Process</font>
          </strong>
        </p>
        <p align="left">
          <font size="2">Putting this all together, here are the steps in order for a good SQL
Server database Continuous Delivery process.  There is some customization that
has to be done for this.  The database testing options that were available for
the simple process, won’t work out of the box for this solution.  This is because
the Database Project doesn’t know about the production and delta scripts.  The
build by default would create the database and run the data generation plan before
unit tests including the database unit tests.  However, the unit tests are run
immediately after the application is built and we need to specify the a step to build
create the scripts and then execute them.  I customized the build definition
by moving the unit test execution activities to later in the process so I could execute
the SQL scripts before the Unit Tests are run.  Once this was moved, I could
use the built in features to run the data generation plan.  Below are the steps
for the full end to end Database Continuous Delivery process.</font>
        </p>
        <h3 align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_24.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_11.png" width="200" height="338" />
          </a>
        </h3>
        <p align="center">
          <font size="1">
            <strong>Figure 11 – End to End Database Continuous Delivery Process</strong>
          </font>
        </p>
        <p align="left">
          <font size="2">To combine this process into the application continuous delivery process,
the same tasks above can executed along with the application steps.  This process
is grouped into three groups: Build/Stage, Deploy, and Execute Automated Tests. 
The process is outlined below.</font>
        </p>
        <h3 align="left">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_26.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_12.png" width="500" height="312" />
          </a>
        </h3>
        <p align="center">
          <strong>Figure 12 – End to End Application and Database Continuous Delivery Process</strong>
        </p>
        <h3 align="left"> 
</h3>
        <h3 align="left"> 
</h3>
        <h3 align="left">VSDBCMD
</h3>
        <p>
          <font size="2">One of the great features of Visual Studio Database Projects is that
the deployment and compare functionality can be executed via a command line utility
called VSDBCMD.exe.  This allows us to perform the necessary steps in our Continuous
Delivery process.  I utilize a InvokeProcess Activity in the build definition
to call a PowerShell script to execute the VSDBCMD commands.  Below are examples
of how to create the Production CREATE script and the DELTA script.  The Production
Script creates the full CREATE script from the compiled Production version of the
Database Project.  The DELTA command shows how to compare two Database Projects
to generate the DELTA SQL Script.</font>
        </p>
        <p>
 
</p>
        <p>
          <strong>
            <font size="2">Create Production Script</font>
          </strong>
        </p>
        <blockquote>
          <pre class="csharpcode">&amp; <span class="str">"C:\program files (x86)\Microsoft
Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd.exe"</span></pre>
          <pre class="csharpcode">/a:deploy /dsp:sql /model:Ecommerce.dbschema /DeploymentScriptFile:c:\temp\OutputFilename2.sql </pre>
          <pre class="csharpcode">/p:TargetDatabase=<span class="str">"NewEcommerce"</span></pre>
          <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        </blockquote>
        <p>
  
</p>
        <p>
          <strong>
            <font size="2">Create Production and Development Delta Script</font>
          </strong>
        </p>
        <blockquote>
          <pre class="csharpcode">&amp; <span class="str">"C:\program files (x86)\Microsoft
Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd.exe"</span></pre>
          <pre class="csharpcode">/a:deploy /dsp:sql /model:Ecommerce.dbschema /DeploymentScriptFile:c:\temp\OutputFilename2.sql </pre>
          <pre class="csharpcode">/targetmodelfile:<span class="str">"C:\tfs\deliveron\Production\EcommerceSolution\Ecommerce\obj\Debug\ecommerce.dbschema"</span></pre>
          <pre class="csharpcode">/p:TargetDatabase=<span class="str">"NewEcommerce"</span></pre>
        </blockquote>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <h3 align="left"> 
</h3>
        <style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <h3 align="left">In Summary
</h3>
        <p align="left">
          <font size="2">This concludes the overview of the solution for Continuous Integration
and Delivery for SQL Server Databases.  I hope it gives you a complete overview
for creating your own Continuous Delivery process.  Feel free to contact me if
you have any questions or comments.</font>
        </p>
        <p align="left">
          <font size="2">
            <strong>Review of Key Concepts</strong>
          </font>
        </p>
        <ul>
          <li>
            <div align="left">
              <font size="2">There are three types of Continuous processes: Integration,
Delivery, and Deployment.</font>
            </div>
          </li>
          <li>
            <div align="left">
              <font size="2">Continuous Delivery should be set up to be a practice
run for Production.</font>
            </div>
          </li>
          <li>
            <div align="left">
              <font size="2">Create compare scripts between development and production
database projects and don’t compare against live databases.</font>
            </div>
          </li>
          <li>
            <div align="left">
              <font size="2">VSDBCMD is a command line utility that perform the
deployment and compare functionality in Visual Studio Database Projects.</font>
            </div>
          </li>
        </ul>
        <p>
This was also cross posted at <a title="http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx" href="http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx">http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx</a></p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=3448c757-600c-476a-9b69-2bf87b8d74aa" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Implementing Continuous Integration (CI) and Delivery for SQL Server Databases</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,3448c757-600c-476a-9b69-2bf87b8d74aa.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/10/31/ImplementingContinuousIntegrationCIAndDeliveryForSQLServerDatabases.aspx</link>
      <pubDate>Mon, 31 Oct 2011 07:52:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;I recently worked with a client to create a fairly comprehensive solution
for implementing Continuous Integration and Delivery for SQL Server Databases using
Visual Studio 2010 Database Projects.&amp;nbsp; I had the opportunity to give a talk on
the project at SQL Saturday in Omaha.&amp;nbsp; The presentation is &lt;a href="http://www.sqlsaturday.com/viewsession.aspx?sat=91&amp;amp;sessionid=5537" target="_blank"&gt;here&lt;/a&gt; if
you want the slides.&amp;nbsp; I think there is some context missing with the slides alone
so I wanted to do this post to further explain the solution.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;Before talking about the solution, let me describe three different
continuous processes.&amp;nbsp; Continuous Integration (CI) is most familiar and is often
used to describe all three of these processes.&amp;nbsp; I think the differences between
these three processes is more clear by using these terms.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb.png" width="240" height="90"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 1 – Continuous Processes&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;Continuous Integration&lt;/strong&gt; – Verifying code quality by
compiling and running unit tests on the build server when a developer checks in changes.&amp;nbsp;
Often abbreviated as CI.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;Continuous Delivery&lt;/strong&gt; – Adds the deployment of the application
and database to an isolated test environment where additional integrated and UI automated
tests can be run.&amp;nbsp; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;strong&gt;Continuous Deployment&lt;/strong&gt; – Includes automated deployment
of the application through each environment through production.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;In this post I will primary review our solution for CI and Continuous
Delivery.&amp;nbsp; This works lays the foundation for the deployment into Staging and
Production but I will discuss this in a future post.&lt;/font&gt;
&lt;/p&gt;
&lt;h3&gt;Database Projects
&lt;/h3&gt;
&lt;p&gt;
&lt;font size="2"&gt;Database tools in the past have been different than the tools used
application code development.&amp;nbsp; These database tools have been difficult to implement
change management practices and Application Lifecycle Management (ALM) practices.&amp;nbsp;
Today there is an increasingly amount of application developers managing database
changes.&amp;nbsp;&amp;nbsp; These are some of the reasons that have led to need for a tool
like Visual Studio Database Projects (DBPro for short).&amp;nbsp; This tool is part of
Visual Studio 2010 (Premium and higher).&amp;nbsp; To create a Visual Studio Database
Project, select SQL Server from the process template menu and then choose SQL Server
2008 Wizard or SQL Server 2008 Database Project. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_28.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_13.png" width="504" height="350"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;&lt;font size="1"&gt;Figure 2 – SQL Server Database Project Templates in Visual
Studio 2010&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;The primary purpose of the Database Projects are to manage the the
version control of database objects in SQL Server databases. The solution we established
utilizes this and many of the features of DBPro including TFS Build Integration, Data
Generation, Database Unit Testing, Static Code Analysis, and Database and Data Deployments.&amp;nbsp;
In this post I’m not going to cover how to use all of these features but focus on
how to implement the features for Continuous Integration, Delivery and Deployment
processes.&amp;nbsp; For more information, please take a look at the Visual Studio ALM
Rangers &lt;/font&gt;&lt;a href="http://vsdatabaseguide.codeplex.com/" target="_blank"&gt;&lt;font size="2"&gt;Visual
Studio Database Guide&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&amp;nbsp; This solution is complimentary
to the guide and goes into more more specifics for CI.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_1.png" width="450" height="306"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 3 – Visual Studio Database Guide&lt;/strong&gt;
&lt;/p&gt;
&lt;h4 align="left"&gt;Challenges
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;Visual Studio Database Projects are a great tool and I highly recommend
teams utilize these for managing version control for the SQL Server Databases.&amp;nbsp;
However, successfully using Database Projects can be challenging.&lt;/font&gt;&lt;font size="2"&gt;&amp;nbsp;
I believe the benefits greatly out weigh the challenges but it is important for the
team to be aware of these for a successful implementation.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;Visual Studio&lt;/strong&gt; – Visual Studio probably seems like
an odd challenge considering this is the tool to use for the solution, however Visual
Studio is a beast.&amp;nbsp; Visual Studio has become everything development.&amp;nbsp; Developers
are used to Visual Studio and I have seen DBAs and other database professions get
frustrated using it when they first start.&amp;nbsp; Stay with it.&amp;nbsp; It will get easier
and is the future direction of Microsoft in SQL Server 2012.&amp;nbsp; From what I have
seen SQL Server Management Studio 2012 is based on Visual Studio.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;“Truth Center” Shift&lt;/strong&gt; – Development teams have been
used to using a shared database server and making changes directly on server since
the stone age.&amp;nbsp; Managing source control of the database in DBPro essentially
changes the “truth center” of the database project to DBPro.&amp;nbsp; Changes to the
schema should be made in DBPro and then executed or deployed from DBPro to the shared
server.&amp;nbsp; Development can also be done in local sandbox called offline schema
development where the developer can make the changes locally and check them in.&amp;nbsp;
Changes made directly to the shared SQL Server database risk being overwritten by
the next deployment from DBPro.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;Permissions&lt;/strong&gt; – I have found DBPro does a great job
managing almost all of the artifacts for databases.&amp;nbsp; The biggest challenge and
frustration has been permissions.&amp;nbsp; The problem is that the database project holds
the specific version of the database.&amp;nbsp; For permissions this doesn’t work in most
real world examples because permissions change in each environment.&amp;nbsp; For examples,
developers need different permissions in development versus what they need in production.&amp;nbsp;
In addition, many enterprises use a separate domain for each environment.&amp;nbsp; As
shown in &lt;strong&gt;Figure 4&lt;/strong&gt; below, Database Roles for the most part are consistent
between environments and primarily the users and their role membership in those roles
will vary.&amp;nbsp; The best method I found for handling these permission differences
is to exclude them altogether.&amp;nbsp; Use the following steps to handle permissions
when importing the schema and adding new objects to the project.&amp;nbsp; One advantage
of removing the users is that that they are normally connected to a login and the
login lives outside of the database in the Master database.&amp;nbsp; Including the users
and logins in the project requires an additional project called SQL Server Server
Project that contains the Master database.&amp;nbsp; This solution does not require a
SQL Server Server Project.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_6.png" width="404" height="209"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 4 – Managing Permissions Across Environments&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;strong&gt;&lt;font size="2"&gt;Importing Databases &lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;When using the importing the schema and objects into your project,
make sure you perform the following steps to first import all of the permissions and
the remove those that will change in different events.&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Enable Import permissions in the Import Wizard to
import all of the permissions including Roles, Users, and Role Membership.&lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;After Import has completed:&lt;/font&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Role permissions are to be kept in the .sqlpermissions
file. &lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Schema Users (without login) are to be kept. &lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;The other users must be removed&lt;/font&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;from sqlpermissions &lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;From Security\Users &lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;From RoleMemberships &lt;/font&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;Adding New Objects&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;When adding new objects in the Database Project &lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Use Schema View&lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Manually modify the Properties\Database.sqlpermissions
and add the new permission&lt;/font&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;EX: Grant Execute to Role for Stored Procedures 
&lt;permissionstatement action="GRANT"&gt;
&lt;permission&gt;
EXECUTE
&lt;/permission&gt;
&lt;grantee&gt;
TestRole
&lt;/grantee&gt;
&lt;/font&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;  &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;PermissionStatement&lt;/span&gt; &lt;span class="attr"&gt;Action&lt;/span&gt;&lt;span class="kwrd"&gt;="GRANT"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Permission&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;EXECUTE&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Permission&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grantee&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;TestRole&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grantee&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Object&lt;/span&gt; &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="spTestFromSSMS2"&lt;/span&gt; &lt;span class="attr"&gt;Schema&lt;/span&gt;&lt;span class="kwrd"&gt;="dbo"&lt;/span&gt; &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="OBJECT"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;Grantor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;dbo&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;Grantor&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;PermissionStatement&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;h4 align="left"&gt;&lt;font size="2"&gt;Permission Scripts&lt;/font&gt;
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;By removing the permissions from the project, there needs to be a place
to account for these.&amp;nbsp; This solution accomplishes this by creating a script in
the Scripts folder for environment that essentially creates the logins, users, and
assigns the role membership for each user.&amp;nbsp; This allows the flexibility to store
any variations between the environments and still store these in the database project
and in source control.&amp;nbsp; Do not set the Build Action to PostDeploy because you
can only have one for each project and it will be combined with the Deployment script.&amp;nbsp;&amp;nbsp;
Instead set the “Copy to Output Directory” property on the script to “Copy Always”.&amp;nbsp;
This will create an Scripts folder and the permission files in the build output directory
so it can be called by the deployment scripts.&lt;/font&gt;
&lt;/p&gt;
&lt;h4 align="left"&gt;Source Control
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;The primary benefit for using the Database Projects is that all of
the database changes can be managed in source control.&amp;nbsp; There are a lot of ways
to organize your source control and with branching and merging this can become complex
to manage.&amp;nbsp; I like to take a pragmatic approach to source control and keep things
simple but allow for complexity if needed in the future.&amp;nbsp; The &lt;a href="http://tfsbranchingguideiii.codeplex.com/" target="_blank"&gt;Visual
Studio TFS Branching Build 2010&lt;/a&gt; is a great reference for adopting branching and
merging strategy.&amp;nbsp; For this post I want to simply show the relationships between
Production, Development, and Work Orders.&amp;nbsp; The main points is that the database
projects should be branched and merged along side the application source control with
some sort of release branch that has the current production version.&amp;nbsp; The Work
Order branch is for production support changes that will be made into production.&amp;nbsp;
Development teams should do downward merges often to always have any work order changes
incorporated early.&amp;nbsp; When the application and database changes are deployed to
production, the development branch should be merged up to the Production branch.&amp;nbsp;
The diagrams below show how this is organized from a logic view and physical view.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;Logical View&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_30.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_14.png" width="400" height="238"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 5 – Logical View of the Database Project Source Control Branches&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;strong&gt;&lt;font size="2"&gt;Physical view&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_32.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_15.png" width="400" height="248"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h3 align="left"&gt;
&lt;/h3&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 6 – Physical View of the Database Project Source Control Branches&lt;/strong&gt;
&lt;/p&gt;
&lt;h4 align="left"&gt;Continuous Integration (CI)
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;To setup the most basic CI process for your Database projects, you
can simply add the Solutions containing the database projects to your CI build that
is building your application code.&amp;nbsp; The benefit of this is that it will build
your database projects and validate that there are no schema errors and can validate
any static code analysis rules.&lt;/font&gt;
&lt;/p&gt;
&lt;h4 align="left"&gt;Continuous Delivery
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;For Continuous Delivery, we want to expand the process to include deploying
the database, insert any test data we need, and then run the database unit tests.&amp;nbsp;
This adds validation that the schema in source control can correctly build the database
and that stored procedures can pass any number of validations with the unit tests.&amp;nbsp;
These steps would look like the following:&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_2.png" width="200" height="262"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 7 – Simple Continuous Delivery Process&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;Visual Studio Database projects make implementing this process very
simple and only requires a couple simple settings.&amp;nbsp; The dialog below shows the
out of the box settings.&amp;nbsp; To open this dialog, select Test &amp;gt; Test Configuration
from the menu.&amp;nbsp;&amp;nbsp; The sections are slightly out of order.&amp;nbsp; To start
we want to set the Deployment database project to the project we want to deploy.&amp;nbsp;
Next choose the configuration.&amp;nbsp; The configuration settings in the database project
will specify the target connection string and other deployment properties.&amp;nbsp; Next,
the Database state setting will generate the test data for the unit tests by running
one of the data generation plans.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_3.png" width="454" height="569"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 8 – Database Test Settings&lt;/strong&gt;
&lt;/p&gt;
&lt;h4 align="left"&gt;Types of Continuous Delivery
&lt;/h4&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;The example above basically deploys the current version of the schema
to the target but doesn’t is not a good practice run into production.&amp;nbsp;&amp;nbsp;
It basically deploys the changes from the last deployment.&amp;nbsp; My goal of the Continuous
Delivery process should be a practice run into production and essentially deploy the
application and database the way it will be done for the production deployment.&amp;nbsp;&amp;nbsp;
There are two types of delivery based on whether or not the application is already
in production.&amp;nbsp; For new systems that haven’t been deployed to production, the
deployment will be to deploy all of the schema.&amp;nbsp; This is referred to as &lt;strong&gt;Greenfield&lt;/strong&gt;.&amp;nbsp;
For existing systems, the schema will the difference of what is currently in production
with what has been developed.&amp;nbsp; This is referred to as &lt;strong&gt;Brownfield&lt;/strong&gt; deployments.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;From a Visual Studio Database Project standpoint, Greenfield deployments
are a simple using the deploy option.&amp;nbsp; This will drop the database and execute
the full schema script to create the database.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_4.png" width="404" height="82"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;&lt;font size="1"&gt;Figure 9 – Greenfield Process&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;For Brownfield deployments in Visual Studio Database Projects, the
process is accomplished in two steps using Production and Development versions of
the database projects.&amp;nbsp; The first step is to use the Production version of the
Database Project to create the full CREATE script.&amp;nbsp; Next, use the compare feature
to compare the Production and Development versions to create the DELTA script.&amp;nbsp;
Again, the key is not to compare the development against the live production database
but to use the version of the Database Project that was created either from the production
database or from the Release branch in source control.&amp;nbsp; Once you have these two
database scripts, run the CREATE script to drop the database and create the database
to the production level.&amp;nbsp; Then execute DELTA script to bring it to the current
development level.&amp;nbsp; From there you can follow the similar steps to execute the
data generation plan and automated tests to complete.&amp;nbsp; See below to see how this
fits together &lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_5.png" width="404" height="212"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;&lt;font size="1"&gt;Figure 10 – Brownfield Process&lt;/font&gt;&lt;/strong&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;Putting this all together, here are the steps in order for a good SQL
Server database Continuous Delivery process.&amp;nbsp; There is some customization that
has to be done for this.&amp;nbsp; The database testing options that were available for
the simple process, won’t work out of the box for this solution.&amp;nbsp; This is because
the Database Project doesn’t know about the production and delta scripts.&amp;nbsp; The
build by default would create the database and run the data generation plan before
unit tests including the database unit tests.&amp;nbsp; However, the unit tests are run
immediately after the application is built and we need to specify the a step to build
create the scripts and then execute them.&amp;nbsp; I customized the build definition
by moving the unit test execution activities to later in the process so I could execute
the SQL scripts before the Unit Tests are run.&amp;nbsp; Once this was moved, I could
use the built in features to run the data generation plan.&amp;nbsp; Below are the steps
for the full end to end Database Continuous Delivery process.&lt;/font&gt;
&lt;/p&gt;
&lt;h3 align="left"&gt;&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_24.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_11.png" width="200" height="338"&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p align="center"&gt;
&lt;font size="1"&gt;&lt;strong&gt;Figure 11 – End to End Database Continuous Delivery Process&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;To combine this process into the application continuous delivery process,
the same tasks above can executed along with the application steps.&amp;nbsp; This process
is grouped into three groups: Build/Stage, Deploy, and Execute Automated Tests.&amp;nbsp;
The process is outlined below.&lt;/font&gt;
&lt;/p&gt;
&lt;h3 align="left"&gt;&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_26.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Continuous-Integration-CI-with-SQL-Serve_CEF7/image_thumb_12.png" width="500" height="312"&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 12 – End to End Application and Database Continuous Delivery Process&lt;/strong&gt;
&lt;/p&gt;
&lt;h3 align="left"&gt;&amp;nbsp;
&lt;/h3&gt;
&lt;h3 align="left"&gt;&amp;nbsp;
&lt;/h3&gt;
&lt;h3 align="left"&gt;VSDBCMD
&lt;/h3&gt;
&lt;p&gt;
&lt;font size="2"&gt;One of the great features of Visual Studio Database Projects is that
the deployment and compare functionality can be executed via a command line utility
called VSDBCMD.exe.&amp;nbsp; This allows us to perform the necessary steps in our Continuous
Delivery process.&amp;nbsp; I utilize a InvokeProcess Activity in the build definition
to call a PowerShell script to execute the VSDBCMD commands.&amp;nbsp; Below are examples
of how to create the Production CREATE script and the DELTA script.&amp;nbsp; The Production
Script creates the full CREATE script from the compiled Production version of the
Database Project.&amp;nbsp; The DELTA command shows how to compare two Database Projects
to generate the DELTA SQL Script.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Create Production Script&lt;/font&gt;&lt;/strong&gt; 
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&amp;amp; &lt;span class="str"&gt;"C:\program files (x86)\Microsoft
Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd.exe"&lt;/span&gt; &lt;/pre&gt;&lt;pre class="csharpcode"&gt;/a:deploy /dsp:sql /model:Ecommerce.dbschema /DeploymentScriptFile:c:\temp\OutputFilename2.sql &lt;/pre&gt;&lt;pre class="csharpcode"&gt;/p:TargetDatabase=&lt;span class="str"&gt;"NewEcommerce"&lt;/span&gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;font size="2"&gt;Create Production and Development Delta Script&lt;/font&gt;&lt;/strong&gt; 
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre class="csharpcode"&gt;&amp;amp; &lt;span class="str"&gt;"C:\program files (x86)\Microsoft
Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd.exe"&lt;/span&gt; &lt;/pre&gt;&lt;pre class="csharpcode"&gt;/a:deploy /dsp:sql /model:Ecommerce.dbschema /DeploymentScriptFile:c:\temp\OutputFilename2.sql &lt;/pre&gt;&lt;pre class="csharpcode"&gt;/targetmodelfile:&lt;span class="str"&gt;"C:\tfs\deliveron\Production\EcommerceSolution\Ecommerce\obj\Debug\ecommerce.dbschema"&lt;/span&gt; &lt;/pre&gt;&lt;pre class="csharpcode"&gt;/p:TargetDatabase=&lt;span class="str"&gt;"NewEcommerce"&lt;/span&gt;&lt;/pre&gt;&lt;/blockquote&gt; &lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;h3 align="left"&gt;&amp;nbsp;
&lt;/h3&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;h3 align="left"&gt;In Summary
&lt;/h3&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;This concludes the overview of the solution for Continuous Integration
and Delivery for SQL Server Databases.&amp;nbsp; I hope it gives you a complete overview
for creating your own Continuous Delivery process.&amp;nbsp; Feel free to contact me if
you have any questions or comments.&lt;/font&gt;
&lt;/p&gt;
&lt;p align="left"&gt;
&lt;font size="2"&gt;&lt;strong&gt;Review of Key Concepts&lt;/strong&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;There are three types of Continuous processes: Integration,
Delivery, and Deployment.&lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Continuous Delivery should be set up to be a practice
run for Production.&lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;Create compare scripts between development and production
database projects and don’t compare against live databases.&lt;/font&gt;
&lt;/div&gt;
&lt;li&gt;
&lt;div align="left"&gt;&lt;font size="2"&gt;VSDBCMD is a command line utility that perform the
deployment and compare functionality in Visual Studio Database Projects.&lt;/font&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
This was also cross posted at &lt;a title="http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx" href="http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx"&gt;http://www.deliveron.com/blog/post/Implementing-Continuous-Integration-(CI)-and-Delivery-for-SQL-Server-Databases.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=3448c757-600c-476a-9b69-2bf87b8d74aa" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,3448c757-600c-476a-9b69-2bf87b8d74aa.aspx</comments>
      <category>Agile</category>
      <category>ALM</category>
      <category>Continuous Integration</category>
      <category>SQL Server 2008</category>
      <category>Team Build 2010</category>
      <category>Team Foundation Server</category>
      <category>Visual Studio 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=2a458474-dca9-4320-9fdd-496354c898f1</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,2a458474-dca9-4320-9fdd-496354c898f1.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,2a458474-dca9-4320-9fdd-496354c898f1.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=2a458474-dca9-4320-9fdd-496354c898f1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Last week I had the opportunity to speak at Omaha’s first SQL Saturday.  My talk
was on Continuous Integration with SQL Server Databases.  I had a good turnout
and some great questions at my session.  Here are the <a href="http://www.sqlsaturday.com/viewsession.aspx?sat=91&amp;sessionid=5537" target="_blank">slides</a> from
my talk.  I mistakenly mentioned in the talk that column changes would be treated
as a Drop and an Add, thus resulting in data loss.  Visual Studio 2010 Database
Projects track the changes like this and incorporates the column change into the delta
script.  
</p>
        <p>
In my example, I have a Product table with existing data.  
</p>
        <p align="center">
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_2.png" width="239" height="131" />
          <strong>Figure
1 – Product table with data</strong>
        </p>
        <p>
I renamed the column from NameOfProduct to ProductName
</p>
        <p align="center">
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb.png" width="404" height="324" />
          <strong>Figure
2 – Rename feature in Database Projects</strong>
        </p>
        <p>
          <strong>
          </strong> 
</p>
        <p align="center">
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_3.png" width="404" height="231" />
          <strong>Figure
3 – Preview Changes Dialog</strong>
        </p>
        <p>
You can see that the delta script that was generated by the Deploy option in the Visual
Studio Database Project is aware of the column name change.  The script calls
the sp_rename stored procedure to rename the column name and keep the data intact.
</p>
        <p align="center">
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_4.png" width="654" height="188" />
          <strong>Figure
4 – Rename Column Script</strong>
        </p>
        <p>
 
</p>
        <p>
Here are the results of table after the rename. No data loss!
</p>
        <p align="center">
          <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_5.png" width="221" height="110" />
          <strong>Figure
5 – Product table data after the rename</strong>
        </p>
        <p>
In my next post I’ll discuss specifics around the CI for SQL Server databases solution.
</p>
        <p>
Enjoy!
</p>
        <p>
This was also cross posted to <a title="http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx" href="http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx">http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx</a></p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=2a458474-dca9-4320-9fdd-496354c898f1" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Column Changes without Data Loss in Visual Studio 2010 Database Projects</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,2a458474-dca9-4320-9fdd-496354c898f1.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/09/06/ColumnChangesWithoutDataLossInVisualStudio2010DatabaseProjects.aspx</link>
      <pubDate>Tue, 06 Sep 2011 08:08:00 GMT</pubDate>
      <description>&lt;p&gt;
Last week I had the opportunity to speak at Omaha’s first SQL Saturday.&amp;nbsp; My talk
was on Continuous Integration with SQL Server Databases.&amp;nbsp; I had a good turnout
and some great questions at my session.&amp;nbsp; Here are the &lt;a href="http://www.sqlsaturday.com/viewsession.aspx?sat=91&amp;amp;sessionid=5537" target="_blank"&gt;slides&lt;/a&gt; from
my talk.&amp;nbsp; I mistakenly mentioned in the talk that column changes would be treated
as a Drop and an Add, thus resulting in data loss.&amp;nbsp; Visual Studio 2010 Database
Projects track the changes like this and incorporates the column change into the delta
script.&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
In my example, I have a Product table with existing data.&amp;nbsp; 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_2.png" width="239" height="131"&gt;&lt;strong&gt;Figure
1 – Product table with data&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
I renamed the column from NameOfProduct to ProductName
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb.png" width="404" height="324"&gt;&lt;strong&gt;Figure
2 – Rename feature in Database Projects&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;&lt;/strong&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_3.png" width="404" height="231"&gt;&lt;strong&gt;Figure
3 – Preview Changes Dialog&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
You can see that the delta script that was generated by the Deploy option in the Visual
Studio Database Project is aware of the column name change.&amp;nbsp; The script calls
the sp_rename stored procedure to rename the column name and keep the data intact.
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_4.png" width="654" height="188"&gt;&lt;strong&gt;Figure
4 – Rename Column Script&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
Here are the results of table after the rename. No data loss!
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/53f0b7d82a03_4F0/image_thumb_5.png" width="221" height="110"&gt;&lt;strong&gt;Figure
5 – Product table data after the rename&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
In my next post I’ll discuss specifics around the CI for SQL Server databases solution.
&lt;/p&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;p&gt;
This was also cross posted to &lt;a title="http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx" href="http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx"&gt;http://www.deliveron.com/blog/post/Column-Changes-with-Visual-Studio-2010-Database-Projects.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=2a458474-dca9-4320-9fdd-496354c898f1" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,2a458474-dca9-4320-9fdd-496354c898f1.aspx</comments>
      <category>SQL Server 2008</category>
      <category>TFS 2010</category>
      <category>Visual Studio 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=45f2d145-fcee-46ef-820d-b637bf1d223a</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,45f2d145-fcee-46ef-820d-b637bf1d223a.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,45f2d145-fcee-46ef-820d-b637bf1d223a.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=45f2d145-fcee-46ef-820d-b637bf1d223a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you have ever tried scripting database schema and data from SQL Server, you have
probably been frustrated like me that there is not a simple process for doing this. 
SQL Server Management Studio includes two options highlighted below.  The <strong>Generate
Scripts…</strong> option works as expected and allows you to easily create a script
to recreate the database.  However, if you want to export the data to import
it at a later point, using the<strong> Export Data…</strong> option doesn’t quite
do what is needed to script the data.  It allows you to script to a CSV or Excel
file, however I have found importing an exported file, isn’t always easy.   
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb.png" width="354" height="387" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 1 - SQL Server Management Studio</strong>
        </p>
        <p>
Surprisingly there is a better option not in SQL Server Management Studio but in Visual
Studio 2010 (I believe this option is available in Visual Studio 2008, but I wasn’t
able to confirm this for the post.).  Visual Studio 2010 includes an view window
called Server Explorer.  This is typically used for data binding and tools like
LINQ and Entity Framework.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_1.png" width="384" height="157" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 2 – Visual Studio 2010 Server Explorer</strong>
        </p>
        <p>
The context menu for the particular data connection includes an option called <strong>Publish
to provider…</strong>  
</p>
        <p align="center">
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_6.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_2.png" width="354" height="339" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 3 – Publish to provider</strong>
        </p>
        <p>
This option launches the Database Publishing Wizard.  When this wizard displays
it gives you the option to export both schema and/or data to a SQL file.  Especially
for data, this is perfect for migrating data from one environment to the next including
preserving identity keys.
</p>
        <p>
The wizard opens with the option to choose a database and automatically script all
objects in the selected database.  I chose the AdventureWorks database and clicked
Next.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_8.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_3.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 4 – Select Database in the Database Publishing Wizard</strong>
        </p>
        <p>
The next step in the wizard is to choose what objects types to publish.  Here
I select Tables.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_10.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_4.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 5 – Choose Object Types in the Database Publishing Wizard</strong>
        </p>
        <p>
With the the Tables option selected in the previous step, the Choose Tables step appears. 
Here I selected a single table for this demo.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_12.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_5.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 6 – Choose Tables in the Database Publishing Wizard</strong>
        </p>
        <p>
Finally choose the output location.  This can either output to a file or to a
hosting provider.  Here I chose the <strong>Script to file</strong> option to
save the output to a file.  To use the <strong>Publish to shared hosting provider </strong>your
hosting provider or target system must support a SQL Publishing Web Service and the
database already exist on the target.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_14.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_6.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 7 – Select an Output Location in the Database Publishing Wizard</strong>
        </p>
        <p>
This screen includes the publishing options.  The options are straight forward. 
The<strong> Drop existing objects in script</strong> option will toggle a dropping
existing objects in the target database before the new objects are scripted. 
The<strong> Schema qualify</strong> option qualifies object names with the schema. 
The <strong>Script for target database</strong> drives the compatibility of the script. 
Finally the <strong>Types of data to publish</strong> allows for schema or data only
or both.  Here I want to script both so I chose <strong>Schema and data</strong>.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_17.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_7.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 8 – Select Publishing Options in the Database Publishing Wizard</strong>
        </p>
        <p>
The final screen is a confirmation of the options selected.  Click Finish to
run the wizard and create the script.  When the wizard completes, it will display
success.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_19.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_8.png" width="354" height="318" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 9 – Successful Database Publishing Wizard</strong>
        </p>
        <p>
Below is the output of the Database Publishing Wizard for the schema and data.
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML11af3a6.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SNAGHTML11af3a6" border="0" alt="SNAGHTML11af3a6" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML11af3a6_thumb.png" width="500" height="236" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 10 – Schema output of the Database Publishing Wizard</strong>
        </p>
        <p>
 
</p>
        <p>
          <a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML120ba20.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SNAGHTML120ba20" border="0" alt="SNAGHTML120ba20" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML120ba20_thumb.png" width="500" height="235" />
          </a>
        </p>
        <p align="center">
          <strong>Figure 11 – Data output of the Database Publishing Wizard</strong>
        </p>
        <p>
For more information on the Database Publishing Wizard, read <a href="http://msdn.microsoft.com/en-us/library/bb907585.aspx" target="_blank">Deploying
a Database by using the Database Publishing Wizard</a> on MSDN.
</p>
        <p>
This was also cross posted at <a title="http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx" href="http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx">http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx</a></p>
        <p>
Enjoy!
</p>
        <p>
Mike Douglas
</p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=45f2d145-fcee-46ef-820d-b637bf1d223a" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Script Database Schema and Data using Visual Studio 2010 and the Database Publishing Wizard</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,45f2d145-fcee-46ef-820d-b637bf1d223a.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/08/23/ScriptDatabaseSchemaAndDataUsingVisualStudio2010AndTheDatabasePublishingWizard.aspx</link>
      <pubDate>Tue, 23 Aug 2011 07:10:00 GMT</pubDate>
      <description>&lt;p&gt;
If you have ever tried scripting database schema and data from SQL Server, you have
probably been frustrated like me that there is not a simple process for doing this.&amp;nbsp;
SQL Server Management Studio includes two options highlighted below.&amp;nbsp; The &lt;strong&gt;Generate
Scripts…&lt;/strong&gt; option works as expected and allows you to easily create a script
to recreate the database.&amp;nbsp; However, if you want to export the data to import
it at a later point, using the&lt;strong&gt; Export Data…&lt;/strong&gt; option doesn’t quite
do what is needed to script the data.&amp;nbsp; It allows you to script to a CSV or Excel
file, however I have found importing an exported file, isn’t always easy.&amp;nbsp;&amp;nbsp; 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb.png" width="354" height="387"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 1 - SQL Server Management Studio&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Surprisingly there is a better option not in SQL Server Management Studio but in Visual
Studio 2010 (I believe this option is available in Visual Studio 2008, but I wasn’t
able to confirm this for the post.).&amp;nbsp; Visual Studio 2010 includes an view window
called Server Explorer.&amp;nbsp; This is typically used for data binding and tools like
LINQ and Entity Framework.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_1.png" width="384" height="157"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 2 – Visual Studio 2010 Server Explorer&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The context menu for the particular data connection includes an option called &lt;strong&gt;Publish
to provider…&lt;/strong&gt;&amp;nbsp; 
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_2.png" width="354" height="339"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 3 – Publish to provider&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
This option launches the Database Publishing Wizard.&amp;nbsp; When this wizard displays
it gives you the option to export both schema and/or data to a SQL file.&amp;nbsp; Especially
for data, this is perfect for migrating data from one environment to the next including
preserving identity keys.
&lt;/p&gt;
&lt;p&gt;
The wizard opens with the option to choose a database and automatically script all
objects in the selected database.&amp;nbsp; I chose the AdventureWorks database and clicked
Next.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_3.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 4 – Select Database in the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The next step in the wizard is to choose what objects types to publish.&amp;nbsp; Here
I select Tables.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_10.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_4.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 5 – Choose Object Types in the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
With the the Tables option selected in the previous step, the Choose Tables step appears.&amp;nbsp;
Here I selected a single table for this demo.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_12.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_5.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 6 – Choose Tables in the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Finally choose the output location.&amp;nbsp; This can either output to a file or to a
hosting provider.&amp;nbsp; Here I chose the &lt;strong&gt;Script to file&lt;/strong&gt; option to
save the output to a file.&amp;nbsp; To use the &lt;strong&gt;Publish to shared hosting provider &lt;/strong&gt;your
hosting provider or target system must support a SQL Publishing Web Service and the
database already exist on the target.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_14.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_6.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 7 – Select an Output Location in the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
This screen includes the publishing options.&amp;nbsp; The options are straight forward.&amp;nbsp;
The&lt;strong&gt; Drop existing objects in script&lt;/strong&gt; option will toggle a dropping
existing objects in the target database before the new objects are scripted.&amp;nbsp;
The&lt;strong&gt; Schema qualify&lt;/strong&gt; option qualifies object names with the schema.&amp;nbsp;
The &lt;strong&gt;Script for target database&lt;/strong&gt; drives the compatibility of the script.&amp;nbsp;
Finally the &lt;strong&gt;Types of data to publish&lt;/strong&gt; allows for schema or data only
or both.&amp;nbsp; Here I want to script both so I chose &lt;strong&gt;Schema and data&lt;/strong&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_17.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_7.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 8 – Select Publishing Options in the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
The final screen is a confirmation of the options selected.&amp;nbsp; Click Finish to
run the wizard and create the script.&amp;nbsp; When the wizard completes, it will display
success.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_19.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="image" border="0" alt="image" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/image_thumb_8.png" width="354" height="318"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 9 – Successful Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
Below is the output of the Database Publishing Wizard for the schema and data.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML11af3a6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SNAGHTML11af3a6" border="0" alt="SNAGHTML11af3a6" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML11af3a6_thumb.png" width="500" height="236"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 10 – Schema output of the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML120ba20.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="SNAGHTML120ba20" border="0" alt="SNAGHTML120ba20" src="http://www.codesmartnothard.com/content/binary/Windows-Live-Writer/Script_1378C/SNAGHTML120ba20_thumb.png" width="500" height="235"&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p align="center"&gt;
&lt;strong&gt;Figure 11 – Data output of the Database Publishing Wizard&lt;/strong&gt;
&lt;/p&gt;
&lt;p&gt;
For more information on the Database Publishing Wizard, read &lt;a href="http://msdn.microsoft.com/en-us/library/bb907585.aspx" target="_blank"&gt;Deploying
a Database by using the Database Publishing Wizard&lt;/a&gt; on MSDN.
&lt;/p&gt;
&lt;p&gt;
This was also cross posted at &lt;a title="http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx" href="http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx"&gt;http://www.deliveron.com/blog/post/Script-Database-Schema-and-data-using-Visual-Studio-2010-and-Database-Publishing-Wizard.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;p&gt;
Mike Douglas
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=45f2d145-fcee-46ef-820d-b637bf1d223a" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,45f2d145-fcee-46ef-820d-b637bf1d223a.aspx</comments>
      <category>ALM</category>
      <category>SQL Server 2008</category>
      <category>Visual Studio 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=dcceb3cf-e4f2-444a-ab5d-6a82844feb7d</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,dcceb3cf-e4f2-444a-ab5d-6a82844feb7d.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,dcceb3cf-e4f2-444a-ab5d-6a82844feb7d.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=dcceb3cf-e4f2-444a-ab5d-6a82844feb7d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Team Project portal site in TFS 2010 is the collaboration hub for many activities
that typically includes document libraries, team calendar,  wiki, reporting,
and more.  TFS 2010 includes a number of reports that can be displayed on the
portal using SSRS (using either SharePoint 2010 Foundation or SharePoint 2010 Enterprise)
and Excel Services (using SharePoint 2010 Enterprise).    In this post,
I will walk through customizing the report to display the burndown for the particular
Iteration..
</p>
        <p>
The first question I often receive is:
</p>
        <p>
          <em>How do I customize the burndown dashboard report to fit my Sprint/Iteration?</em>
        </p>
        <p>
When you display the project portal page and view the burndown dashboard report, you
will notice that the default parameters don’t match the current iteration.  To
update this, we can override the parameters being passed into the report through the
URL.  I want to set Start Date, End Date, and Iteration parameters to display
the correct data.
</p>
        <p>
First, navigate to the page with the report
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_2.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb.png" width="644" height="248" />
          </a>
        </p>
        <p>
Click on the arrow and choose “Edit Web Part” to edit the parameters for the report.
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_4.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_1.png" width="204" height="171" />
          </a>
        </p>
        <p>
On the right of the screen is the settings for the web part and report. The link is
what needs to be modified.
</p>
        <p>
          <a href="http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2fBurndown&amp;rs:Command=Render&amp;rc:Toolbar=false&amp;StartDateParam=07/05/2011&amp;EndDateParam=07/26/2011">http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2f 
<br />
Burndown&amp;rs:Command=Render&amp;rc:Toolbar=false&amp;StartDateParam=07/05/2011&amp;EndDateParam=07/26/2011</a>
        </p>
        <p>
To Determine the properties to add or change, you can go to the report itself and
look at the properties available. In this example, we want to update the Start Date
and End Date and add the Iteration. To find out what the name of the Iteration parameter
is, go to the following URL to see the properties.
</p>
        <p>
          <a href="http://tfsserver/Reports/Pages/Folder.aspx?ItemPath=%2fTfsReports%2fBP%2fTeamProject%2fDashboards&amp;ViewMode=List">http://tfsserver/Reports/Pages/Folder.aspx?ItemPath=%2fTfsReports%2fBP%2fTeamProject%2fDashboards&amp;ViewMode=List</a>
        </p>
        <p>
Choose the Manage option in the context menu of the report
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_6.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_2.png" width="354" height="326" />
          </a>
        </p>
        <p>
In the settings screen, choose the Parameters tab and find the parameter you are looking
for. This is the name we will add to the URL above. In this instance, it is IterationParam
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_8.png">
            <img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_3.png" width="604" height="459" />
          </a>
        </p>
        <p>
The format of the IterationParam parameter wasn’t intuitive.  The item is a multi-select
checkbox list.  So it wouldn’t take a simple text value such as “Iteration 01”.
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/SNAGHTML561b382.png">
            <img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML561b382" border="0" alt="SNAGHTML561b382" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/SNAGHTML561b382_thumb.png" width="244" height="163" />
          </a>
        </p>
        <p>
To figure out the format of value, I used the report viewer to set the value of the
Iteration and exported the report as an Atom feed.  Then I opened the Atom XML
and to pull out the value of the Iteration Param that it created.  Below is what
the link looks like with the IterationParam value added.
</p>
        <p>
          <a href="http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2fBurndown&amp;rs:Command=Render&amp;rc:Toolbar=false&amp;IterationParam=%5BWork%20Item%5D.%5BIteration%20Hierarchy%5D.%5BIteration1%5D.%26%5B7130920747760410946%5D%26%5B-4689172157298829814%5D&amp;StartDateParam=07/06/2011&amp;EndDateParam=07/26/2011">http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards 
<br />
%2fBurndown&amp;rs:Command=Render&amp;rc:Toolbar=false&amp;IterationParam=%5BWork%20Item%5D.%5B 
<br />
Iteration%20Hierarchy%5D.%5BIteration1%5D.%26%5B7130920747760410946%5D%26%5B-4689172157298829814%5D&amp; 
<br />
StartDateParam=07/06/2011&amp;EndDateParam=07/26/2011</a>
        </p>
        <p>
Finally paste this URL into the link in the web part and save. This is ready to display.
</p>
        <p>
Mike Douglas
</p>
        <p>
This post was cross posted to <a title="http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx" href="http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx">http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx</a></p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=dcceb3cf-e4f2-444a-ab5d-6a82844feb7d" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Customizing the Burndown Dashboard Report in The TFS 2010 Team Portal</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,dcceb3cf-e4f2-444a-ab5d-6a82844feb7d.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/08/03/CustomizingTheBurndownDashboardReportInTheTFS2010TeamPortal.aspx</link>
      <pubDate>Wed, 03 Aug 2011 04:00:00 GMT</pubDate>
      <description>&lt;p&gt;
The Team Project portal site in TFS 2010 is the collaboration hub for many activities
that typically includes document libraries, team calendar,&amp;#160; wiki, reporting,
and more.&amp;#160; TFS 2010 includes a number of reports that can be displayed on the
portal using SSRS (using either SharePoint 2010 Foundation or SharePoint 2010 Enterprise)
and Excel Services (using SharePoint 2010 Enterprise).&amp;#160;&amp;#160;&amp;#160; In this post,
I will walk through customizing the report to display the burndown for the particular
Iteration..
&lt;/p&gt;
&lt;p&gt;
The first question I often receive is:
&lt;/p&gt;
&lt;p&gt;
&lt;em&gt;How do I customize the burndown dashboard report to fit my Sprint/Iteration?&lt;/em&gt;
&lt;/p&gt;
&lt;p&gt;
When you display the project portal page and view the burndown dashboard report, you
will notice that the default parameters don’t match the current iteration.&amp;#160; To
update this, we can override the parameters being passed into the report through the
URL.&amp;#160; I want to set Start Date, End Date, and Iteration parameters to display
the correct data.
&lt;/p&gt;
&lt;p&gt;
First, navigate to the page with the report
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_2.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb.png" width="644" height="248" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Click on the arrow and choose “Edit Web Part” to edit the parameters for the report.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_4.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_1.png" width="204" height="171" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
On the right of the screen is the settings for the web part and report. The link is
what needs to be modified.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2fBurndown&amp;amp;rs:Command=Render&amp;amp;rc:Toolbar=false&amp;amp;StartDateParam=07/05/2011&amp;amp;EndDateParam=07/26/2011"&gt;http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2f 
&lt;br /&gt;
Burndown&amp;amp;rs:Command=Render&amp;amp;rc:Toolbar=false&amp;amp;StartDateParam=07/05/2011&amp;amp;EndDateParam=07/26/2011&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
To Determine the properties to add or change, you can go to the report itself and
look at the properties available. In this example, we want to update the Start Date
and End Date and add the Iteration. To find out what the name of the Iteration parameter
is, go to the following URL to see the properties.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://tfsserver/Reports/Pages/Folder.aspx?ItemPath=%2fTfsReports%2fBP%2fTeamProject%2fDashboards&amp;amp;ViewMode=List"&gt;http://tfsserver/Reports/Pages/Folder.aspx?ItemPath=%2fTfsReports%2fBP%2fTeamProject%2fDashboards&amp;amp;ViewMode=List&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Choose the Manage option in the context menu of the report
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_6.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_2.png" width="354" height="326" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In the settings screen, choose the Parameters tab and find the parameter you are looking
for. This is the name we will add to the URL above. In this instance, it is IterationParam
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_8.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/image_thumb_3.png" width="604" height="459" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
The format of the IterationParam parameter wasn’t intuitive.&amp;#160; The item is a multi-select
checkbox list.&amp;#160; So it wouldn’t take a simple text value such as “Iteration 01”.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/SNAGHTML561b382.png"&gt;&lt;img style="background-image: none; border-right-width: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="SNAGHTML561b382" border="0" alt="SNAGHTML561b382" src="http://codesmartnothard.com/content/binary/Windows-Live-Writer/Customizing-the-Burndown-Dashboard-Repor_12DEF/SNAGHTML561b382_thumb.png" width="244" height="163" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
To figure out the format of value, I used the report viewer to set the value of the
Iteration and exported the report as an Atom feed.&amp;#160; Then I opened the Atom XML
and to pull out the value of the Iteration Param that it created.&amp;#160; Below is what
the link looks like with the IterationParam value added.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards%2fBurndown&amp;amp;rs:Command=Render&amp;amp;rc:Toolbar=false&amp;amp;IterationParam=%5BWork%20Item%5D.%5BIteration%20Hierarchy%5D.%5BIteration1%5D.%26%5B7130920747760410946%5D%26%5B-4689172157298829814%5D&amp;amp;StartDateParam=07/06/2011&amp;amp;EndDateParam=07/26/2011"&gt;http://tfsserver/ReportServer/Pages/ReportViewer.aspx?%2fTfsReports%2fBP%2fTeamProject%2fDashboards 
&lt;br /&gt;
%2fBurndown&amp;amp;rs:Command=Render&amp;amp;rc:Toolbar=false&amp;amp;IterationParam=%5BWork%20Item%5D.%5B 
&lt;br /&gt;
Iteration%20Hierarchy%5D.%5BIteration1%5D.%26%5B7130920747760410946%5D%26%5B-4689172157298829814%5D&amp;amp; 
&lt;br /&gt;
StartDateParam=07/06/2011&amp;amp;EndDateParam=07/26/2011&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Finally paste this URL into the link in the web part and save. This is ready to display.
&lt;/p&gt;
&lt;p&gt;
Mike Douglas
&lt;/p&gt;
&lt;p&gt;
This post was cross posted to &lt;a title="http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx" href="http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx"&gt;http://www.deliveron.com/blog/post/Customizing-the-Burndown-Dashboard-Report-in-TFS-2010-Team-Portal.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=dcceb3cf-e4f2-444a-ab5d-6a82844feb7d" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,dcceb3cf-e4f2-444a-ab5d-6a82844feb7d.aspx</comments>
      <category>SharePoint</category>
      <category>SQL Server 2008</category>
      <category>TFS 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=54e71262-61cd-41b0-b570-ff820e5a6e85</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,54e71262-61cd-41b0-b570-ff820e5a6e85.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,54e71262-61cd-41b0-b570-ff820e5a6e85.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=54e71262-61cd-41b0-b570-ff820e5a6e85</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">PowerShell is an awesome technology.  It has become an essential
tool for doing automated deployments with Team Foundation Server 2010.  Creating
deployment scripts in PowerShell are very easy to manage and maintain by the entire
development without having to know about the details of the build definitions. 
In future posts, I will explain how I use the build definitions and PowerShell to
perform the deployments.  With this post I wanted to share a small tip on being
able to catch all errors with a Try, Catch.</font>
        </p>
        <p>
          <font size="2">In PowerShell, there are two types of errors. Terminating errors and
non-terminating errors.  Terminating errors will automatically be caught in a
Try, Catch block but non-terminating errors will not.  Look at this example below.</font>
        </p>
        <blockquote>
          <p>
            <font size="1">try 
<br />
{ 
<br />
    copy-item "c:\notexists\file.txt" "c:\temp" 
<br />
} 
<br />
catch {</font>
          </p>
          <p>
            <font size="1">write-host "bad copy"</font>
          </p>
          <p>
            <font size="1">}</font>
          </p>
        </blockquote>
        <p>
          <font size="2">This command looks like it should write to the out the error message
because the folder and file do not exists. However when you run this, it will only
display the PowerShell error message.  </font>
        </p>
        <blockquote>
          <p>
            <font color="#ff0000" size="1">Copy-Item : Cannot find path 'C:\notexists\file.txt'
because it does not exist. 
<br />
At C:\temp\copyitem.ps1:3 char:14 
<br />
+     copy-item &lt;&lt;&lt;&lt;  "c:\notexists\file.txt"
"c:\temp" 
<br />
    + CategoryInfo         
: ObjectNotFound: (C:\notexists\file.txt:String) [Copy-Item], ItemNotFoundException 
<br />
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand</font>
          </p>
        </blockquote>
        <p>
          <font size="2">This is an example of a non-terminating error.  There are two
ways to fix this.  The –ErrorAction ”Stop” flag can be added to many of cmdlets.  </font>
        </p>
        <blockquote>
          <p>
            <font size="1">copy-item "c:\notexists\file.txt" "c:\temp" -ErrorAction
"Stop"</font>
          </p>
        </blockquote>
        <p>
          <font size="2">Now, when the script is run, it will display the error message, “bad
copy”.</font>
        </p>
        <p>
          <font size="2">This is great but if you are like me, you don’t want to have to add
this to every command.   Luckily there is a way to do this for the entire
script.  At the beginning of the script, you can set $ErrorActionPreference =
“Stop”.  If you want to be able to toggle it, it default setting is “Continue”.</font>
        </p>
        <blockquote>
          <p>
            <font size="1">$ErrorActionPreference = "Stop"</font>
          </p>
        </blockquote>
        <p>
          <font size="2">Here is the final script.  Enjoy!</font>
        </p>
        <blockquote>
          <p>
            <font size="1">$ErrorActionPreference = "Stop"</font>
          </p>
          <p>
            <font size="1">try 
<br />
{ 
<br />
    copy-item "c:\notexists\file.txt" "c:\temp" 
<br />
} 
<br />
catch {</font>
          </p>
          <p>
            <font size="1">write-host "bad copy"</font>
          </p>
          <p>
            <font size="1">}</font>
          </p>
        </blockquote>
        <p>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2">
          </font>
        </p>
        <p>
          <font size="2"> </font>
        </p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=54e71262-61cd-41b0-b570-ff820e5a6e85" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Hey PowerShell, Why is my Try, Catch not working?</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,54e71262-61cd-41b0-b570-ff820e5a6e85.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/07/03/HeyPowerShellWhyIsMyTryCatchNotWorking.aspx</link>
      <pubDate>Sun, 03 Jul 2011 03:14:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;PowerShell is an awesome technology.&amp;#160; It has become an essential
tool for doing automated deployments with Team Foundation Server 2010.&amp;#160; Creating
deployment scripts in PowerShell are very easy to manage and maintain by the entire
development without having to know about the details of the build definitions.&amp;#160;
In future posts, I will explain how I use the build definitions and PowerShell to
perform the deployments.&amp;#160; With this post I wanted to share a small tip on being
able to catch all errors with a Try, Catch.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;In PowerShell, there are two types of errors. Terminating errors and
non-terminating errors.&amp;#160; Terminating errors will automatically be caught in a
Try, Catch block but non-terminating errors will not.&amp;#160; Look at this example below.&lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font size="1"&gt;try 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; copy-item &amp;quot;c:\notexists\file.txt&amp;quot; &amp;quot;c:\temp&amp;quot; 
&lt;br /&gt;
} 
&lt;br /&gt;
catch {&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;write-host &amp;quot;bad copy&amp;quot;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;font size="2"&gt;This command looks like it should write to the out the error message
because the folder and file do not exists. However when you run this, it will only
display the PowerShell error message.&amp;#160; &lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font color="#ff0000" size="1"&gt;Copy-Item : Cannot find path 'C:\notexists\file.txt'
because it does not exist. 
&lt;br /&gt;
At C:\temp\copyitem.ps1:3 char:14 
&lt;br /&gt;
+&amp;#160;&amp;#160;&amp;#160;&amp;#160; copy-item &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;#160; &amp;quot;c:\notexists\file.txt&amp;quot;
&amp;quot;c:\temp&amp;quot; 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; + CategoryInfo&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;
: ObjectNotFound: (C:\notexists\file.txt:String) [Copy-Item], ItemNotFoundException 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.CopyItemCommand&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;font size="2"&gt;This is an example of a non-terminating error.&amp;#160; There are two
ways to fix this.&amp;#160; The –ErrorAction ”Stop” flag can be added to many of cmdlets.&amp;#160; &lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font size="1"&gt;copy-item &amp;quot;c:\notexists\file.txt&amp;quot; &amp;quot;c:\temp&amp;quot; -ErrorAction
&amp;quot;Stop&amp;quot;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;font size="2"&gt;Now, when the script is run, it will display the error message, “bad
copy”.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;This is great but if you are like me, you don’t want to have to add
this to every command.&amp;#160;&amp;#160; Luckily there is a way to do this for the entire
script.&amp;#160; At the beginning of the script, you can set $ErrorActionPreference =
“Stop”.&amp;#160; If you want to be able to toggle it, it default setting is “Continue”.&lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font size="1"&gt;$ErrorActionPreference = &amp;quot;Stop&amp;quot;&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;font size="2"&gt;Here is the final script.&amp;#160; Enjoy!&lt;/font&gt;
&lt;/p&gt;
&lt;blockquote&gt; 
&lt;p&gt;
&lt;font size="1"&gt;$ErrorActionPreference = &amp;quot;Stop&amp;quot;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;try 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160; copy-item &amp;quot;c:\notexists\file.txt&amp;quot; &amp;quot;c:\temp&amp;quot; 
&lt;br /&gt;
} 
&lt;br /&gt;
catch {&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;write-host &amp;quot;bad copy&amp;quot;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="1"&gt;}&lt;/font&gt;
&lt;/p&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;&amp;#160;&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=54e71262-61cd-41b0-b570-ff820e5a6e85" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,54e71262-61cd-41b0-b570-ff820e5a6e85.aspx</comments>
      <category>PowerShell</category>
      <category>Team Build 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=835b4a5d-31ea-49c6-80b6-938c9bbe5e55</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,835b4a5d-31ea-49c6-80b6-938c9bbe5e55.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,835b4a5d-31ea-49c6-80b6-938c9bbe5e55.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=835b4a5d-31ea-49c6-80b6-938c9bbe5e55</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font size="2">The Visual Studio ALM Rangers just released two projects, the </font>
          <a href="http://rabcg.codeplex.com" target="_blank">
            <font size="2">Build
Customization Guide</font>
          </a>
          <font size="2"> and the </font>
          <a href="http://ralabman.codeplex.com/" target="_blank">
            <font size="2">Lab
Management Guide</font>
          </a>
          <font size="2">.  Both projects provide real world,
in-depth guidance and hands-on-labs (HOL) for planning and creating solutions for
utilizing the Team Build 2010 and Visual Studio 2010 Lab Management.  Every development
team should utilize the features covered in these guides for creating a build strategy
that includes Continuous Integration (CI), packaging and versioning of applications,
and automated deployments to at least the development and test environments. By utilizing
Visual Studio Lab Management, these environments can be quickly provisioned and managed
by those development teams.  They will be able to do things restore to a baseline
before building, deploying, and running tests in those environments, clone the environment
to provide multiple test environments for QA, and attaching a snapshot of the virtual
environment along with other rich information to bugs for the developers. </font>
        </p>
        <p>
          <font size="2">Visit the websites for all of the details and downloads for the guidance.</font>
        </p>
        <h3>Build Customization Guide
</h3>
        <p>
          <font size="2">I am especially excited about the Build Customization Guide being released
because this was first Visual Studio Ranger project I have had worked on.  I
had the opportunity to work with many talented and dedicated individuals.</font>
        </p>
        <p>
          <font size="2">The Epics included in this guidance are:</font>
        </p>
        <ul>
          <li>
            <font size="2">Practical guidance and tooling to simplify the customization of Team
Foundation Build</font>
          </li>
          <li>
            <font size="2">Practical guidance to use Team Foundation Build process templates to
automate build and non-build scenarios in Microsoft environments</font>
          </li>
          <li>
            <font size="2">Practical guidance to enable simple and flexible deployment of applications
and their data stores </font>
          </li>
          <li>
            <font size="2">Practical guidance for Activities to empower developers and build engineers </font>
          </li>
          <li>
            <font size="2">Quality hands-on labs that complement the guidance and effectively
guide the user through the features </font>
          </li>
          <li>
            <font size="2">Visualization of the guidance using quick reference posters </font>
          </li>
        </ul>
        <p>
          <a title="http://rabcg.codeplex.com/" href="http://rabcg.codeplex.com/">
            <font size="2">http://rabcg.codeplex.com/</font>
          </a>
        </p>
        <h3>Lab Management Guide
</h3>
        <p>
          <font size="2">I didn’t contribute to the Lab Management Guide, but I have read through
the guidance.  It includes a lot of great information that include planning Lab
Management, setting up the Virtual Lab environment, and creating Virtual Machines
using the VM Factory. </font>
        </p>
        <p>
          <font size="2">The Epics included in this guidance are:</font>
        </p>
        <ul>
          <li>
            <font size="2">Visualization of the guidance using quick reference posters </font>
          </li>
          <li>
            <font size="2">Advanced golden image management using the VM Factory for Lab Management </font>
          </li>
          <li>
            <font size="2">Provide guidance on setting up Test environments with respect to pre-defined
personas </font>
          </li>
          <li>
            <font size="2">Provide Guidance to enable large and small teams to setup and configure
both automated and manual tests </font>
          </li>
          <li>
            <font size="2">Provide practical guidance for managing and maintaining a Lab Management
environment </font>
          </li>
          <li>
            <font size="2">Provide practical guidance to enable teams to quickly setup and configure
their lab management environment </font>
          </li>
        </ul>
        <p>
          <a title="http://ralabman.codeplex.com/" href="http://ralabman.codeplex.com/">
            <font size="2">http://ralabman.codeplex.com/</font>
          </a>
        </p>
        <h3>Visual Studio ALM Rangers
</h3>
        <p>
          <font size="2">So who are the the Visual Studio ALM Rangers?  They are a group
of internal Microsoft employees and external communities leaders/MVPs who’s mission
is to accelerate the adoption of Visual Studio with out-of-band solutions for missing
features and guidance.  Willy-P. Schaub has posted some great information about
who we are, the past accomplishments, and future plan in the </font>
          <a href="http://blogs.msdn.com/b/willy-peter_schaub/archive/2011/06/09/visual-studio-alm-rangers-5-year-report-sharing-the-essentials.aspx" target="_blank">
            <font size="2">Visual
Studio ALM Rangers 5 year Report</font>
          </a>
          <font size="2">.</font>
        </p>
        <p>
          <font size="2">Please contact us at </font>
          <a href="mailto:tfs@deliveron.com">
            <font size="2">tfs@deliveron.com</font>
          </a>
          <font size="2"> for
information on these guides or implementing these solutions in your environment.</font>
        </p>
        <p>
          <font size="2">Mike</font>
        </p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=835b4a5d-31ea-49c6-80b6-938c9bbe5e55" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Visual Studio ALM Rangers release the Build Customization and Lab Management Guides</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,835b4a5d-31ea-49c6-80b6-938c9bbe5e55.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/06/18/VisualStudioALMRangersReleaseTheBuildCustomizationAndLabManagementGuides.aspx</link>
      <pubDate>Sat, 18 Jun 2011 17:52:00 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font size="2"&gt;The Visual Studio ALM Rangers just released two projects, the &lt;/font&gt;&lt;a href="http://rabcg.codeplex.com" target="_blank"&gt;&lt;font size="2"&gt;Build
Customization Guide&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; and the &lt;/font&gt;&lt;a href="http://ralabman.codeplex.com/" target="_blank"&gt;&lt;font size="2"&gt;Lab
Management Guide&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&amp;#160; Both projects provide real world,
in-depth guidance and hands-on-labs (HOL) for planning and creating solutions for
utilizing the Team Build 2010 and Visual Studio 2010 Lab Management.&amp;#160; Every development
team should utilize the features covered in these guides for creating a build strategy
that includes Continuous Integration (CI), packaging and versioning of applications,
and automated deployments to at least the development and test environments. By utilizing
Visual Studio Lab Management, these environments can be quickly provisioned and managed
by those development teams.&amp;#160; They will be able to do things restore to a baseline
before building, deploying, and running tests in those environments, clone the environment
to provide multiple test environments for QA, and attaching a snapshot of the virtual
environment along with other rich information to bugs for the developers. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;Visit the websites for all of the details and downloads for the guidance.&lt;/font&gt;
&lt;/p&gt;
&lt;h3&gt;Build Customization Guide
&lt;/h3&gt;
&lt;p&gt;
&lt;font size="2"&gt;I am especially excited about the Build Customization Guide being released
because this was first Visual Studio Ranger project I have had worked on.&amp;#160; I
had the opportunity to work with many talented and dedicated individuals.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;The Epics included in this guidance are:&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;font size="2"&gt;Practical guidance and tooling to simplify the customization of Team
Foundation Build&lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Practical guidance to use Team Foundation Build process templates to
automate build and non-build scenarios in Microsoft environments&lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Practical guidance to enable simple and flexible deployment of applications
and their data stores &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Practical guidance for Activities to empower developers and build engineers &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Quality hands-on labs that complement the guidance and effectively
guide the user through the features &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Visualization of the guidance using quick reference posters &lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a title="http://rabcg.codeplex.com/" href="http://rabcg.codeplex.com/"&gt;&lt;font size="2"&gt;http://rabcg.codeplex.com/&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Lab Management Guide
&lt;/h3&gt;
&lt;p&gt;
&lt;font size="2"&gt;I didn’t contribute to the Lab Management Guide, but I have read through
the guidance.&amp;#160; It includes a lot of great information that include planning Lab
Management, setting up the Virtual Lab environment, and creating Virtual Machines
using the VM Factory. &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;The Epics included in this guidance are:&lt;/font&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;font size="2"&gt;Visualization of the guidance using quick reference posters &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Advanced golden image management using the VM Factory for Lab Management &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Provide guidance on setting up Test environments with respect to pre-defined
personas &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Provide Guidance to enable large and small teams to setup and configure
both automated and manual tests &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Provide practical guidance for managing and maintaining a Lab Management
environment &lt;/font&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;font size="2"&gt;Provide practical guidance to enable teams to quickly setup and configure
their lab management environment &lt;/font&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
&lt;a title="http://ralabman.codeplex.com/" href="http://ralabman.codeplex.com/"&gt;&lt;font size="2"&gt;http://ralabman.codeplex.com/&lt;/font&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;h3&gt;Visual Studio ALM Rangers
&lt;/h3&gt;
&lt;p&gt;
&lt;font size="2"&gt;So who are the the Visual Studio ALM Rangers?&amp;#160; They are a group
of internal Microsoft employees and external communities leaders/MVPs who’s mission
is to accelerate the adoption of Visual Studio with out-of-band solutions for missing
features and guidance.&amp;#160; Willy-P. Schaub has posted some great information about
who we are, the past accomplishments, and future plan in the &lt;/font&gt;&lt;a href="http://blogs.msdn.com/b/willy-peter_schaub/archive/2011/06/09/visual-studio-alm-rangers-5-year-report-sharing-the-essentials.aspx" target="_blank"&gt;&lt;font size="2"&gt;Visual
Studio ALM Rangers 5 year Report&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt;.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;Please contact us at &lt;/font&gt;&lt;a href="mailto:tfs@deliveron.com"&gt;&lt;font size="2"&gt;tfs@deliveron.com&lt;/font&gt;&lt;/a&gt;&lt;font size="2"&gt; for
information on these guides or implementing these solutions in your environment.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font size="2"&gt;Mike&lt;/font&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=835b4a5d-31ea-49c6-80b6-938c9bbe5e55" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,835b4a5d-31ea-49c6-80b6-938c9bbe5e55.aspx</comments>
      <category>ALM</category>
      <category>Lab Management</category>
      <category>Team Build 2010</category>
      <category>Team Foundation Server</category>
      <category>TFS 2010</category>
      <category>Visual Studio 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=746a9a62-2127-4b04-b52b-af9cf58c14df</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,746a9a62-2127-4b04-b52b-af9cf58c14df.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,746a9a62-2127-4b04-b52b-af9cf58c14df.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=746a9a62-2127-4b04-b52b-af9cf58c14df</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The Nebraska Code Camp is a free, community-driven conference.  Attend the Nebraska
Code Camp on April 9th, 2011 in Lincoln, NE.  Includes 25 sessions from local
and regional speakers on topics including Windows Phone 7, BDD, ALM, WCF, MEF, JQuery,
and Cloud Computing.  I am fortunate enough to giving two talks on Visual Studio
2010 ALM including <a href="http://www.nebraskacodecamp.com/Sessions/Details/5" target="_blank">Getting
Agile with Visual Studio 2010</a> and <a href="http://www.nebraskacodecamp.com/Sessions/Details/6" target="_blank">Coded
UI Tests Deep Dive</a>.
</p>
        <p>
Take a look at all of the <a href="http://www.nebraskacodecamp.com/Sessions" target="_blank">Sessions</a> and <a href="http://www.nebraskacodecamp.com/Speakers" target="_blank">Speakers</a> at
this great event.
</p>
        <p>
          <a href="http://www.nebraskacodecamp.com/Register" target="_blank">Register</a> today. 
Did I mention it is FREE??!!!  I hope to see you all there.
</p>
        <p>
          <a href="http://twitter.com/NebraskaCC" target="_blank">Follow Nebraska Code Camp</a> on
Twitter
</p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=746a9a62-2127-4b04-b52b-af9cf58c14df" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Attend Nebraska Code Camp on April 9th, 2011</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,746a9a62-2127-4b04-b52b-af9cf58c14df.aspx</guid>
      <link>http://www.codesmartnothard.com/2011/03/29/AttendNebraskaCodeCampOnApril9th2011.aspx</link>
      <pubDate>Tue, 29 Mar 2011 06:22:00 GMT</pubDate>
      <description>&lt;p&gt;
The Nebraska Code Camp is a free, community-driven conference.&amp;#160; Attend the Nebraska
Code Camp on April 9th, 2011 in Lincoln, NE.&amp;#160; Includes 25 sessions from local
and regional speakers on topics including Windows Phone 7, BDD, ALM, WCF, MEF, JQuery,
and Cloud Computing.&amp;#160; I am fortunate enough to giving two talks on Visual Studio
2010 ALM including &lt;a href="http://www.nebraskacodecamp.com/Sessions/Details/5" target="_blank"&gt;Getting
Agile with Visual Studio 2010&lt;/a&gt; and &lt;a href="http://www.nebraskacodecamp.com/Sessions/Details/6" target="_blank"&gt;Coded
UI Tests Deep Dive&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Take a look at all of the &lt;a href="http://www.nebraskacodecamp.com/Sessions" target="_blank"&gt;Sessions&lt;/a&gt; and &lt;a href="http://www.nebraskacodecamp.com/Speakers" target="_blank"&gt;Speakers&lt;/a&gt; at
this great event.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.nebraskacodecamp.com/Register" target="_blank"&gt;Register&lt;/a&gt; today.&amp;#160;
Did I mention it is FREE??!!!&amp;#160; I hope to see you all there.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://twitter.com/NebraskaCC" target="_blank"&gt;Follow Nebraska Code Camp&lt;/a&gt; on
Twitter
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=746a9a62-2127-4b04-b52b-af9cf58c14df" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,746a9a62-2127-4b04-b52b-af9cf58c14df.aspx</comments>
      <category>ALM</category>
      <category>Nebraska Code Camp</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=510464a0-fdd7-4635-8fe8-786bf726a84c</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,510464a0-fdd7-4635-8fe8-786bf726a84c.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,510464a0-fdd7-4635-8fe8-786bf726a84c.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=510464a0-fdd7-4635-8fe8-786bf726a84c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Team Deploy 2010 is a custom add-on for Team Foundation Server 2010 (TFS) to deploy
MSIs to servers and PCs.  The deploy activity uses an XML file to manage the
servers and steps for deployment including starting/stopping services and installing/uninstalling
the MSIs.  This is very effective for automated deployments in environments where
automated deployments are allowed.  This however does not provide a practice
run into downstream environments where automated deployments are not allowed such
as Staging/Integration and Production.
</p>
        <p>
An alternative to this that does offer some deployment consistencies beyond the MSI
is to have Team Deploy 2010 (or Team Deploy for TFS 2008 also supports this) execute
a PowerShell script to perform the deployment steps.  The advantage of this is
that the PowerShell scripts can also be used to perform the manual deployments to
these other environments.  This won’t work in every scenario but should in a
lot.  In this post, I am going to explain how to do this.
</p>
        <p>
The first thing to do is to install Team Deploy 2010.  This is free and can be
downloaded at <a href="http://TeamDeploy.CodePlex.com">http://TeamDeploy.CodePlex.com</a>. 
The installation instructions are detailed on the site.  For this, I will assume
Team Deploy 2010 is already installed.
</p>
        <p>
Next open Visual Studio 2010 and create a new build definition workflow.  Create
3 arguments called RemoteExecuteFilename, TargetMachine, and RemoteCommand.
</p>
        <p>
Instead of using the Deploy activity, add the RemoteExecute activity in an AgentScope
container.
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_2.png">
            <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb.png" width="504" height="342" />
          </a>
        </p>
        <p>
Set the properties on the RemoteExecute activity to the arguments passed in.
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_4.png">
            <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb_1.png" width="454" height="332" />
          </a>
        </p>
        <p>
Next, set the properties that were exposed as arguments of the build definition. 
For the RemoteCommand, here is where you want to specify calling PowerShell.exe and
the script file that will be executed on the target machine.  One thing I have
learned after taking this snapshot is that if you have a space in the path for the
script than use this syntax:
</p>
        <p>
PowerShell.exe –File “\\buildserver\deploy scripts\Update.ps1”
</p>
        <p>
Next specify the path where the PSTools were installed and finally specify the machine
that you want to run the remote script.
</p>
        <p>
          <a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_6.png">
            <img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb_2.png" width="504" height="296" />
          </a>
        </p>
        <p>
The final step is to create the deployment script.  Thanks to the power of PowerShell,
these deployment scripts can perform any action.  I have created steps for starting/stoping
services, applying SQL Server schema changes, search and replace strings in configuration
files, etc. Essentially anything you can do in a batch file and in .NET code, can
be done in PowerShell.
</p>
        <p>
Here is a small sample script that I created.  I have creates some much more
complicated scripts and ran them on remote machines without any issues.
</p>
        <pre class="csharpcode">
          <span class="str">"Performing removal steps..."</span> $servicename
= <span class="str">"PLA"</span> $service = Get-Service $servicename <span class="kwrd">if</span>($service.Status <span class="preproc">-eq</span><span class="str">"Running"</span>)
{ <span class="str">"Stopping "</span> + $servicename Stop-Service $servicename
} <span class="str">"status="</span> + $service.Status Remove-Item <span class="str">"c:\miketest2"</span> msiexec
/qn /x <span class="str">"{26260DBA-1519-4967-9118-D827793EF3B3}"</span><span class="str">"Removal
complete. Starting the installation steps..."</span> msiexec /qb! /i <span class="str">"\\buildserver\deploy\simple.msi"</span> New-Item <span class="str">"c:\miketest2"</span> -type
directory <span class="str">"Applying SQL Server Schema changes..."</span> sqlcmd
-S W2K8R2BOOT -E -i \\buildserver\deploy\dropaddcooltable.sql <span class="kwrd">if</span>($service.Status <span class="preproc">-eq</span><span class="str">"Stopped"</span>)
{ <span class="str">"Starting "</span> + $servicename Start-Service $servicename
}</pre>
        <p>
This is it. Here are also a couple things to consider. Copy MSIs, SQL Scripts, and
the deployment script to a versioned folder.  The folder is the snapshot in time
including the deployment file.  Keep the deployment scripts in source control. 
Lastly there is a new feature in PowerShell 2.0 called PowerShell Remoting. 
I have tried it, but it looks like this could also work.  It is on my list to
research and I will be sure to report back when I find out more information.
</p>
        <p>
Enjoy!
</p>
        <p>
Mike 
</p>
        <p>
This was cross posted at <a title="http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx" href="http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx">http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx</a> on
the Deliveron’s blog at <a href="http://www.deliveron.com/blog">http://www.deliveron.com/blog</a>.
</p>
        <p>
        </p>
        <style type="text/css">

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=510464a0-fdd7-4635-8fe8-786bf726a84c" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>Executing PowerShell Scripts on Remote Machines with TFS 2010 and Team Deploy 2010</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,510464a0-fdd7-4635-8fe8-786bf726a84c.aspx</guid>
      <link>http://www.codesmartnothard.com/2010/12/08/ExecutingPowerShellScriptsOnRemoteMachinesWithTFS2010AndTeamDeploy2010.aspx</link>
      <pubDate>Wed, 08 Dec 2010 05:45:00 GMT</pubDate>
      <description>&lt;p&gt;
Team Deploy 2010 is a custom add-on for Team Foundation Server 2010 (TFS) to deploy
MSIs to servers and PCs.&amp;#160; The deploy activity uses an XML file to manage the
servers and steps for deployment including starting/stopping services and installing/uninstalling
the MSIs.&amp;#160; This is very effective for automated deployments in environments where
automated deployments are allowed.&amp;#160; This however does not provide a practice
run into downstream environments where automated deployments are not allowed such
as Staging/Integration and Production.
&lt;/p&gt;
&lt;p&gt;
An alternative to this that does offer some deployment consistencies beyond the MSI
is to have Team Deploy 2010 (or Team Deploy for TFS 2008 also supports this) execute
a PowerShell script to perform the deployment steps.&amp;#160; The advantage of this is
that the PowerShell scripts can also be used to perform the manual deployments to
these other environments.&amp;#160; This won’t work in every scenario but should in a
lot.&amp;#160; In this post, I am going to explain how to do this.
&lt;/p&gt;
&lt;p&gt;
The first thing to do is to install Team Deploy 2010.&amp;#160; This is free and can be
downloaded at &lt;a href="http://TeamDeploy.CodePlex.com"&gt;http://TeamDeploy.CodePlex.com&lt;/a&gt;.&amp;#160;
The installation instructions are detailed on the site.&amp;#160; For this, I will assume
Team Deploy 2010 is already installed.
&lt;/p&gt;
&lt;p&gt;
Next open Visual Studio 2010 and create a new build definition workflow.&amp;#160; Create
3 arguments called RemoteExecuteFilename, TargetMachine, and RemoteCommand.
&lt;/p&gt;
&lt;p&gt;
Instead of using the Deploy activity, add the RemoteExecute activity in an AgentScope
container.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_2.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb.png" width="504" height="342" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Set the properties on the RemoteExecute activity to the arguments passed in.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_4.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb_1.png" width="454" height="332" /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Next, set the properties that were exposed as arguments of the build definition.&amp;#160;
For the RemoteCommand, here is where you want to specify calling PowerShell.exe and
the script file that will be executed on the target machine.&amp;#160; One thing I have
learned after taking this snapshot is that if you have a space in the path for the
script than use this syntax:
&lt;/p&gt;
&lt;p&gt;
PowerShell.exe –File “\\buildserver\deploy scripts\Update.ps1”
&lt;/p&gt;
&lt;p&gt;
Next specify the path where the PSTools were installed and finally specify the machine
that you want to run the remote script.
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_6.png"&gt;&lt;img style="border-right-width: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto" title="image" border="0" alt="image" src="http://codesmartnothard.com/content/binary/WindowsLiveWriter/ExecutingPowerShellScriptsonRemoteMachin_9B19/image_thumb_2.png" width="504" height="296" /&gt;&lt;/a&gt; 
&lt;/p&gt;
&lt;p&gt;
The final step is to create the deployment script.&amp;#160; Thanks to the power of PowerShell,
these deployment scripts can perform any action.&amp;#160; I have created steps for starting/stoping
services, applying SQL Server schema changes, search and replace strings in configuration
files, etc. Essentially anything you can do in a batch file and in .NET code, can
be done in PowerShell.
&lt;/p&gt;
&lt;p&gt;
Here is a small sample script that I created.&amp;#160; I have creates some much more
complicated scripts and ran them on remote machines without any issues.
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="str"&gt;&amp;quot;Performing removal steps...&amp;quot;&lt;/span&gt; $servicename
= &lt;span class="str"&gt;&amp;quot;PLA&amp;quot;&lt;/span&gt; $service = Get-Service $servicename &lt;span class="kwrd"&gt;if&lt;/span&gt;($service.Status &lt;span class="preproc"&gt;-eq&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Running&amp;quot;&lt;/span&gt;)
{ &lt;span class="str"&gt;&amp;quot;Stopping &amp;quot;&lt;/span&gt; + $servicename Stop-Service $servicename
} &lt;span class="str"&gt;&amp;quot;status=&amp;quot;&lt;/span&gt; + $service.Status Remove-Item &lt;span class="str"&gt;&amp;quot;c:\miketest2&amp;quot;&lt;/span&gt; msiexec
/qn /x &lt;span class="str"&gt;&amp;quot;{26260DBA-1519-4967-9118-D827793EF3B3}&amp;quot;&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Removal
complete. Starting the installation steps...&amp;quot;&lt;/span&gt; msiexec /qb! /i &lt;span class="str"&gt;&amp;quot;\\buildserver\deploy\simple.msi&amp;quot;&lt;/span&gt; New-Item &lt;span class="str"&gt;&amp;quot;c:\miketest2&amp;quot;&lt;/span&gt; -type
directory &lt;span class="str"&gt;&amp;quot;Applying SQL Server Schema changes...&amp;quot;&lt;/span&gt; sqlcmd
-S W2K8R2BOOT -E -i \\buildserver\deploy\dropaddcooltable.sql &lt;span class="kwrd"&gt;if&lt;/span&gt;($service.Status &lt;span class="preproc"&gt;-eq&lt;/span&gt; &lt;span class="str"&gt;&amp;quot;Stopped&amp;quot;&lt;/span&gt;)
{ &lt;span class="str"&gt;&amp;quot;Starting &amp;quot;&lt;/span&gt; + $servicename Start-Service $servicename
}&lt;/pre&gt;
&lt;p&gt;
This is it. Here are also a couple things to consider. Copy MSIs, SQL Scripts, and
the deployment script to a versioned folder.&amp;#160; The folder is the snapshot in time
including the deployment file.&amp;#160; Keep the deployment scripts in source control.&amp;#160;
Lastly there is a new feature in PowerShell 2.0 called PowerShell Remoting.&amp;#160;
I have tried it, but it looks like this could also work.&amp;#160; It is on my list to
research and I will be sure to report back when I find out more information.
&lt;/p&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;p&gt;
Mike 
&lt;/p&gt;
&lt;p&gt;
This was cross posted at &lt;a title="http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx" href="http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx"&gt;http://www.deliveron.com/blog/post/Executing-PowerShell-Scripts-on-Remote-Machines-with-TFS-2010-and-Team-Deploy-2010.aspx&lt;/a&gt; on
the Deliveron’s blog at &lt;a href="http://www.deliveron.com/blog"&gt;http://www.deliveron.com/blog&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;style type="text/css"&gt;

.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=510464a0-fdd7-4635-8fe8-786bf726a84c" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,510464a0-fdd7-4635-8fe8-786bf726a84c.aspx</comments>
      <category>ALM</category>
      <category>PowerShell</category>
      <category>Team Build 2010</category>
      <category>Team Deploy</category>
      <category>TFS 2010</category>
      <category>Visual Studio 2010</category>
    </item>
    <item>
      <trackback:ping>http://www.codesmartnothard.com/Trackback.aspx?guid=f28e6205-1ac5-41f3-be0d-f84d7db5c79b</trackback:ping>
      <pingback:server>http://www.codesmartnothard.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.codesmartnothard.com/PermaLink,guid,f28e6205-1ac5-41f3-be0d-f84d7db5c79b.aspx</pingback:target>
      <dc:creator>Mike Douglas</dc:creator>
      <wfw:comment>http://www.codesmartnothard.com/CommentView,guid,f28e6205-1ac5-41f3-be0d-f84d7db5c79b.aspx</wfw:comment>
      <wfw:commentRss>http://www.codesmartnothard.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f28e6205-1ac5-41f3-be0d-f84d7db5c79b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Coded UI Tests do a great job of capturing the action recordings of the steps performed
in a test case. The action recordings are used to create the automated code to test
the actions. Unfortunately sometimes these steps are too literal and become excessive
especially when running the tests using multiple rows of parameters (that are essentially
data driven tests) 
</p>
        <p>
In my example, I created a test case that lists some steps that include opening the
application, adding a new customer record, and closing the application. The application
allows for creating multiple customer records without closing and reopening the application.
Closing and reopening the application for each row in the automated test is unnecessary.
Shared steps at the beginning or ending of the tests including logging in/out could
be good candidates to make more efficient.
</p>
        <p>
Below is the example of the test that was generated from the action recordings of
the test case. 
</p>
        <pre class="csharpcode">        [DataSource(<span class="str">"Microsoft.VisualStudio.TestTools.DataSource.TestCase"</span>, <span class="str">"http://localhost:8080/tfs/defaultcollection;Tailspin
Toys"</span>, <span class="str">"53"</span>, 
<br />
DataAccessMethod.Sequential), TestMethod] <span class="kwrd">public</span><span class="kwrd">void</span> AddCustomer_ShouldSaveAndClose()
{ <span class="rem">// To generate code for this test, select "Generate Code for Coded
UI Test" 
<br />
// from the shortcut menu and select one of the menu items.</span><span class="rem">//
For more information on generated code, 
<br />
// </span><span class="rem">see http://go.microsoft.com/fwlink/?LinkId=179463</span><span class="kwrd">this</span>.UIMap.OpenCustomerKeeper(); <span class="kwrd">this</span>.UIMap.OpenNewRecord(); <span class="kwrd">this</span>.UIMap.FillParams.UIText1EditText
= TestContext.DataRow[<span class="str">"Name"</span>].ToString(); <span class="kwrd">this</span>.UIMap.FillParams.UIText2EditText
= TestContext.DataRow[<span class="str">"City"</span>].ToString(); <span class="kwrd">this</span>.UIMap.FillParams.UIText3EditText
= TestContext.DataRow[<span class="str">"Phone"</span>].ToString(); <span class="kwrd">this</span>.UIMap.FilloutNameCityandPhone(); <span class="kwrd">this</span>.UIMap.SaveandClose(); <span class="kwrd">this</span>.UIMap.VerifyCustomerSaved(); <span class="kwrd">this</span>.UIMap.CloseApplication();
}</pre>
        <style type="text/css">




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
        <p>
As you can see it generated the OpenCustomerKeeper() and CloseApplication() methods.
For each parameters row for the test case it will open and close the application.
These are the two methods I only want to execute at the start of the test run and
the end of the test run. Also if I had other tests that could be run without restarting
the application this change would benefit those tests also.
</p>
        <p>
Our options are to move these steps to the TestInitialize/TestCleanup or ClassInitialize/ClassCleanup.
The TestInitialize/TestCleanup however is called before each test that also includes
before each row of the data driven test. Therefore, this would be the same result
and open/close the application before each row. This leaves the ClassInitialize/ClassCleanup.
Unfortunately it is not quite as easy as moving the method. First these two methods
need to be static so this.UIMap won’t exist. Secondly, the Playback engine is not
initialized in these methods. We will need to explicitly perform the Initialize and
Cleanup of the Playback engine. Lastly the ClassInitialize attribute has to be applied
to a method with passes in the TestContext as a parameter.
</p>
        <p>
Here is the ClassInitialize method
</p>
        <pre class="csharpcode">
          <span class="kwrd">static</span>
          <span class="kwrd">private</span> UIMap
sharedTest = <span class="kwrd">new</span> UIMap(); [ClassInitialize] <span class="kwrd">static</span><span class="kwrd">public</span><span class="kwrd">void</span> ClassInit(TestContext
context) { Playback.Initialize(); <span class="kwrd">try</span> { sharedTest.OpenCustomerKeeper();
} <span class="kwrd">finally</span> { Playback.Cleanup(); } }</pre>
        <p>
        </p>
        <p>
Lastly, we will move the CloseApplication() method to the ClassCleanup method.
</p>
        <blockquote>
          <pre class="csharpcode">[ClassCleanup] 
<span class="kwrd">static</span><span class="kwrd">public</span><span class="kwrd">void</span> ClassCleanup()
{ Playback.Initialize(); <span class="kwrd">try</span> { sharedTest.CloseApplication();
} <span class="kwrd">finally</span> { Playback.Cleanup(); } }</pre>
        </blockquote>
        <p>
        </p>
        <p>
I hope you find this useful.
</p>
        <p>
Mike
</p>
        <p>
Contact us at <a href="mailto:tfs@deliveron.com">tfs@deliveron.com</a> to work with
your development teams for all of your Visual Studio ALM needs.
</p>
        <img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=f28e6205-1ac5-41f3-be0d-f84d7db5c79b" />
        <br />
        <hr />
This weblog is sponsored by <a href="http://www.deliveron.com">Deliveron Consulting
Services</a>. 
</body>
      <title>More Efficient Coded UI Tests with ClassInitialize</title>
      <guid isPermaLink="false">http://www.codesmartnothard.com/PermaLink,guid,f28e6205-1ac5-41f3-be0d-f84d7db5c79b.aspx</guid>
      <link>http://www.codesmartnothard.com/2010/11/26/MoreEfficientCodedUITestsWithClassInitialize.aspx</link>
      <pubDate>Fri, 26 Nov 2010 11:01:00 GMT</pubDate>
      <description>&lt;p&gt;
Coded UI Tests do a great job of capturing the action recordings of the steps performed
in a test case. The action recordings are used to create the automated code to test
the actions. Unfortunately sometimes these steps are too literal and become excessive
especially when running the tests using multiple rows of parameters (that are essentially
data driven tests) 
&lt;/p&gt;
&lt;p&gt;
In my example, I created a test case that lists some steps that include opening the
application, adding a new customer record, and closing the application. The application
allows for creating multiple customer records without closing and reopening the application.
Closing and reopening the application for each row in the automated test is unnecessary.
Shared steps at the beginning or ending of the tests including logging in/out could
be good candidates to make more efficient.
&lt;/p&gt;
&lt;p&gt;
Below is the example of the test that was generated from the action recordings of
the test case. 
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;        [DataSource(&lt;span class="str"&gt;"Microsoft.VisualStudio.TestTools.DataSource.TestCase"&lt;/span&gt;, &lt;span class="str"&gt;"http://localhost:8080/tfs/defaultcollection;Tailspin
Toys"&lt;/span&gt;, &lt;span class="str"&gt;"53"&lt;/span&gt;, 
&lt;br /&gt;
DataAccessMethod.Sequential), TestMethod] &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; AddCustomer_ShouldSaveAndClose()
{ &lt;span class="rem"&gt;// To generate code for this test, select "Generate Code for Coded
UI Test" 
&lt;br /&gt;
// from the shortcut menu and select one of the menu items.&lt;/span&gt; &lt;span class="rem"&gt;//
For more information on generated code, 
&lt;br /&gt;
// &lt;/span&gt;&lt;span class="rem"&gt;see http://go.microsoft.com/fwlink/?LinkId=179463&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.OpenCustomerKeeper(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.OpenNewRecord(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.FillParams.UIText1EditText
= TestContext.DataRow[&lt;span class="str"&gt;"Name"&lt;/span&gt;].ToString(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.FillParams.UIText2EditText
= TestContext.DataRow[&lt;span class="str"&gt;"City"&lt;/span&gt;].ToString(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.FillParams.UIText3EditText
= TestContext.DataRow[&lt;span class="str"&gt;"Phone"&lt;/span&gt;].ToString(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.FilloutNameCityandPhone(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.SaveandClose(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.VerifyCustomerSaved(); &lt;span class="kwrd"&gt;this&lt;/span&gt;.UIMap.CloseApplication();
}&lt;/pre&gt;
&lt;style type="text/css"&gt;




.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;
&lt;p&gt;
As you can see it generated the OpenCustomerKeeper() and CloseApplication() methods.
For each parameters row for the test case it will open and close the application.
These are the two methods I only want to execute at the start of the test run and
the end of the test run. Also if I had other tests that could be run without restarting
the application this change would benefit those tests also.
&lt;/p&gt;
&lt;p&gt;
Our options are to move these steps to the TestInitialize/TestCleanup or ClassInitialize/ClassCleanup.
The TestInitialize/TestCleanup however is called before each test that also includes
before each row of the data driven test. Therefore, this would be the same result
and open/close the application before each row. This leaves the ClassInitialize/ClassCleanup.
Unfortunately it is not quite as easy as moving the method. First these two methods
need to be static so this.UIMap won’t exist. Secondly, the Playback engine is not
initialized in these methods. We will need to explicitly perform the Initialize and
Cleanup of the Playback engine. Lastly the ClassInitialize attribute has to be applied
to a method with passes in the TestContext as a parameter.
&lt;/p&gt;
&lt;p&gt;
Here is the ClassInitialize method
&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;private&lt;/span&gt; UIMap
sharedTest = &lt;span class="kwrd"&gt;new&lt;/span&gt; UIMap(); [ClassInitialize] &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClassInit(TestContext
context) { Playback.Initialize(); &lt;span class="kwrd"&gt;try&lt;/span&gt; { sharedTest.OpenCustomerKeeper();
} &lt;span class="kwrd"&gt;finally&lt;/span&gt; { Playback.Cleanup(); } }&lt;/pre&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
Lastly, we will move the CloseApplication() method to the ClassCleanup method.
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre class="csharpcode"&gt;[ClassCleanup] 
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ClassCleanup()
{ Playback.Initialize(); &lt;span class="kwrd"&gt;try&lt;/span&gt; { sharedTest.CloseApplication();
} &lt;span class="kwrd"&gt;finally&lt;/span&gt; { Playback.Cleanup(); } }&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
I hope you find this useful.
&lt;/p&gt;
&lt;p&gt;
Mike
&lt;/p&gt;
&lt;p&gt;
Contact us at &lt;a href="mailto:tfs@deliveron.com"&gt;tfs@deliveron.com&lt;/a&gt; to work with
your development teams for all of your Visual Studio ALM needs.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.codesmartnothard.com/aggbug.ashx?id=f28e6205-1ac5-41f3-be0d-f84d7db5c79b" /&gt;
&lt;br /&gt;
&lt;hr /&gt;
This weblog is sponsored by &lt;a href="http://www.deliveron.com"&gt;Deliveron Consulting
Services&lt;/a&gt;. </description>
      <comments>http://www.codesmartnothard.com/CommentView,guid,f28e6205-1ac5-41f3-be0d-f84d7db5c79b.aspx</comments>
      <category>ALM</category>
      <category>Coded UI Tests</category>
      <category>TFS 2010</category>
    </item>
  </channel>
</rss>
