Wednesday, March 18, 2009

Code Snippet plugin for Windows Live Writer v2.0.0

It's been a while since I looked at this plugin, just as it's been a while since I blogged (but that's another story). I have spent the last day or two implementing most of the features listed below in the current code base. This release is fully functional and I am looking for some of you folks to help me determine its stability in other environments.

Here's a list of what is included in this release:

Screenshots

Please take a look at some of the screenshots I posted in Code Snippet plugin for Windows Live Writer section of the the Plugin Collection for Windows Live Writer project at CodePlex.

New Languages

The following formats have been added to the list of supported languages:
  • AutoIt (never heard of it, saw someone looking for such support elsewhere and decided to add it, why not!)
  • ColdFusion
  • Java
  • PHP
  • Regular Expression

New Options Dialog

One of the things I wanted to do for a long time was expose some of the configuration parameters for the plugin. In previous versions, some of these configuration parameters were available in the configuration file. But now, you can edit them through a dialog and more of the options have been exposed.

New Features

Customize Styles
In previous releases the styles used to apply the syntax highlighting were exposed in a very limited fashion. You could only get the cascading style sheet to include as a reference in your website. However, this works great only if your audience is viewing your posts in your website. If you want to make sure your RSS feeds, for example, have the proper formatting, you need to embed the styles.
Now, you can change the look of your code snippets by modifying these styles through the Options dialog. The changes are stored in the configuration file and will be used to apply to any future code snippets you insert in your posts.
Edit Code Snippets
In the original implementation, I did not want to use the in-place editing features of the Windows Live Writer API. So, I opted for a different implementation where you can highlight existing snippets of code, whether or not these were inserted using this plugin. Basically, any highlighted text can be converted to a code snippet. This is a great feature, if I may say so myself, for re-applying style changes, if you previously embedded the styles in your post.
Convert Any Text to a Code Snippet
Using the same feature for editing snippets of code, you can now select any text in your post and convert it to a code snippet.

Miscellaneous Enhancements

Here's a list of additional enhancements to the plugin. These enhancements are not visible to the end user but in my opinion make the package more robust and complete.
  • Refactored style logic to allow exposure through Options dialog.
  • Migrated solution to Visual Studio 2008 SP1.
  • Verified / Updated all source code documentation for completeness and to ensure it is as accurate as possible.
  • Localized all string resources, including those used in the Options dialog using some custom classes, such as Attribute classes, for use in the PropertyGrid control. (Anyone interested in translating these resources?)
  • Added stand-alone application to launch the Code Snippet plugin outside of the context of the Windows Live Writer editor. This is helpful for debugging, or when you just want to get some formatted HTML to post in a forum or something. (This is not pat of the deployment - let me know if you think it should be.)
  • Analyzed the source code through the Code Analysis feature of Visual Studio 2008.
  • Fixed the source code based on ReSharper 4.1 and Code Analysis recommendations.

Please refer to my original post for details on some of the other features the plugin offers.

Read full post...

Sunday, July 15, 2007

Making Web Setup projects run on Windows Vista

Windows Vista offers many enhancements over previous operating systems. Unfortunately for us developers it also presents some challenges. One such challenge is making a Web Setup project run on Windows Vista. This post shows step-by-step how to make it work.

Windows Vista comes pre-configured with IIS 7. Unfortunately, Web Setup projects do not recognize IIS 7 and therefore will fail when you attempt to run it on Windows Vista. In my case, the failure is presented as shown in the following figure.

Doing a lot of searching in Google presented me with nothing really obvious. As you can see from the figure above, the error message is not really helpful. Luckily, while searching for something else, I stumbled onto a MSDN article titled Troubleshooting Windows Installer Deployment. In the article I found the section Web Setup deployment projects in Visual Studio 2005 on Windows Vista, as a new section for Visual Studio 2005 SP1. The section says

When you create a Web Setup deployment project in Visual Studio 2005 on Windows Vista, you need to turn on the Windows feature IIS Metabase and IIS 6 configuration compatibility, and you need to be logged on as an Administrator; otherwise you will be unable to run setup.exe to install the project.

In order to turn on the Windows feature you can follow these steps:

1. Launch Control Panel and select Programs. This will display the Programs options.

2. In the Programs options select Turn Windows features on or off. This will display the Windows Features dialog.

3. In the Windows Features dialog expand the branch as shown in the following figure to finally select IIS Metabase and IIS 6 configuration compatibility. Select OK to install the feature.

Let Windows complete the installation. Once complete you will be able to run your Web Setup project on Windows Vista.

Read full post...

Thursday, May 31, 2007

Automatically launch a silent remote MSI installation from Team Build

If you need to maintain an up-to-date test machine with the latest installation of the product you are testing, this post shows you how you can trigger the automatic installation of the latest components as a result of a successful build.

The logic has been tested using Team Build. However, since the underlying technology is MSBuild, the information described here does not require Team Build.

Prerequisites

MSBuild, and therefore Team Build, is unable to natively build Setup projects. In order to build a Setup project from within a Build Type you need to use the Visual Studio environment via the command line. This implies you will need to have access to Visual Studio. Preferably, the Visual Studio environment should be installed on the Build Machine.

In addition, because the Build Machine will be triggering the execution of the installation remotely, the user account under which the build process executes should have remote, administrative access to the Test Machine on which the installation will occur. Alternatively, you may use another user credentials to execute the installation but this means that these credentials will need to be part of the command that will launch the remote process, and therefore part of the Build Type project file.

Required Tools

Devenv - Executable used to launch Visual Studio. It can be used to build Setup projects from the command line, amongst other things. For details on all command line switches for Devenv refer to the MSDN online documentation. For details on building Setup projects using Team Build, please refer to the article Walkthrough: Configuring Team Foundation Build to Build a Visual Studio Setup Project.

PsExec - Allows execution of processes on other systems. PsExec is part of the Windows Sysinternals download and it is hosted at Microsoft TechNet.

Msiexec - The resulting MSI from a Setup project is not an executable. In order to perform actions outside of its default association, you require the use of a tool called Msiexec. This tool provides the means to install, modify, and perform operations on Windows Installer from the command line. Silent execution of these Windows Installer files can be accomplished through Msiexec.

Combining the Tools

In order to build a Setup project you need to use an Exec task in the AfterCompile target, as the following code snippet shows.

<Target Name="AfterCompile">
  ...
  <Exec Command="$(DevEnv) &quot;$(SolutionRoot)\Setup\Setup.vdproj&quot; /Build &quot;Release|Any CPU&quot;"/>
  ...
</Target>

Once you have access to the resulting MSI file, you can use the following command to execute a remote installation. Note that you will need to replace the information such as Server Name (MyServerName in the example below) and paths with yours.

<Target Name="AfterCompile">
  ...
  <Copy SourceFiles="$(SolutionRoot)\Setup\Release\Setup.msi" DestinationFolder="\\MyServerName\C$\Temp\Setup" />
  <Exec Command="$(PsExec) \\MyServerName -w &quot;C:\Temp\Setup&quot; msiexec /i &quot;C:\Temp\Setup\Setup.msi&quot; -quiet"/>
  ...
</Target>

Note: There have been cases where PsExec causes MSBuild to hang in the middle of a remote installation. I have yet to figure out why this may happen. If you run into this scenario and are able to fix it please share your experiences.

Alternate Scenario

There are times when you may want to trigger the installation on a remote machine from within your Visual Studio environment. For example, I do this often when I perform integration testing of MSBuild custom tasks, where I need to install the custom task in the Build Machine. Rather than doing it manually, I make it part of the Setup project's Post-build event.

I use the following script to automate the installation of my setups. In order for you to use the script, add it to your own Setup project's Post-build event and replace all the lines in bold with your own information.

echo ======================================================================
echo POSTBUILDSTEP for setup project.
 
set ServerName=YOUR_SERVER_NAME
set ServerPath=\\%ServerName%
set RemoteDrive=C
set MsiPath=Temp\YourProjectName
set MsiName=YourProjectNameSetup.msi
set RemoteMsiFilePath=%RemoteDrive%:\%MsiPath%
set RemoteMsiFileName=%RemoteMsiFilePath%\%MsiName%
set UncMsiFilePath=%ServerPath%\%RemoteDrive%$\%MsiPath%
 
echo Verifying/Creating temporary folder at "%UncMsiFilePath%"
if not exist "%UncMsiFilePath%" mkdir "%UncMsiFilePath%"
if errorlevel 1 goto BuildEventFailed
 
echo Uninstalling "%RemoteMsiFileName%" from server %ServerName%
psexec %ServerPath% -w "%RemoteMsiFilePath%" msiexec /uninstall "%RemoteMsiFileName%" -quiet
if errorlevel 1619 goto BuildEventContinue
if errorlevel 1606 goto BuildEventFailed
if errorlevel 1605 goto BuildEventContinue
if errorlevel 1 goto BuildEventFailed
 
:BuildEventContinue
echo Copying "$(BuiltOuputPath)" to "%UncMsiFilePath%"
xcopy /Y /R "$(BuiltOuputPath)" "%UncMsiFilePath%"
if errorlevel 1 goto BuildEventFailed
 
echo Installing "%RemoteMsiFileName%" on server %ServerName%
psexec "%ServerPath%" -w "%RemoteMsiFilePath%" msiexec /i "%RemoteMsiFileName%" -quiet
if errorlevel 1 goto BuildEventFailed
goto BuildEventOK
 
:BuildEventFailed
echo POSTBUILDSTEP for setup project FAILED
exit 1
 
:BuildEventOK
echo POSTBUILDSTEP for setup project COMPLETED OK
echo ======================================================================
echo.

With the script in place, whenever I build the Setup project the script will uninstall any previous version and re-install the new version of my custom task. This technique can be applied to pretty much any type of Setup project.

Read full post...

Wednesday, May 30, 2007

VSTS Database Professional using Remote SQL Server

My local SQL Server 2005 installation was damaged and I needed to be able to continue work on a project that makes use of the Visual Studio 2005 Team Edition for Database Professionals (VSTS DB Pro). The problem is that VSTS DB Pro requires a local SQL Server 2005 Developer Edition instance and above for it to work. So how does one make use of a remote SQL Server instance?

Perhaps there's another way to make it work with a remote SQL Server instance, but it appears that the current version of VSTS DB Pro does not natively support such configuration.

Luckily I found a MSDN Forum Post where Thomas Waldron suggests the use of a tool called TcpTrace to redirect the local 1433 port to that of a remote SQL Server instance. It works like a charm! I can now load my database projects.

Read full post...

Wednesday, March 28, 2007

Digg This plugin for Windows Live Writer

Update (08/01/07): Source code now available on CodePlex.

Digg This plugin for Windows Live Writer is a plugin to insert a "Digg This" button into to your Windows Live Writer posts. It is a wrapper to the API described in the Integrate: "Digg This" Button page at Digg.

Digg This Sidebar Editor

If you already use Digg, you will surely know how to use this plugin. The functionality is designed to closely match the online submission form. The Sidebar editor is broken into two tabs: General and Appearance.

The General tab contains the information used as defaults for the submission to Digg. The Appearance tab contains properties that allow you to modify the way the Digg This button will look when published.

The simplest way to use this plugin is to specify a post title, specify at least one paragraph of text that will describe briefly the post, place the cursor wherever you would like to insert the Digg This button and click on the Insert Digg This... option in the Sidebar. You will notice that the post title is used for the submission title and the first paragraph is used for the submission text. The first time one of your readers clicks on the button once the post is published, they will be sent to the Digg site to submit the post to Digg. The defaults you specified will appear for the user to either use as is, or modify accordingly.

Some of the features of the Digg This plugin are:

Auto-selection of Title & Text – The Digg This button has the ability to accept recommendations or defaults as part of the submission link. These parameters are used to pre-populate the respective fields when a user submits an entry. Instead of having the submitter type their own text, which they can still do during submission time, the Digg This plugin will take the post’s title and the first paragraph in the post body and use these as the suggested Title and Text properties in the Windows Live Writer Sidebar, respectively.

Submission Character Count – Just like the online submission form on Digg for the Title and Text fields, the number of remaining characters available will appear in the status bar of the Windows Live Writer Sidebar.

Visual Layout of Digg This Button – Using the Appearance features present in the Windows Live Writer Sidebar when the object is selected, you can modify the Layout, Text Wrapping, and Margin properties and see them apply immediately.

Tooltip Help – All fields have an associated tool tip that provides more details about the specific use of that field.

Persistent Options – Changes to the Digg This properties can be used as defaults. These include layout and submission properties, accept for Title and Text, which get overwritten whenever a new instance of the Digg This button is inserted in a post.

Download Digg This plugin for Windows Live Writer Setup

Read full post...