Monday, January 12, 2009

Using Powershell script to start and stop web services during development

I have been developing some Web Services under VS2008 and Vista 64.

For some reason whenever I tried to test the services under VS2008 I received the message :

Unable to launch the ASP,NET Development Server because port XXXX is in use.

I decided to start and stop the services manually using Powershell and, if debugging was required to used the "Debug->Attach to Process" facility.

Here is the Powershell command to start an instance of the development server on a specified port:

&"C:\Program Files (x86)\Common Files\microsoft shared\DevServer\9.0\WebDev.WebServer.EXE" /port:1420 /path:"C:\Users\User Name\Documents\Code\Services\Status"

Here is the Powershell command to stop all instances of the development server:


&stop-process -name WebDev.WebServer -confirm



Regards

Andy

Sunday, January 11, 2009

ClickOnce - Manually modifying the Application file list.

I am developing a ClickOnce application which requires assemblies and other resources which are not automatically included in the "Application Files".

You can include files in the "Applciation Files" list by adding them to the project. (i.e In VS rightclick on the ClickOnce project and select Add->Existing Item.

The problem with this is that the files are copies into the Project directory.

A better way to handle this is to use an Xml editor to manually edit the project file (*.csproj).

Refer to blogs.msdn.com/mwade/archive/2008/06/29/how-to-publish-files-which-are-not-in-the-project

Regards

Andy

Install Opera Code Signing Certificates into Vista

I recently purchased a "code signing" certificate from Comodo . Comodo charge about half as much as Thawte who are about half of Verisign.
The certificate transfer process is pretty tricky and the certificate ends up installed in the Certificate store of the browser used to request and transfer it.
YOU MUST USE THE SAME BROWSER TO ORDER AND DOWNLOAD THE CERTIFICATE.
I recommend using Opera 9.6 to order and download certificates.
Because I had difficulties with the ordering and download process Comodo issued a replacement certificate. Unfortunately I then used the first certificate for code signing. Comodo had revoked this certificate and the ClickOnce install dialog indicated "Unknown Publish". However, there was NO indication in the Windows Certificate Manager "CertMrg.msc" that the certifcate had been revoked. This issue was only resolved when Comodo support told me the serial number of working certificate.


To install the certificate in Vista proceed as follows:

First export the certificate from the browser ( In this case Opera 9.63 ).


Tools->Preferences->Advanced Tab.
You should see a "Manage Certificates" button.
Press the button.
The browser certificate manager will be displayed. The downloaded code signing certificates should be shown under the "Personal" tab.

Select the certificate and press the "Export" button on the right side of the form.

A file create dialog is displayed. Give the exported certificate a file name and select to save as type "PKCS #12 (*.p12) This type is equivalent to the Windows .pfx type.

Follow the dialogs to export the certificate.


Now install the certificate into the Vista certificate store.

First run the Vista Certificate manage program "certmgr.msc"

Select the Personal/Certificates folder and then Ations->All Tasks->Import

Select the file exported above ( be sure to filter on file type .p12 ).

Follow the import wizard. Be sure NOT to select the

"Enable strong private key protecion" VS Code signing cannot handle the password request

Place the certicate in the "Personal" folder.

The certificate should now be availabe for code signing in VS.

Good luck. Andy

Friday, January 9, 2009

Microsoft StyleCop - Editing setting under Vista 64

Microsoft StyleCopy 4.3 has a master settings file named Settings.StyleCop
This file may be edited with the StyleCopSettingsEditor.exe.
Under Vista 64 write access to the program folders is restricted to users with Administrator privileges.
Here's the rub.
StyleCopSettingsEditor must be running as Administrator to write setting changes to
Settings.StyleCop.
Settings.StyleCop is associated with StyleCopSettingsEditor.exe thru the StyleCop extension, but the "Run as Administrator" option is only available when clicking on exe's.
You can "Run as Administrator" StyleCopSettingsEditor.exe but the exe requires a command line parameter pointing to Settings.StyleCop.

The solution:
Create a shortcut on the desktop to StyleCopSettingsEditor.exe.

Append "Settings.StyleCop" to the target which becomes:

"C:\Program Files (x86)\Microsoft StyleCop 4.3\StyleCopSettingsEditor.exe" "Settings.StyleCop"

Under the Compatibility tab check "Run as Administrator"

Double Click the shortcut to launch StyleCopSettingsEditor.exe. The program is now running as Administrator and has sufficient rights to update Settings.StyleCop in the program folder.

Wednesday, November 12, 2008

Microsoft.mshtml.dll cannot be referenced in VS 2008 3.5 project

I am using VS 2008 and recently upgraded a project from .Net 2.0 to .Net 3.5. (thru the project properties page)
When doing this I checked the Client-only Framework subset option. When I compiled I had errors indicating that the compiler could not reference Microsoft.mshtml.dll.
When I checked the project references this one was marked with the asterisk.

Unchecking Client-only Framework subset option corrected the problem.

Andy

Sunday, September 7, 2008

Testing Enumerations in Eco Ocl

I can never remember the Ocl syntax used to refer to the value of an enumeration.

The syntax is $enumname$::$enumvalue$ 

Here is a sample Ocl string to select a particular value of VehicleTypes 

"VehicleSupplier.allInstances->select( Type = VehicleTypes::MotorHome)"

Monday, August 18, 2008

Using Linq extension methods with arrays

I was generating a file path and file name from user text.

This routine was vulnerable to chars illegal to the file system in the user text.

I needed to strip any illegal chars from the user text.  

The Path class has two static methods which return path and file name illegal chars.

These are:

Path.GetInvalidPathChars( ) -> char[]

Path.GetInvalidFileNameChars( ) -> char[]

In order to strip both I wanted to create the set union of these two arrays.

The Linq set extension methods return IEnumerable which cannot be easily copied to a new array.  

In the end I used the following to generate a set comprising the union of both sets of illegal chars.

List illegals = new List( Path.GetInvalidPathChars( ).Union( Path.GetInvalidFileNameChars( ) ) );

Note that if you wish to change the file extension it is important to add '.' to the list of illegal chars.  Failure to do so may result in your filename being truncated at the '.'.