Labels

Showing posts with label ScottG - VS2005. Show all posts
Showing posts with label ScottG - VS2005. Show all posts

Friday, April 4, 2008

Creating Re-Usable Project and Item Templates with VS 2005

Hi,

This blog post summarizes how we can fasten the WSP creation by creating & using Templates. The templates can of two types viz. Project Templates & Item Templates.

For using the templates, required is to create them and save them at ‘C:\Documents and Settings\Arunm.XP\My Documents\Visual Studio 2008\My Exported Templates\<Template Name>.zip.

The templates allows you to capture your personal coding preferences and default project items and encapsulate them in re-usable templates that you can quickly use when starting a new project or adding a new item to it. This can both save you a lot of manual time, as well as ensure on new projects that everything is setup exactly the way you like them.

Project Templates:

· Listed in the "My Templates" section of your "Create New Project" or "Create New WebSite" dialog box.

· Allow you to specify the initial set of files (and their layout and content), assembly references, and other preferences when you create a new project.

Item Templates:

· Listed in the "My Templates" section of your "Add New Item" dialog box.

· Allow you to create a customized template that you add new files to a project.

Features:

· You can name each Project and Item template using a descriptive name, and have any number of them that you want in VS 2005.

· You can also use ‘Built-In Macro Replacement Tokens’ to customize things like names, namespaces, paths, date/times, etc.

· You can also easily publish them and share them with others -- allowing you to easily distribute them across a team or your own community of friends.

Steps to Create Project Template:

In breif creating project template is very simple. Follow step as below.

· As normal process, create a website.

· Add contents into it. Add those contents which you want to add in all the projects. For E.g Images, XML, CSS folders, BasePage etc.

· Save it.

· Choose File – Export Template. This will open below dialog.












· Select Project Template. Click Next.

· This will open one more dialog where you can specify default icon, output location and few more. Then click Finish.

Once saved these project templates will be listed in the "My Templates" section of your "Create New Project" or "Create New WebSite" dialog box.

Steps to Create Item Template:

In breif creating Item template is same as project template. The only difference is - Item template is created for one item at a time.

· As normal process, create a website.

· Add contents into it. Add a single or multiple contents which you want to add in all the projects. For E.g Base Page, Defualt.aspx, Resx file.

· Save it.

· Choose File – Export Template. This will open same dialog as above. Select Item Template. Click Next.

· This will open one below dialog and will show one or multiple items depending on whehter you want to add single or multiple Items.

· But there is a catch here. As said above the checkboxes below are mutulally exclusive, i.e you can choose only one item to add.











· Select Item and Click Next. This will open one more dialog where you can add references. Skip it and click next.

· This will open one more dialog where you can specify default icon, output location and few more. Then click Finish.

Once saved these Item templates will be listed in the "My Templates" section of your of your "Add New Item" dialog box.

Hope this helps.

Thanks & Regards,

Arun Manglick Tech Lead +91 20 30230500 Ext: 620 +91 9850901262

Thursday, April 3, 2008

Custom formatting HTML in VS 2005

Hi,

This blog post summarizes how we can customize the indentation, line breaks etc of HTML content using below menus.

Best would be to access the Scott’s Link.

We can do two things here:

· Format the HTML

· Define the Formating Rules.

Format the HTML:

· Either access it using the Edit – Advanced menu

· Or as below.










Formating Rules:

Once make the selection and right click and choose ‘Formatting & Validation’ as below.










This will launch below dialog:









Using the dialog below things can be controlled:

· Default capitalization and casing rules,

· Attribute quoting.

· Self-terminating semantics of elements.

· When elements wrap to a new line within the page:

You can also click the “Tag Specific Options” button to bring up a dialog that enables further element customization.









Again I recommened, if you need more details, best would be to access the Scott’s Link.

Hope this helps.

Thanks & Regards,

Arun Manglick || Tech Lead || +91 20 30230500 Ext: 620 | +91 9850901262

Fast HTML Editor Navigation within VS 2005

Hi,

This blog post summarizes how VS 2005 automatically & quickly navigate back and forth between design-view and source-view without getting lost in the deeply nested HTML content, or without spending a lot of time.

Best would be to access the Scott’s Link.

We can do two things here:

· Source View to HTML View – Select some item in source view and switch to HTML view, you’ll find the content is selected in HTML view.

· HTML View to Source View - Select some item in HTM view and switch to source view, you’ll find the content is selected and also the property window is open and displaying the selected items properties.

· Tag Navigator control



1. Available in both design-view and source-view.

2. This lists the element hierarchy from the current location of the cursor up to the root <html> element in the document. I.e. displays the hierarchy of parent elements.

3. The current location is show in the last square on this tab.

4. Enables to quickly navigate/select any of the parent elements.

Hope this helps.

Thanks & Regards,

Arun Manglick || Tech Lead || +91 20 30230500 Ext: 620 | +91 9850901262

Creating Sub-Web Projects using the VS 2005 WAP option

Hi,

This blog post summarizes how to split up/partition an ASP.NET web application into multiple projects within Visual Studio. The goal with doing this is typically to improve the modularity of large sites and/or to improve the IDE compile-time performance for large projects.

Scott G says - I wouldn't necessarily recommend this (See last part of the post) for performance reasons (unless there are thousands and thousands of pages it probably doesn't make a huge difference), but it can sometimes make it easier to help manage a large project.

The split feature is only supported in WAP option and not in WSP. Hence I suggest to go thru the links below.

n Creating Sub-Projects in IIS using VS 2005 Web Application Projects - This post describes the basics of how to setup a multi-project solution that builds a single ASP.NET 2.0 application.

n Creating Shared User Controls and Master Pages with Sub Projects - This post describes how to define master-pages and user controls within a root web project, and the use them within sub-projects in the application.

WAP – Web Application Project

WSP – Web Site Project

Hope this helps.

Thanks & Regards,

Arun Manglick || Tech Lead

Tuesday, April 1, 2008

Dueling Assembly References - Slow Build Performance

Hi,

This blog post summarizes what is ‘Dueling Assembly References’ and how it affects build performance in Web Site Project option.

Note: Before we go further, let me make sure that this only affects Web Site Projects and not Web Application Projects.

What is Dueling Assembly References:

In WSP, developers can add references to assemblies in multiple ways. When you right-click on a project and choose the “Add Reference” menu option, it provides a dialog like the one below that allows you to reference below:

· .NET assemblies registered in the GAC – .Net Tab

· Class libraries built as projects in the same VS solution – Projects Tab

· COM components – COM Tab

· File-path based assemblies – Browse Tab











Here we’ll talk about Browse Tab - When we add a file-system based assembly using this tab, Web Sites will do below.

· Copy the assembly picked into the \bin directory of the project.

· (By default) add a .refresh file into the \bin directory - That contains a relative path string that points back to the original assembly path location.

When we build the solution, VS will automatically check those assemblies with .refresh files to see if a newer version of the original assembly is available, and if so automatically re-copy the assembly and re-compile the solution using it. This avoids you having to manually update the assembly yourself every time it changes. However If you don’t want this “automatic refresh” capability, you can delete the .refresh file – in which case VS will not check the timestamp nor update the assembly for you.













Because assemblies often have dependent assembly references, VS will also automatically copy dependent assemblies that a reference assembly requires into the \bin directory of the target web-site as well. For example: if you setup a file-based reference to ClassLibrary1.dll, which in turn uses an assembly called SharedLibrary.dll that resides in the same directory, Visual Studio will make sure both assemblies are copied into the Web Site’s \bin directory (note: if it didn’t do this then the app would fail to run).

Note: No .refresh files been added for dependent assemblies in the bin.

This dependency might give birth to ‘Dueling Assembly References’ probelem – See below:

Assume one Web Site Project contain references to two different assemblies say A.dll abd B.dll where each updated dynamically (using .refresh files). On the dependent hand assume, these two different dlls, in turn have dependencies on some assembly say C.dll.

There will be no dueling problem referenced assembly C.dll is the same version for both assemblies A.dll and B.dll. But it will cause problems if the AssemblyC.dll being used is different between the two.

How it will affect Build performance:

In cases where AssemblyC.dll is different, VS ends up copying the AssemblyC.dll file twice for each build – since it continually thinks that the assembly has been updated (once for each reference). This ends up requiring all references to be recalculated by the compiler, and a full re-build to occur within the IDE. This will cause build performance to slow down dramatically, and will cause builds to appear to pause as VS does this reference recalculation and fix-up on every single build.

How to Fix This Problem

There are a couple of ways to fix this problem:

· The “most correct” way to fix this issue is to make sure your class library references are built against the same version of any dependent assemblies.

This is good to-do not just to fix the above build performance problem, but also because it decreases the likelihood of introducing hard to figure out bugs in your application (at runtime only one version of the shared assembly is going to be used –so if you don’t fix this at least one of your dependent assemblies will end up running against an assembly it wasn’t built/unit-tested with).

· The “easiest quick fix” way to resolve this issue is to modify one or more of your assembly file-based references to not be “automatic refresh enabled”. You can do this by deleting the .refresh files within your \bin directory that produce that shared conflict. We can re-enable the auto-refresh behavior once you fix the shared assembly conflicts.

Why WAP do not have this problem:

Since they don’t use .refresh files for file-assembly references. So you won’t have this build-performance problem with it (instead it will just pick one version of the shared assembly to use). However, you still want to be careful about cases where you have two components built against two separate versions of a shared assembly – since this can still cause hard to understand behavioral bugs at runtime that end up bypassing your carefully written unit-tests (which were run against a different version of the shared assembly).

Hope this helps.

Thanks & Regards,

Arun Manglick || Tech Lead || +91 20 30230500 Ext: 620 | +91 9850901262

Optimizing ASP.NET 2.0 Build Performance

Hi,

VS 2005 supports two project-model options: VS 2005 Web Site Projects and VS 2005 Web Application Projects.

This blog post summarizes how to best optimize the build performance with Visual Studio 2005 when using Web Site Projects/ Web Application Projects.

VS 2005 Web Site Projects [WSP]:

· Built-in with the initial VS 2005 release.

· Provide a project-less based model for doing web development that uses that same dynamic compilation system that ASP.NET 2.0 uses at runtime.

VS 2005 Web Application Projects [WAP]:

· Supported as a separate download.

· Provide a project model that uses a MSBuild based build system that compiles all code in a project into a single assembly.

· It is different than VS2003 in terms - Similar to VS 2003 - but without many of the limitations that VS 2003 web projects had with regard to FrontPage Server Extensions, IIS dependencies, and other issues.

From a feature perspective there is no "one best option" to use - it really depends on your personal preferences and team dynamics. For example: a lot of enterprise developers love the VS 2005 WAP option because it provides a lot more build control and team integration support, while a lot of web developers love the WSP because of its "just hit save" dynamic model and flexibility.

Two articles you might find useful to decide which works best for you is this MSDN whitepaper that includes some comparisons between the two models, and Rick Strahl's Web Application Projects and Web Deployment Projects are Here article that provides a good discussion of the pros/cons of the different options.

Which Project Option Builds Faster?

The answer is – WAP. Assumption – Full Build is considered.

By "full build" I mean cases where every class and page in a project is being compiled and re-built - either because you selected a "Rebuild" option within your "build" menu, or because you modified code within a dependent class library project or in the /app_code directory and then hit "build" or "ctrl-shift-b" to compile the solution.

Few reasons:

· The main reason is that the VS 2005 WAP option only compiles your page's code-behind code and other classes within your project.

· It does not analyze or compile .aspx pages i.e the content/controls/in-line code within your .aspx pages -- which means it does not need to parse those files.

· On the downside this means that during compilation it will not check for errors in those files. On the positive side it makes compilations much faster.

This downside can be fulfilled by adding a VS 2005 Web Deployment project to your solution for deep verification. Required is to configure this to run only when building "release" or "staging" builds of your solution (to avoid taking a build hit at development time), and use it to provide a deep verification of both your content and source code prior to shipping your app.

However there are techniques to improve the build process in WSP and WAP.

Tricks for Optimizing WSP Build Times

· Verify that you are not suffering from an issue I call "Dueling Assembly References".

· Keep the number of files in your /app_code directory small. It happens only when you have lots of directories or dozens of files. In such cases recommend is to add a separate class library project to your VS solution and move these classes within that instead since class library projects compile faster than compiling classes in the /app_code directory.

Note: Keeping less number of files in app_code also reduces the switch time from source to design-view within the VS HTML designer.The designer causes the /app_code directory to be compiled before the designer surface loads. Reason behind this compilation is - you can host controls defined within /app_code in the designer.

· Enable the On-Demand Compilation option for your web-site projects.

What does ‘Build Page’ mean - When you edit a page and then hit F5 (run with debugging) or Ctrl-F5 (run without debugging) the solution will compile as below.

o All of the class library projects like before,

o Then compile the /app_code directory and Global.asax file, and

o Then instead of re-verifying all pages within the web-site it will only verify only the current page you are working on, and any user controls that the page references.

o Then on-Demand - ASP.NET will automatically re-compile any other page or control you access at runtime -- so you will always have an up-to-date and current running application

With large (and even medium) projects with lots of pages, this can obviously lead to major performance wins

However, If you want a way to force a re-build to occur on pages not open, or across all pages within the web-site, you can use the "Build Web Site" menu options within the "Build" menu of Visual Studio.

What does deselecting ‘Build Web site as part of solution’ mean: When you make Ctrl + Shift + B, below happens.

o Compiling all class library projects.

o But will not re-build all pages within your web-site project.

Tricks for Optimizing WAP Build Times

· Watch out for Virus Checkers, Spy-Bots, and Search/Indexing Tools.

VS hits the file-system a lot, and obviously needs to reparse any file within a project that has changed the next time it compiles. Several times are cases where virus scanners, spy-bot detecters, and/or desktop search indexing tools end up monitoring a directory containing a project a little too closely, and continually change the timestamps of these files (they don't alter the contents of the file - but they do change a last touched timestamp that VS also uses). This then causes VS to have to re-build it again. Check for this if this has became a practice and you are seeing build performance issues, and preferably disable such directories from being scanned.

· Turn off AutoToolboxPopulate in the Windows Forms Designer Options - To disable this option, select the Tools->Options menu item, and then unselect the Windows Forms Designer/General/AutoToolboxPopulate checkbox option.

· Examine which 3rd party packages are running in Visual Studio.

There are a lot of great 3rd party VS packages that you can plug into Visual Studio. These deliver big productivity wins, and offer tons of features. Occasionally I've seen issues where performance or stability is being affected by them though.

Thanks & Regards,

Arun Manglick || Tech Lead