Showing posts with label Visual Studio 2010. Show all posts
Showing posts with label Visual Studio 2010. Show all posts

Wednesday, July 13, 2011

Documenting Key End-to-End Deployment Scenarios

 

The IIS Web Deployment Tool (Web Deploy) and the deployment features introduced in Visual Studio 2010 enable you to automate many deployment tasks, but we have heard you all that many common scenarios not yet documented fully. We are addressing this need by creating step-by-step walkthroughs that will guide you from beginning to end through scenarios that address common real-world needs.

UPDATE:  We just published the Enterprise Deployment Series which can be found at:

Interestingly, remaining of this blog post is not the documentation of the solution but actual articulation of problem statements. This post presents the first set of scenarios that we have identified and solicit your feedback to help us determine they are representative enough or not. If you have any feedback as usual you can post them here as comments or feel free to send me an email at Vishal.Joshi@Microsoft.com.

Scenario 1: Enterprise Deployment with Continuous Integration

In this scenario, a solution that includes multiple web application projects is deployed to test, staging, and production environments, using a continuous integration process for staging and production.

Target Environments

The TESTING environment consists of a server that runs IIS 7.5 and a server that runs SQL Server 2008 R2. The developer machine has a network connection to the test servers, and the developer uses one-click publish to deploy to testing environment.

STAGING consists of a web farm (2 servers running IIS 7.5) and a database server that runs SQL Server 2008 R2. The developer machine has network access to a TFS server that acts as a source code repository, and the TFS server has network access to the staging servers. (The developer machine does not have direct access to the staging environment, and the developer does not have administrative rights on the staging servers.) Team Build builds the Visual Studio solution, runs unit tests, and publishes to staging. Each time that Team Build performs build and deployment, it simultaneously creates a deployment package (web deploy .zip file) for use in deploying to production.

The PRODUCTION environment mirrors staging except that a firewall (or perhaps even different domains) prevents direct access for publishing from the TFS server to production. When a build is approved for production, the IT department uses the package created when TFS publishes to staging to deploy to the production servers.

The diagram below illustrates this scenario:

Enterprise_Scenario_Diagram

Enterprise scenarios may have a QA environment set up in a manner similar to staging; however, for the purposes of demonstrating how to set up deployment it's not necessary to include that here, because the process would be similar to the process for setting up staging.

Visual Studio Solution

The Visual Studio solution to be deployed consists of multiple web application projects, a class library project, and a unit test project. Deployment must take into account the following considerations:

  • One of the projects uses ASP.NET membership functionality, and the membership database must be deployed. Account information can be deployed to test but not to staging or production.
  • One of the projects uses a SQL Server database that is accessed using the Entity Framework (Database First, using an .edmx file). On initial deployment to any environment, only the structure (schema) should be deployed. For any database deployment after the initial deployment, data already entered online in that environment must be preserved.
  • The class library project creates an assembly for a custom control that is used in one of the projects. This assembly needs to be installed in the GAC as part of the deployment process.
  • The custom control gets a default value from the registry. The registry value needs to be different in each environment and needs to be updated when the solution is deployed. (This particular use of registry settings is not common, but updating the registry is a common need, and this provides a simple way of integrating a registry update into the scenario.)
  • The Web.config file contains settings that must be different for debug vs. release builds, and settings that must be different for different target environments.
  • One of the web projects includes a folder for log files. The deployment process must not copy files in this folder from source to destination and must not delete files from the folder on the target server.
  • IIS settings for error handling and authentication must be set up on the target server during deployment. For the test environment these can be the same as the settings on the developer machine, but for staging and production the settings are different.

Some additional deployment considerations apply only to the automated deployment from TFS for staging and production:

  • Deployment should occur only if the unit tests are successful.
  • The web projects need to be precompiled before deployment.
  • The IIS settings for staging and production are taken from IIS on the TFS server. (This is a limitation of the current release of Visual Studio and Web Deploy; when the walkthroughs are updated for the next release of the software, hopefully IIS will not be required on the TFS server (keeping fingers crossed Smile)
  • App_offline.htm must be set up at the start of deployment and removed at the end.
  • Deployment activities should be logged. When deployment completes or fails, email notifications should be sent to designated recipients.
  • If deployment fails, the previous deployment's package should be redeployed, or the current deployment should be retried.
Tasks Illustrated

The walkthroughs for this scenario would guide you through the following tasks"

  • Downloading the Visual Studio solution to be deployed.
  • Setting up the test server.
  • Using one-click publish to deploy to testing servers:
    • Initial deployment.
    • Redeployment without a database change (for example, an update to code in a web page).
    • Redeployment after making a database schema change.
  • Setting up staging and production servers.
  • Setting up the build server.
  • Three deployments to staging (initial, web page change, database change).
  • Three deployments to production (initial, web page change, database change).

For the Visual Studio 2010 version of the walkthrough, database updates will involve running custom SQL scripts as part of the deployment. The scripts will be created manually; tools such as TSData and Red Gate can be used to generate such scripts, but those tools will not be covered in these walkthroughs. Eventually we will look at smoothing this flow as well.

Scenario 2: Enterprise Deployment for MVC and Entity Framework Code First

This is a variant of the first scenario that differs from it in the following ways:

  • The web projects are MVC instead of Web Forms.
  • Entity Framework Code First is used instead of Database First (no .edmx file).
  • TeamCity is used instead of TFS.

Scenario 3: Enterprise Deployment for Web Site Projects

This is another variant of the first scenario that differs from it in the following ways:

  • The web projects are web site projects instead of web application projects or MVC.
  • Web Deployment Projects (WDP 2010) are used.
  • One-click publish is not available for web site projects, so a web deployment package is used for deploying to test.

For those of you who work in enterprise environments, do these scenarios adequately represent the kinds of challenges you face in deploying ASP.NET web applications? Are any key pieces missing? We cannot answer every question in these walkthroughs, but if there are other issues commonly faced by your team, we can add solutions for them to the walkthroughs as well.

Your thoughts and feedback are welcome.  Also I want to thank Tom Dykstra, Bilal Aslam & Sayed Hashimi on our team who will be helping on putting together a lot of this content for you.

FEB 2012 UPDATE:  The work on these scenario documentation has started happening.  The tutorials are still being written but the sample app with an initial draft of the first part of the tutorials is available on MSDN:

http://code.msdn.microsoft.com/ASPNET-Enterprise-Web-6b2ad7cf

(The tutorials are in Word docs in a folder in the sample project.)

They’ll be published on the ASP.NET site most likely in the next couple of months.

Thanks for reading!!

-Vishal

Wednesday, June 15, 2011

Announcing HTML5 & CSS3 support for Visual Studio 2010 SP1

image

Since the last few months it feels like web standards are moving at pace that we would really like them to move. Every browser is pushing the envelope ahead including our very own IE9. For the first time it feels like web is getting the extra freedom of expression that it deserves and we want to contribute to that.

ASP.NET developers have been asking for HTML5 & CSS3 support all the time and today we are super excited to announce the public availability of Visual Studio Web Standards Update which brings a ton of HTML5 & CSS3 support to Visual Studio 2010 SP1. VS Web Standards Update is a free extension available for anyone who is using Visual Studio 2010 SP1 and it provides HTML5 & CSS3 support based on current W3C specifications.

clip_image001

HTML5

clip_image004

VS Web Standards Update provides you intellisense and validation for most common HTML 5 features like:

· Video & related tags

· Audio & related tag

· New input types like email, url, date etc

· Drag & Drop support

· Accessibility standard WAI-ARIA

· Microdata

· Schema.org & more SEO friendly goodness

·

Browser APIs

· Geo-Location - Having location aware websites is growing trend and now you will have full intellisense and validation within Visual Studio for creating websites which are location aware. For sample view the source for the IE9 test drive demo.

· Local Storage – IE has been supporting local storage from IE8 onwards, now Visual Studio will provide you with full fidelity intellisense to create sites which can save state within browser. For sample of try view source on HTML5 Demo Site

CSS3

clip_image005

This update supports intellisense and validation for most of the CSS3 modules including:

· 2D Transforms

· 3D Transforms

· Animations

· Background & Borders

· Basic Box Model

· Basic UI

· Behavior

· Color

· Flexible Box Layout

· Fonts

· Generated Content for Paged Media

· Hyperlink Presentation

· Line

· Lists

· Marquee

· Media Queries

· Multi Column

· Namespaces

· Paged Media

· Presentations Levels

· Ruby

· Selectors

· Speech

· Syntax

· Template Layout

· Text

· Transitions

Additionally, if you are trying to make websites which work on a variety of platforms and browsers you will love the fact that Web Standards Update not only supports IE specific prefixes like –ms; but also other vendor prefixes like –webkit and –moz.

With all of the above goodness we hope you all will enjoy this update as much as we did creating it and hope you will share the good news with our larger developer community.

Sharable Links

· Download URL - http://visualstudiogallery.msdn.microsoft.com/a15c3ce9-f58f-42b7-8668-53f6cdc2cd83

· VWD Team Announcement post by Mads - http://blogs.msdn.com/b/webdevtools/archive/2011/06/15/web-standards-update-for-visual-studio-2010-sp1.aspx

· Walkthrough post by Hanselman - http://www.hanselman.com/blog/AnnouncingTheWebStandardsUpdateHTML5SupportForTheVisualStudio2010Editor.aspx

Finally, I want to call out that this update is made feasible due to heroic efforts by a lot our team members working on their personal spare time, so please give a huge shout out to our team including Mads Kristensen, Peter Spada, Van Kichline, Aliaksei Baturytski, Damian Edwards, Barry Tang, Bala Chirtsabesan, Alex Gavrilov, Xinyang Qiu, Jon Jung, Scott Hanselman, Teri Schroeppel & Yong Lee.

Thanks again!!

Vishal R. Joshi | http://vishalrjoshi.com | @vishalrjoshi

PS: The Web Standards Update works on both VS 2010 SP1 and VWD Express 2010 SP1. Being a VS Extension, it does not support certain CSS3 selector syntax & Browser API intellisense which would require servicing the shipping bits.

Monday, March 07, 2011

ASP.NET Team Sessions at TechEd Dubai

The TechEd, Middle East web site does not have deep-linking for the sessions so I thought I would quickly blog it out so that it can be shared easily.  Here are the sessions Scott & I are doing at TechEd Dubai (sorted by date & time)if you are around please stop by:

-----------------------------------------------------------------------------------------------

09 March 2011 10:30 AM - 11:30 AM

Deep Dive into Razor

Track: Web Platforms (WEB303)

Speakers: Scott Hunter

Razor is the new syntax for building web applications in both ASP.NET Web Pages and ASP.NET MVC. It has a very concise syntax that blurs the transition between code and markup. We will start with a deep dive showing how to program the web using Razor which will include building reusable components called helpers that can share both markup and code in a very natural way. Next we will demonstrate how Razor’s extensibility can be used to use it outside of typical web scenario’s by writing some code using the Razor syntax to send rich emails that contain both text, markup and code. You should walk away knowing how to program that web with Razor and how Razor can be used outside the web to increase your productivity as a rich templating engine.

-----------------------------------------------------------------------------------------------

The New Cool Kid on the Block: ASP.NET MVC 3

09 March 2011 11:45 AM - 12:45 PM

Track: Web Platforms (WEB304) 

Speaker: Vishal Joshi

ASP.NET MVC 3 with its friends Razor and NuGet are here to make your web development much easier and jazzier. If you are a web developer intending to build standards based, maintainable and extensible apps in a productive fashion, you are not allowed to leave Tech·Ed without learning about ASP.NET MVC 3. It doesn’t matter even if you haven’t played with ASP.NET MVC before, come join us and we will introduce you to it. If you have been working with ASP.NET MVC already, join us and you can hear about all the new toys you now have.

-----------------------------------------------------------------------------------------------

10 March 2011 09:00 AM - 10:00 AM

What’s New in ASP.NET & Visual Studio for Web Developers

Track: Web Platforms (WEB305)

Speaker: Scott Hunter

ASP.NET 4 gives you more control than ever over markup as well as adding exciting new features making both client and server side data based applications easier and faster to develop than ever before. With Visual Studio 2010 adding improved support for JavaScript, HTML markup and CSS editing and powerful new web application deployment technology, together, ASP.NET 4 and Visual Studio 2010 make it easier and quicker than ever to develop standards based, CSS styled web applications. We will also cover some of the latest improvements in Visual Studio such as support for Razor Syntax, NuGet and IIS Express.

-----------------------------------------------------------------------------------------------

10 March 2011 10:30 AM - 11:30 AM

Introduction to Microsoft ASP.NET MVC

Track: Web Platforms (WEB05L) 

Speakers: Scott Hunter, Vishal Joshi

This lab introduces you to developing Web applications with ASP.NET MVC, and teaches you the basic conventions and features contained within it. It also shows you how to unit test your custom controllers and your application's route definitions.

-----------------------------------------------------------------------------------------------

10 March 2011 01:45 PM - 02:45 PM

Meet the Visual Studio Team

Track: Developer Tools, Languages, and Frameworks (IAT209)

Speakers: Lisa Feigenbaum, Shy Cohen, Brian Keller, Vishal Joshi, Scott Hunter

Session Type: Interactive Discussion

Audience: Developer

This is an opportunity to interact with key members of the Visual Studio team. They discuss their areas of expertise and answer any questions you might have.

-----------------------------------------------------------------------------------------------

10 March 2011 03:00 PM - 04:00 PM

Web Deployment That Can Impress your Boss

Track: Web Platforms (WEB306)

Speaker: Vishal Joshi

If you typically deploy your web applications using Windows Explorer or have a deployment document longer than your resume, please stop. Come see a practical session on how the new deployment goodness in Visual Studio 2010 can help. We dig into Web Deploy (a.k.a. MSDeploy) and deployment from within Visual Studio 2010. Learn how to package up web apps in .zip files, deploy them using UI, or command file, move their settings and databases easily and much more. We start with the basics and ramp it up quickly, exploring team build deployment and advanced techniques.

-Vishal

Tuesday, May 18, 2010

Applying XDT magic to App.Config

For several weeks now people have been asking to be able to use the XML Document Transform (XDT) with App.Config files similar to what is available with Web.Config files in VS 2010…
In all honesty there is no official/supported  implementation of XDT for any other project type than Web Application Projects but the good news is that the basis of Web.Config Transformation resides in Web Publishing Pipeline (WPP) which are set of extensible tasks and targets hooked up to provide a great deployment story for Web Applications…
Today, Ming (our senior dev on Visual Studio) and I decided to get together to give some love to App.Config file too… The below implementation is a crude way of getting XDT working into other project types within VS 2010… In a way, I would say it is a big solution for a smaller problem but the idea here is to get people unblocked and show the kind of things that WPP is capable of doing… 
If by now everything is sounding foreign then please check out the articles:

  • Web.Config Transformation
  • VS 2010 Snippets for Web.Config Transformations
  • Web.Config Transforms (XDTs) for any XML files in your web projects
    Goals
    • Being able to use XDT syntax for App.Config files similar to what you can use with Web.Debug.Config and Web.Release.Config…
    • Being able to use this in an automated fashion in build environments like Team Build…
    • Reduce the concept count and make it as simple as possible (without digging deep into optimization & performance)…
  • Please take a look at Visual Studio extension which allows you to do this without the manual workarounds below:
  •  http://visualstudiogallery.msdn.microsoft.com/69023d00-a4f9-4a34-a6cd-7e854ba318b5

    Step by Step Instructions

    The example I am using below should be hopefully super simple that you can follow along without any prep work… All you need is VS 2010 which has “Visual Web Developer” components installed…

    Step 1 Create a new Windows Forms Application in VS 2010

    Step 2 Add App.Config file to the project…

    Add simple test settings to App.Config file as shown below:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <appSettings>
        <add key="author" value="Vishal Joshi"/>    
      </appSettings>
    </configuration>




    Step 3 Add App.Debug.Config file to the project, I would recommend using the same App.Config file adding mechanism as shown below




    app.debug.config



    Step 4 Modify the content of App.Debug.Config as shown below:



    <?xml version="1.0"?>
    
    <!-- For more information on using App.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
    
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
      <appSettings>
        <add key="article" value="XDT Magic for App.Config Files" xdt:Transform="Insert"/>
      </appSettings>
    </configuration>





    The key things to note above are:





    • There is a XDT namespace declaration which allows XDT engine to recognize the Transform/Locator syntax in the file


    • There is a new node being inserted into the config file using the syntax xdt:Transform=”Insert”




    Step 5 Save the edited files and unload the project frin VS 2010 Solution Explorer using the right click command as shown below:



    unload project




    Step 6 Edit the .csproj/.vbproj file to make App.Debug.Config file to be dependent on App.Config file as shown in the syntax below:




        <Content Include="App.config" />
        <Content Include="App.Debug.Config" >
          <DependentUpon>App.Config</DependentUpon>
        </Content>





    The key things to note above are:





    • By default the build action of App.Config and App.Debug.Config file will be “ None”… It needs to be changed to “Content”… This is a tiny pre-requisite for WPP but if you encounter any issues because of this then we can dig the work around…


    • DependentUpon node will make your App.Debug.Config appear as a node under your App.Config file similar to the way Web.Debug.Config and Web.Release.Config files appear under Web.Config file…


    • In VB Projects nested files are hidden so you might need to unhide these by clicking the icon on the solution explorer…




    Step 7 Change the ProjectConfigFileName property within your .csproj/.vbproj file



    WPP has an inbuilt property called ProjectConfigFileName which is by default set to Web.Config, we need to change this to app.Config which will allow projects like WinForm project not expect web.config files to transform… You can add this property right under ProjectGuid property as shown below:



      <PropertyGroup>
        <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
        <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
        <ProductVersion>8.0.30703</ProductVersion>
        <SchemaVersion>2.0</SchemaVersion>
        <ProjectGuid>{2D587604-866B-4675-8587-FA9728EC59D8}</ProjectGuid>
        <ProjectConfigFileName>App.Config</ProjectConfigFileName>




    Step 8 Hook up WPP within your WinForms project by importing the WPP targets.



    You can search for “Import” node in your project file and then simply copy below one line for WPP targets import



      <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />





    Step 9 Add a target to copy the transformed App.Config file to your output (BIN) directory




    You can simply copy paste the below code just before your </project> node closes in the .csproj/.vbproj file



      <Target Name="PostTransformAppConfig" AfterTargets="TransformWebConfig">
        <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
              SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" 
              DestinationFiles="$(OutputPath)\WinFormConfigTransform.exe.config" />
        <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
              SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" 
              DestinationFiles="$(OutputPath)\WinFormConfigTransform.vshost.exe.config" />
      </Target>





    The key things to note above are:





    • We hooked up the new PostTransformAppConfig target after TransformWebConfig target… The TransformWebConfig target is the native target in WPP which does any XML transform and will do the actual job of transforming App.Config as well..


    • The location at which the new App.Config file is getting copied is pretty self explanatory but do note that you do want to change “WinFormConfigTransform” to be the name of your own Project…  I just used a project called “WinFormConfigTransform” and hence the DestinationFiles path is named as such…




    Step 10 Run /T:TransformWebConfig task on your Project from MSBuild



    You need to use Visual Studio 2010 Command prompt and type in the below command



    msbuild C:\Vishal\WinFormConfigTransform.csproj /t:TransformWebConfig



    After running the above command if you now check the BIN folder of your project you should see that the Project.exe.Config file is now modified as shown below:



    image 



    NOTE: If you want the App.Config file to be Transformed after every build in your Visual Studio IDE (this will take some perf away but may not even be noticeable) then you can change Step 9 code to be as below:



    <Target Name="PostTransformAppConfig" AfterTargets="Build">
        <CallTarget Targets="TransformWebConfig"/>
        <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
              SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" 
              DestinationFiles="$(OutputPath)\WinFormConfigTransform.exe.config" />
        <Copy Condition="Exists('$(TransformWebConfigIntermediateLocation)\transformed\App.config')" 
              SourceFiles="$(TransformWebConfigIntermediateLocation)\transformed\App.config" 
              DestinationFiles="$(OutputPath)\WinFormConfigTransform.vshost.exe.config" />
      </Target>



    The only key difference above is that I made the new target to be called after “Build” and in the new target I made a call to “TransformWebConfig” target to ensure the transform happens before we try to copy the transformed app.config file to their final location…




    With the above change now when you build in IDE then the new transformed App.Config will be copied to your output directory…



    With the above 10 steps you should now be able to Transform your App.config just like the way you do Web.Config files in VS 2010



    -Vishal



    PS:  Whenever you make changes to your project file (like above) you make your project susceptible to data loss during upgrade to future versions of VS as next versions of VS will not know all the fancy code you put in the files, but such risks are part of the game to get all the fancy toys working :-)

    Sunday, May 02, 2010

    Xml Document Transforms (XDT) for any XML file in your project

    There have been several requests floating around to be able to use XDTs (the technology behind Web.Debug.Config/Web.Release.Config) with other XML files within the project…  To make that feasible I wrote a XmlDocumentTransform.targets  file which can generically transform any XML file using the standard Web.Config Transformation syntax introduced with VS 2010…

    Learn more about XDT & Web.Config Transformation here…

    Now to get started first download XmlDocumentTransform.targets file from my Skydive…

    Follow the below simple steps to get transformation working for any well formed XML file in your project…

    • Step 1: Save the downloaded XmlDocumentTransform.targets to %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v10.0\Web\XmlDocumentTransform.targets

    image

    NOTE: I would highly encourage you to make a copy of the Microsoft.WebApplication.targets file as backup before you do Step 2 below, as if this file is modified incorrectly then your VS 2010 instances might start showing funny problems which will be virtually impossible to debug and the only option left with you will be to repair/uninstall-install VS 2010… (i.e. proceed at your own risk :-))

    •  Step 2: Put following line of code in Microsoft.WebApplication.targets file just before closing of the Project node i.e. before </Project>...  
      <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\XmlDocumentTransform.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\XmlDocumentTransform.targets')" />
      The Microsoft.WebApplication.targets file is located at %ProgramFiles%\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications... 

    image  
    NOTE: Changing the above targets file will allow you to use this functionality with all the Web Application Projects (WAPs), if you just want to change this for the current project then you can put the same Import node in .csproj or .vbproj as well...  If you use per project model then you can also check in this file into source code control and have your team use it seamlessly…

    • Step 3: Open your .csproj/vbproj file and insert the below property in <PropertyGroup> section  <AllXmlsToTransform>Settings.xml;app.config</AllXmlsToTransform>

    image

     NOTE: The Settings.xml or app.config can be replaced with the name of Xml files you want to transform…

    • Step 4: Insert <OnAfterTransformWebConfig>TransformXml;</OnAfterTransformWebConfig> similar to #3 above but do not modify the TransformXml; text here…  This is the actual hook which ties in your project to this generic XDT system...  After making the Step 3 & Step 4 changes your project file should have below content…

    image

    • Step 5: Create Setting.Debug.Xml or similar files and put XDT syntax in them... You need to make sure in the .csproj/.vbproj file of yours you have the DependentUpon property is set like the example below:
          <Content Include="Configuration\Settings.xml" />
          <Content Include="Configuration\Settings.Debug.xml">
            <DependentUpon>Configuration\Settings.xml</DependentUpon>
          </Content>
          <Content Include="Configuration\Settings.Release.xml">
            <DependentUpon>Configuration\Settings.xml</DependentUpon>
          </Content>

    image

    NOTE: The above will allow your solution to look pretty, i.e. just like web.debug.config and web.release.config files show nested under web.config, your *.$(configuration).* files will show nested under your parent file too…

    With the above 5 steps you are all set to use XDT with any of the deployment models covered in the Overview of Web Deployment Post…  In a way above steps harness the power of Web Publishing Pipeline (WPP) extensibility model and you can do several other extensions like above if you are familiar with MsBuild sytax…

    SAMPLE:   The remainder of the post is just showing you the steps to test whether the changes you made worked or not (i.e. the remaining half of the post is just playing with what you already accomplished in the first half)… :-)

    • To test the above target file I created the below MVC 2.0 project structure:

    image

    • Once you put DependentUpon node in your project file you will have to click the  “Show All Files” icon on the solution explorer for VB Projects to see Settings.Debug.Xml
    • My Settings.xml file looked as below:

    image

    • My Settings.Debug.xml file looked as below:

    image

    • To test out I tried simple “file system” publish (Right click on project and say Publish)… The new WAP Publish dialog for me looked as below:

    image

    • After publishing my C:\TestPublish folder looked as below:

    image

    • Note that Settings.Debug.xml was removed from my final publish location as it is not required for my web to function and the content of Settings.xml file were transformed and looked as below:

    image

    TeamBuild/Commandline Approach: You can also use your new transformations from TeamBuild/MsBuild by using the below command (from VS 2010 Command prompt if you are trying locally):

    MsBuild MyXDTTestProject.csproj /t:TransformXml

    The output of the command line transform should look as below:

    image

    As specified above your transformed XML will be stored in obj\$(configuration)\Settings.xml… 

    As such feel free to open the XmlDocumentTransform.targets file which you download, I have tried to put as much comments as I could to make it readable…  If you go through it I am sure you will be able to do many other cool things out of it…

    -Vishal

    Monday, April 26, 2010

    Xml Document Transform (XDT) Snippets for VS 2010

    During my PDC talk I had shown some of the snippets that can come handy while using Web.Config Transformations…  This post is intended to share the XDT snippets and instructions on how to install them to use them with VS 2010…

    image

    • After this the XDT snippets will be available for you to use within any XML file within VS 2010…

    To know how to use XDTs for Web.Config file please check out the post about Web.Config Transformations

    Few interesting points about Transforms & Locators which are worth noting to do pretty powerful stuff with your XML are:

    • Transforms  - Transforms act on a XML node i.e. from XDT engine standpoint the node on which a transform is found is plucked out of the document and passed as a node to the Transform itself (e.g. “SetAttributes” Transform)… The Transform class internally implements the logic of modifying the node with its own special logic (i.e. setting attributes in case of “SetAttributes” Transform) and returns back the node to the engine…  The XDT engine then replaces the new node into the document…  The engine also passes the handle of the parent node to the transform which the transform can then play around with (e.g. “Insert” Transform receives a new node as well as the parent node and has the DOM code of inserting the new node under the parent…)

    image

    • Locators – XDT usually traverses through the XML document and constructs the XPath all along e.g. when it hits the add node under connectionStrings in web.config it has already constructed the XPath (/configuration/connectionString/add)…  Locators help with narrowing down the XPath so that the correct node can be picked up… Check out the example below:
       <connectionStrings>
    <add name="1stDB"
    connectionString="Data Source=Server1;Initial Catalog=DB1;Integrated Security=True"
    xdt:Transform="SetAttributes" />
    <add name="2ndDB"
    connectionString="Data Source=Server2;Initial Catalog=DB2;Integrated Security=True"
    xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>




    Based on the standard logic of XPath traversing XDT will always pick up the first “add” node i.e. one with 1stDB in the example below… That may not be always desirable…  In XDT we could have implemented the logic to do special things for appSettings & connectionStrings but then that would have made XDT specific to web.config instead we implemented Locators which now allows XDT to be general purposes XML transformation engine…  In the above example if we use a Locator called xdt:Locator=”Match(name)” on the 2ndDB then as soon as the XDT engine encouters a locator it calls the class implementing it (i.e. “Match” and allows it to play with the XPath that is being generated… In this case the match locator will help construct the XPath as /configuration/connectionString/add[@name=’2ndDB’]



    xdt:locator



    The high level takeaway here is that when you play around with the snippets for XDT keep the above concepts for Transforms & Locators in mind and with the quick snippet explanations of each transforms and locators you should be able to very easily use all of them… If you encounter any issues plz feel free to reach out…



    Thanks!!



    -Vishal



    Friday, April 16, 2010

    Web Deployment Projects Released to Beta (WDP for VS 2010)

     

    Our team recently released WDP for VS 2010… The key features to note for WDP for VS 2010 are:

    1. All the core features of WDP 2008
    2. Migration from WDP 2008 to WDP 201o
    3. Multi-Targeting support in WDP 2010
    4. Support Web Deploy Packages in the WDP project..

    You can read more about the above features on our team blog at Visual Web Developer Team Blog

    Download WDP 2010 Beta by clicking here!!

    The guidance around using WDP 2010 is

    • Use it if you want to migrate to VS 2010 and are currently using WDP for VS 2008
    • Use it for TeamBuild/MSBuild based deployment of Web Site Projects in VS 2010…
    • Use them for Web Application Projects (WAPs) if you feel it is extremely important for you to pre-compile/merge your projects… If not then you can use Web Deployment features built into VS 2010

    Hope this helps!!

    -Vishal

    Thursday, April 15, 2010

    Web Deployment Demos, Slides & Videos for VS 2010 launch

    I have been dormant for ever, have been keeping busy on a very exciting project… Anyways April 12th 2010 was a big day with VS 2010 formally launching…  Few days back I asked Twitter whether people needed a ready made talk to talk about VS 2010 Web Deployment as part of the community launch events of VS 2010 and got a lot of asks for the content so here it is… 

    Titles & Abstract I would recommend you do not use are below… :-)  The reason I say that is coz VS 2010 & Web Deploy are way more exciting than the way I present here; so get creative and make a fun abstract & title…  The only reason I have them descriptive is so that you know what are the key items to put in there…

    Title: Web Deployment with VS 2010 & Web Deploy

    Abstract: Web deployment is not as easy as it should be; whether you are deploying to a shared hosting environment or to your company’s web servers there are a lot of manual steps involved.  Check out how new VS 2010 and Web Deploy can help you deploy your web along with its dependencies like databases and IIS settings to any environment with just One Click Publish.  Also check out how  you can transport your entire web in a single .zip file and finally hear all about the web.staging.config, web.release.config etc  and the simple transformation syntax in them to create web.config per deployment configuration… Finally also learn how you can automate your Web Deployments using Team build so you no more have to worry about daily builds and setting up of environments…

    Video:  Check out the video at http://microsoftpdc.com/Sessions/FT56, this should prep you up on what are the talking points…

    Demos & Slides: You can download it from my SkyDrive

    If you have any questions/thoughts on the content you can feel free to write comments here or reach me at @VishalRJoshi 

    Hope this helps!!

    -Vishal

    Saturday, October 31, 2009

    VS 2010 Beta 2 Read Me Items for Web Deployment

    There are some known issues/bugs related to VS 2010 Web Deployment features in VS 2010 Beta 2 Read Me… I can imagine reading the entire Beta 2 read me file can be daunting so I thought I can just copy paste the ones related to Web Deployment here…

    DB Deployment will fail if the Database Name is longer than 127 characters

    Description: If you are using latest VS 2010 Web Deployment Features and trying to deploy your database using the Deploy SQL property page then at times you might get error from VSMsDeploy task. 

    There might be several reasons for the failure including connection and authentication issue but a current bug in the product does not allow you to script schema/data from a database (typically SQL Express MDF file) if the file path is longer than 127 characters.  In the OS like XP or Win2K3 the default path for the VS project & its default ASP.NET Login/Profile DB could be something like C:\Documents and Setting\... \Visual Studio 2010\Projects\MyProject\App_Data\ASPnet_DB.mdf... This path can potentially exceed 127 characters and result into Deployment failure...

    Workaround: The easy work around is to have the project copied to a location where the path will not exceed 127 characters for e.g. C:\MyProject\App_Data...  This issue will eventually be resolved in the product...

    Some VS 2010 Web Deployment Features will not work if VS 2010 is installed on Vista RTM instead of Vista SP1

    Description:  If you are using the new Web Deployment feature set in VS 2010 and are using the below features which integrate with MSDeploy:

    then you will have to use Vista SP1 instead of Vista RTM as your OS.

    Workaround: MsDeploy requires features which are built inside Vista SP1 and hence trying to run Web Deployment features on Vista RTM fails.  This is a required dependency so you will have to use Vista SP1 as your OS for VS 2010.  Do note that you can still use any other operating system like XP, Win2K3, Win2k8 R2, Win7 etc to install VS 2010 and use the Web Deployment features, it is just advised that any of the OS versions that you use are updated with the latest Service Packs so that all the required dependencies are in place.

    MsDeploy.exe.config file will be required to run Web Deployment on machines with .NET 4.0 only

    Description: If you installed VS 2010 on a clean machine which does not have .NET 2.0 (e.g Win2K3)  and are trying to use the VS 2010 Web Deployment Features then when you run the deploy.cmd file to install your web package you might receive error stating "Msdeploy.exe -.NET Framework Initialization Error Unable to find a version of the runtime to run this application."  This is due to the fact that VS 2010 comes with only .NET 4/CLR4 and and CLR 4 does not allow CLR 2.0 executables to run  without having an explict exe.config file…  If you are using other .NET 2.0/3.0 or 3.5 exes on a box with just .NET 4 then you might face similar issues with those EXEs too…

    Workaround: You can easily work around this by going to "%Program Files%\IIS\Microsoft Web Deploy" (& additionally also on "%Program Files (x86)%\IIS\Microsoft Web Deploy" folders and create following msdeploy.exe.config file in there

    <configuration>
    <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime version="v2.0.50727" />
    <supportedRuntime version="v4.0" />
    </startup>
    </configuration>






    This issue will be fixed in the future releases of the product.



    -Vishal

    Wednesday, October 21, 2009

    How to ensure placeholder folders are created during VS 2010 Web Deployment

    During many web deployment scenarios developers want to be able create place holder folders where eventually their log files or runtime generated files like XMLs, Images etc will be stored…

    With VS 2010 Web Deployment there will be a small work around required for you to be able to deploy place holder folders…  Before I go about explaining the work around let me call out that if you do not know about VS 2010 Web Deployment features it might be worth while to check out the blog series about VS 2010 Web Deployment at Overview Post for VS 2010 Web Deployment

    Anyways, as VS 2010 Web Deployment is completely based on MSBuild based Web Publishing Pipeline (WPP) lot of deployment depends upon the MSBuild constructs…  One of the key features which is also supported using MSBuild based constructs is the ability to exclude Files and Folders from deployment.  I am hoping to write blog posts on both of these topics at some point but currently without going into the details consider following:

    There is a file/folder structure like C:\MyWeb\Foo\Bar\myfile.htm…  VS 2010 will allow you to exclude or include myfile.htm or folder “Foo” from Web Deployment… If you now chooses to include myfile.htm but chooses to exclude “Foo” folder then the WPP will get into unwanted complex state for potentially trivial gains…

    That is the reason most of the include, exclude, delete etc operations are done at the File level rather than at Folder level… So when you are excluding a folder from deployment  behind the scenes a bunch of files under that folder are getting excluded and the end result is the folder being excluded too… The above explanation is not exactly how it translates into code but is more for understanding purposes…

    Anyways, this design decision causes the side effect that if there are no files in a folder then the folder does not get deployed as well… By now I imagine you must have figured out the work around too :-) Ya! just put a place holder file even if it is empty.txt in your place holder folder and it will get deployed too !!

    If this causes you a lot of grief then do write back with your scenarios so that we can try to understand and analyze them individually…

    Also do note that whether you are creating a web package or doing 1-Click Publish the same rationale applies as ultimately same WPP is executed behind the scenes for both…

    -Vishal

    Thursday, October 08, 2009

    Live Meeting: Simplifying Deployment With the Web Deployment Tool (MSDeploy)

    One of our MVPs Sayed Ibrahim Hashimi is doing a Live Meeting  MVP TV talk on : Simplifying Deployment With the Web Deployment Tool (MSDeploy)

    You are invited to join the talk which is scheduled for

    Wednesday, October 14th, 2009 | 4:00pm – 5:00pm (PDT, Redmond time)

    Abstract

    Deploying ASP.NET Websites has always been a challenge and different teams have used different approaches to overcoming those challenges. Microsoft has offered some support for making deployment easier in the past. For instance they first introduced Web Deployment Projects for Visual Studio 2005, and also have a version for 2008. Web Deployment Projects do greatly simplify the process of calling the aspnet_compiler and aspnet_merge tool but even though their title states “Deployment” they had no support for physically deploying the site. Now Microsoft has introduced the Web Deployment Tool, also known as MSDeploy. MSDeploy will bridge the gap between taking a web site and physically deploying it to its destination. With MSDeploy you can easily and very effectively perform tasks such as pushing an ASP.NET site (Web site, Web Application Project, ASP.NET, etc) from one machine to several other machines. This is achieved by the target machines having the MSDeploy Remote Agent Service installed and running. You can sync two different Web Sites that are hosted in IIS, you can create a web package (simply a .zip file) and use that as your source, you can sync two different folders, and many other options. Another compelling feature of MSDeploy is that it will be integrated into Visual Studio 2010. From Visual Studio 2010 you can compile your ASP.NET Web Application Project and then create the Web Package which contains all your content files plus IIS settings. This one file will full describe your web.

    Live Meeting Information

    Join the meeting.
    Audio Information
    Computer Audio
    To use computer audio, you need speakers and microphone, or a headset.
    Telephone conferencing
    Use the information below to connect:
    Toll-free: +1 (866) 500-6738
    Toll: +1 (203) 480-8000
    Participant code: 5460396

    Please join 10 minutes prior to the start time.

    First Time Users:
    To save time before the meeting, check your system to make sure it is ready to use Microsoft Office Live Meeting.
    Notes

    Troubleshooting
    Unable to join the meeting? Follow these steps:

    1. Copy this address and paste it into your web browser:
    https://www.livemeeting.com/cc/mvp/join

    2. Copy and paste the required information:
    Meeting ID: PR7D6Z
    Entry Code: A5128ML0Y0D
    Location: https://www.livemeeting.com/cc/mvp

    If you still cannot enter the meeting, contact support

    Note

    Microsoft Office Live Meeting can be used to record meetings. By participating in this meeting, you agree that your communications may be monitored or recorded at any time during the meeting.

    Hope this helps!!

    -Vishal

    Friday, August 28, 2009

    All for that small Drop Down Box – Part 3

    I wrote couple of posts describing how Web MultiTargeting (Web MT) works in VS 2010… You can find those posts at:

    Today  I hope to cover few other things related to MultiTargeting that the team focused on during VS 2010 and ASP.NET 4 cycle…

    Silverlight MultiTargeting

    VS 2010 will allow you to develop Silverlight (SL) projects seamlessly…  SL has got its own runtime versions like SL 2.0/3.0 and eventually there will be SL 4.0 too…  SL development has been possible with VS 2008 where you might have your Web Projects using SL 2.0 or 3.0 and now when VS 2010 comes out is is obvious that developers will expect smooth migration and upgrade for their VS 2008 SL projects into VS 2010…

    So in VS 2010 there will be functionality available to upgrade your SL projects to SL 3.0… As SL has different versions it becomes important for VS 2010 to support MultiTargeting between different SL versions… Do note that these version are completely independent of .NET FX versions…

    We have talked about Web Projects supporting .NET 2.0/3.0/3.5 as well as .NET 4… In addition to this it is now important for each of these Web Project to support different versions of SL… Thus when you create a new SL project there will be a drop down in the new project creation wizard which allows you to choose what version of SL do you want to target as shown below:

    Silverlight New Project

    On selecting Silverlight Application when you click “OK” then the below wizard will show up which will allow you to target the available Silverlight versions in your project…

    Silverlight MT

    SL MT also uses the Reference assemblies infrastructure that we discussed during Part –1 of this post…  You can find that SL also has its own set of “Reference Assemblies” as shown below:

    SL Reference Assemblies

    This actually brings up an interesting point to note that Reference Assemblies infrastructure is pretty extensible and can be used for Frameworks which are technically outside of .NET Framework too…

    ASP.NET MVC

    As you know ASP.NET MVC 1.0 was released on top of VS 2008… Then eventually the support for VS 2010 was also provided…  VS 2010 will fully support ASP.NET MVC just like it supports Web Application Projects or Web Site Projects… There will be upgrade options available from VS 2008 MVC projects to VS 2010 MVC Projects… 

    MVC projects can MultiTarget based on project references i.e. if you have reference to MVC 1.0 your intellisense will work for 1.0 and if you have reference to MVC 2.0 your intellisense will work for 2.0…  If your hoster does not support ASP.NET MVC just yet you can just select the reference to MVC assemblies and in the properties mark “CopyLocal” to True which will copy the MVC assemblies into your BIN which you can just simply deploy to the server along with your project (as shown below)…

    CopyLocal

    Multiple Frameworks in same Solution

    If you have read Web MultiTargeting posts (Part 1Part 2) you already know by now that there is a lot happening with respect to toolbox filtering, property grid filtering, context sensitive markup intellisense, JavaScript intellisense, C#/VB intellisense,  IIS App Pool management, web.config etc… 

    If someone has a big solution with several web projects, few class libraries, few web services etc, it is very likely that they will not update all of their project at the same time to .NET 4… So VS 2010 needs to make sure that things don’t break even if there were multiple projects in a single solution and all of them were targeting different .NET Framework Versions (with few Silverlight projects with multiple versions into the mix :-)) …

    There were various stress scenarios which were tested and optimized for in this area… In fact we have something called as “Overall Goodness Factor (OGF)”… OGF is a subjective adhoc test which needs to be performed on a regular basis by various people across the the team to understand how the product is behaving…  As most of the folks in our teams are developers (even if their title don’t say so :-)) they do reasonable job in playing around with various real world projects… This particular OGF covering stress scenario was always hard to execute, coz every time we had to set up this complex project structure from ground up and play around with it to make sure VS 2010 is actually performing correctly… Btw, the OGF report is sent out pretty broadly across the division for features like MT so if  any team’s OGF was not “Good” it use to become the the center of everyone’s attraction across the division (not in a good way :-))… In short there was enough motivation provided to get things right!!

    Making sure all Web Stack Features Work

    As Web MT operates relatively in the lower layers of VS 2010 and ASP.NET 4 stack a small issue in MT surfaces as a big issue somewhere else… Although this is very much assumed and expected but the MT team had to specifically write Automation tests to ensure other features within the products like Dynamic Data, AJAX, Web Deployment, Build/Compilation, Debugging, WCF, Web Services etc etc continues to perform while targeting any .NET Framework version…

    Most of the time we did not face a lot of issue in this area, but nevertheless something which is worth mentioning…:-)

    Target Framework Moniker & Profiles

    As we talked about earlier “Reference Assemblies” which are laid down on the disk at %Program Files%\Reference Assemblies folder are meta data only assemblies… By default there are Reference Assemblies folders created for Silverlight versions and .NET Framework versions (e.g. 2.0, 3.0. 3.5 & 4)… VS 2010 architecture runs using a concept called as “Target Framework Moniker” which describes where reference assemblies should be picked from the disk…  The target framework Moniker looks something like below:

    ".NETFramework,Version=v4.0,Profile=ServerCore"

    • Target Framework Identifier (“.NETFramework” in above example)
    • Target Framework Version (“Version=v4.0” in above example)
    • Profile Name (“ServerCore” in above example)

    Based of this information VS 2010 will pick up “Reference Assemblies” which in turn will allow VS 2010 to control the behavior across the board in the IDE (i.e. on toolbox filtering, intellisense, property grid filtering etc etc)…

    When Profile Name in the target framework Moniker is present then VS 2010 looks under the framework for the presence of the Profile definition (Think of “MT Profile” as a SUBSET of the full .NET framework)

    Profile Folder

    When Profile Name in target framework Moniker is missing then the full frameworks are picked up… i.e. “.NETFramework,Version=v4.0” will pick up reference assemblies for the full .NET 4 Framework… 

    Profiles are interesting coz in the future there might be platforms and servers which do not need full .NET Framework but only subset of it… VS 2010 can ensure that projects developed using a specific Profile will not land up accidentally consuming the larger surface area of .NET framework which might be absent on the destination… Eventually Mobile development can have its own profile and so can Windows Client development have its own… Anyways, the key point is that “Profiles” are a reusable way to provide MultiTargeting support with Visual Studio and will be expressed via the “target framework moniker”…

    You might be wondering where is this target Framework Moniker physically visible… Well the answer is complicated but what is important to note is that starting .NET 4 ASP.NET web.config  schema will support a special attribute called targetFramework=”4.0” as shown below:

    TargetFrameworkMoniker

    Following things are worth noting about this attribute:

    • The attribute resides on the compilation node of the system.web attribute of the web.config…
    • This attribute was introduced in ASP.NET 4 and it is not supported for .NET 2.0/3.0/3.5 webs (as they shipped before the concept of Reference Assemblies and Profiles was introduced)… i.e. do not try to code something like “targetFramework=v3.5” in VS 2010  it will not work :-)
    • “targetFramework” attribute is just a short form of “targetFrameworkMoniker”…
    • “targetFrameworkMoniker” was the attribute which was earlier used in VS 2010 Beta1 but in final VS 2010 release it will be renamed to “targetFramework”…
    • targetFramework=”4.0” is same as targetFramework=.NETFramework,Version=v4.0”
    • If there was a profile then that could be added to targetFramework too e.g. targetFramework=”.NETFramework,Version=v4.0,Profile=ServerCore" (btw, Profile=ServerCore" is just a made up name by me, it does not exist :-))
    • Post VS 2010 Beta1, targetFramework will not be a required attribute at runtime for ASP.NET 4… But, it is required for VS 2010 to support correct MT behavior within IDE so I strongly encourage you to not delete that attribute from your web.config file… Its, just a little attribute it means no harm :-)
    • As targetFramework attribute is optional at runtime, if it was missing from web.config and the web was deployed under .NET 2.0 App Pool in IIS then ASP.NET will assume the web to be 2.0 Web… If the web was deployed on .NET 4.0 App Pool in IIS then ASP.NET will assume that the web is .NET 4 web… 
    • targetFrameworkMoniker, which was  the VS 2010 Beta1  equivalent of targetFramework attribute was a required attribute  i.e. if that was absent you would get an error as below:

    “The application domain or application pool is currently running version 4.0 or later of the .NET Framework. This can occur if IIS settings have been set to 4.0 or later for this Web application, or if you are using version 4.0 or later of the ASP.NET Web Development Server. The <compilation> element in the Web.config file for this Web application does not contain the required 'targetFrameworkMoniker' attribute for this version of the .NET Framework (for example, '<compilation targetFrameworkMoniker=".NETFramework,Version=v4.0">'). Update the Web.config file with this attribute, or configure the Web application to use a different version of the .NET Framework.”

    The solution for the above error in VS 2010 BETA 1 is to add below attribute under compilation node of the web.config file

    targetFrameworkMoniker=.NETFramework,Version=v4.0”

    Anyways, I guess now you know a lot more about a single attribute within web.config than you would ideally like to, so let’s move on :-)

    Retargeting between Framework Versions

    I intentionally kept this piece towards the end coz now you know a whole gamut of things that happen around Web MT within Visual Studio for a single project… The nice part is that VS 2010 will allow you to simply go to your project properties and use that retargeting drop down box shown below to flip your Framework version between 2.0, 3.0, 3.5, 4 or any of the Profiles that might be installed on your box… And as soon as you retarget IDE will frantically start doing a bunch of things behind the scenes and within no time will reload your project and get you all set on new Framework of your choice…

    image

    If you choose to down target your project from say .NET 4 to .NET  3.5 you will get a bunch of errors when you build, the primary reason for that is that VS 2010 cannot simply wipe out source code from your code files, it does not really know what code you wrote and tweaked painstakingly and suddenly loosing it all might be scary… But anyways, the chances of people moving from .NET 4 to 3.5 are very few so most people do not ever experience the errors… Even if you see retargeting errors most of the time the solution is all about deleting some new 4.0 specific code which is pretty easy to do…

    Anyways, in the image above you will also see a tons of extra frameworks, we have not yet made progress beyond 4.0, so most of them are not real… :-) They are all the test profiles and frameworks that MT team created painstakingly to make sure MT really works in whatever difficult situation we will throw at it…  So, when VS 2010 ships all the test frameworks will be gone and all you will see are few Frameworks is that small Drop Down Box…. :-)

    -Vishal

    The remaining posts in the Web MultiTargeting Series are: