Wednesday, December 19, 2007

For a project I did using VSTO, we need to have strong named assemblies when deploying our VSTO application.

Now we have one 3rd party assembly which is not strong named.

So how could you make a 3rd party assembly strong named for your project ?

It’s very easy and it only takes 2 command line commandos:

ILDASM /out:asm.il asm.dll
ILASM asm.il /KEY=key.snk /DLL /OUTPUT=asm.dll

With these parameters

  • Asm.dll is your dll to sign
  • Key.snk is your key
12/19/2007 2:58:17 PM (Romance Standard Time, UTC+01:00)  #     | 
 Wednesday, October 03, 2007

Everyone knows Snag-it, the great capturing tool of Camtasia.  I think that a lot of developers use this tool to make screen captures.

Well these guys gives us a nice plugin for VSTS.  After you have installed this plugin, you can easily add a screenshot to your work items in VSTS.  It's just great :-).

You can download it here. If you want to see it working before installing just watch this video.

10/3/2007 8:15:50 AM (Romance Standard Time, UTC+01:00)  #     | 
 Friday, July 27, 2007
How can you set in a very fast way the tab order of your winform in VS2005 ? By using the menu option "Tab Order".
7/27/2007 9:35:18 AM (Romance Standard Time, UTC+01:00)  #     | 
 Friday, July 06, 2007

I just found a strange label behaviour in VS2005.  When I add a label on my winform and I add the text to it where we use rounded brackets, the closing rounded bracket isn't showed and at the beginning of text another opening rounded bracket is showed.


The properties of the label.


The result on the label

The most strange thing is that it's only in the project where I'm currently working and they don't have their own label control.

After checking out more it's also with the "/" character.

Don't know what it is, but it's irritating.

Update : this behaviour is only when you use the property RightToLeft = true and the combination of Autosize = false.  It seems that this is a bug.  Don't have found a solution for it. But a collegue of me has reproduced this bug.

7/6/2007 9:03:44 AM (Romance Standard Time, UTC+01:00)  #     | 
 Thursday, April 19, 2007
For a project I'm currently working on, we need a service that send on regular base a signal to a certain system, this service can't be hosted in IIS and we need to use a windows service because the Windows Service can continuously send that signal. This service uses an httplistener to receive the soap messages from clients and parses the incoming SOAP to get the data. This simulates the IIS so soap calls can be send through HTTP, clients are not aware of the fact that they are not talking to IIS. This concept allows keeping sending the heartbeats while processing the soaprequest.
4/19/2007 9:25:48 PM (Romance Standard Time, UTC+01:00)  #     | 
 Tuesday, January 16, 2007

I had reinstalled my PC, and I want to add my own code snippets back in VS2005, only they are located on a location that differs from the standard location for code snippets.  So normally you would go to the code snippet manager (Under the tools menu) and you can add your snippets from a different location.

But now the code snippet manager is missing in the tools menu.

You can add the command back by going into Tools/Customize, Click on the Commands Tab, select the Tools Menu, and drag the Code Snippets Manager onto any command bar that you like.

1/16/2007 10:18:47 AM (Romance Standard Time, UTC+01:00)  #     | 
 Monday, January 08, 2007
Why do you need them? We could give you a short answer about this. When developing several projects in a company, you want them to have the same look. So, just like me, for every new project you copy files, code, etc from a previous project. The danger is that in the first place you forgot some items and then you have to add them later. This all takes up a lot of work. You could help yourself and your team by creating a project template. When this template is installed you can use it, just like when you start to create a new project with one of the standard templates.
1/8/2007 1:58:44 PM (Romance Standard Time, UTC+01:00)  #     | 
 Wednesday, January 03, 2007

When you want to build your solution in VS 2005, together with TFS as source control it could that you encountered the following error:

Build FAILED.
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Microsoft.Common.targets(2797,9): error MSB3491: Could not write lines to file "obj\project.vbproj.FileList.txt". Access to the path 'd:\builds\project\obj\project.vbproj.FileList.txt' is denied.

The problem is that this file is checked into source control and they are marked as read-only.  Even by setting the read-only flag to off it doesn’t work, because the next build the flag is switched on again.  As they are intermediate files, generated by the build, these should never been checked in.  So to solve the error above, delete the file from SCC, delete the file from your HD and try again.

1/3/2007 2:47:30 PM (Romance Standard Time, UTC+01:00)  #     | 

As always, you want only a single instance running of your program.  To do this you have to make use of the Mutex object.  By using reflection we get the executing name of our application.  We will use it for checking if there’s already an instance.

The Mutex object can be used for interprocess synchronization.  With this we could check if our application is already running.  With the waitone method we can request the  ownership of our mutext object.  If it return false, then there’s already a process running using this mutex object.

Example code :

using System.Reflection;
using System.Threading;

…..

private static Mutex s_Mutex;

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
s_Mutex = new Mutex(true, Assembly.GetExecutingAssembly().GetName().Name);

if (s_Mutex.WaitOne(0, false))
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
else
MessageBox.Show("Already an instance running", "your application", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}

1/3/2007 9:41:28 AM (Romance Standard Time, UTC+01:00)  #     | 
 Monday, May 15, 2006

The previous post was just about the basic principles of code snippets in VS2005.  Now we will describe the power boost of code snippets: the $name$ notation (or the literal replacement) and the object replacement.

The literal replacement.

When you want to create a code snippet with some customized parts (like variable type, variable name, ...) that must replaced by the developer after inserting the code snippet, you can use a literal.

How do you create this?
In the Snippet element place an element called "Declarations".  In this element you place your literals which can be one or more literals.  The literal element has a few elements:

  • ID: The ID of the literal
  • Default: The default value for the literal

Optional you can add:

  • Function: Function to execute when the literal receives focus in Visual Studio
  • Tool tip: short description of the literal

Now you have created your literal, but you have to place it in your code snippet.  This is done by placing the $ sign in front and at the end of your Literal ID element.  Now go to the code element.  Within your code place the $literalID$ notation where you want it.  The next time you add the code snippet you will see a green rectangle.  This is the place where you have added your literal.  If you have inserted a default value this will be filled in the rectangle.

You can have multiple insertions for the same $literalID$ element.  This gives us a nice effect in Visual Studio.  Only for the first entry you will see the green rectangle.  After filling in the rectangle, Visual Studio will automatically replace all the other literals with the same ID with your filled in value.

Two examples:
Example 1: One literal

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>My MessageboxSnippet</Title>
<Shortcut>mmbs</Shortcut>
<Description>My Snippet for messagebox in c#</Description>
<Author>
</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>YourMessage</ID>
<ToolTip>Place your message here</ToolTip>
<Default>Place your message here</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[MessageBox.Show("$YourMessage$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

Example 2 : More literals and used more than one time

<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>My MessageboxSnippet</Title>
<Shortcut>mmbs</Shortcut>
<Description>My Snippet for messagebox in c#</Description>
<Author>
</Author>
</Header>
<Snippet>
<Declarations>
<Literal Editable="true">
<ID>YourMessage</ID>
<ToolTip>Place your message here</ToolTip>
<Default>Place your message here</Default>
<Function>
</Function>
</Literal>
<Literal Editable="true">
<ID>Title</ID>
<ToolTip>Place your message title here</ToolTip>
<Default>Place your message title here</Default>
<Function>
</Function>
</Literal>
</Declarations>
<Code Language="csharp"><![CDATA[MessageBox.Show("$YourMessage$","$Title$");
MessageBox.Show("$YourMessage$");]]></Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

As you can see, code snippets in VS2005 give some great power to developers.  I have created or downloaded and changed them to our needs, several good code snippets. Every developer has installed them locally.

5/15/2006 6:08:07 PM (Romance Standard Time, UTC+01:00)  #     | 
 Thursday, May 11, 2006

Code snippets can make the life of a developer a lot easier.  Already in VS2003 you had the possibility to add code snippets to your toolbox or make use of a third party tool.  In VS2005 Microsoft has added a code snippet manager.  We will explain in short how to create such a code snippet.

The format of the code snippet is XML base.  An example of a code snippet file:

<CodeSnippets
xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
     <Title>My MessageboxSnippet</Title>
     <Description>My Snippet for messagebox in c#</Description>
     <Shortcut>mmbs</Shortcut>
</Header>
<Snippet>
<References>
<Reference>
<Assembly>System.Windows.Forms.dll</Assembly>
</Reference>
</References>
<Code Language="VB">
<![CDATA[MessageBox.Show("My first own snippet")]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

We have several parts:

  • Header
    • Title: Name of the snippet
    • Description : Description of the snippet
    • Shortcut : Shortcut to access the snippet
  • Snippet
    • Reference: references to DLL's needed when implementhing the snippet.  Be aware that this is only supported by VB.Net snippets.  Snippets for other code needs to add the reference manually in your solution.
    • Code language: the language of the code
      • VB
      • CSharp

The only thing left now is to save the snippet as a .snippet file and place it in the snippet directory.  By default your snippet directory can be found here : My Documents\Visual Studio 2005\Code Snippets\ and then the language and then the directory "My Code snippets".

A complete course can be found in the MSDN.

But there is an easier way.  The VS Editor Team has released a PowerToy named Snippy.  This is a very handy tool for creating your own snippets.  Click here for more info.

Some interesting code snippets:
Microsoft: http://msdn.microsoft.com/vstudio/downloads/codesnippets/default.aspx
NUnit: http://codebetter.com/blogs/scott.bellware/archive/2006/02/28/139446.aspx
Public property: http://weblogs.asp.net/jeffwids/archive/2005/09/08/424679.aspx

I also found a great tool for world wide snippet sharing: http://www.codexchange.net/
And like gotdotnet there's also a gotcodesnippet site: http://gotcodesnippets.com/

5/11/2006 9:23:04 PM (Romance Standard Time, UTC+01:00)  #     |