sharing about .NET and technology RSS 2.0
# Friday, October 31, 2008
# Thursday, October 30, 2008

I am using Windows Live Writer for posting items to my blog. One thing that I don’t like in general, is that applications store resources in the MyDocuments folder and that you cannot specify another location. I’m a huge fan of portable applications, which means that they don’t need any registry settings and/or dependencies, so that you can simply xcopy deploy to another location. Certainly if you are using an external HD, USB flash drive, etc.

Windows Live Writer (WLW) stores by default the drafts in the ‘MyDocuments\My Weblog Posts\Drafts’ folder. I am using the latest beta (v14.0.5025.904) of WLW and didn’t find any settings through the application that enables you to customize folder paths.

I decided to dig into the assemblies of WLW via reflector to see how it is implemented. After some investigation I found that there is a class called ApplicationEnvironment that reside in the WindowsLive.Writer.CoreServices assembly. The Initialize method looks like this

image

Apparently WLW has built-in functionality that enables you to run the application with the settings carried around with the software. WLW checks if there is a folder called ‘UserData’ in the installation folder and uses that folder to store all settings, drafts, etc. This is really great, you simply copy all contents of your WLW directory to for example your external drive and you simply create a folder called ‘UserData’. If you start WLW again it will create all the necessary subfolders and settings.

image

I think it’s a feature of WLW beta that has not been documented yet ;-)

Thursday, October 30, 2008 2:08:31 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [3] -
.NET | Windows Live Writer
# Monday, October 27, 2008

With the PDC 08 going on you can download a CTP of Visual Studio 2010.

Monday, October 27, 2008 9:11:56 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [0] -
.NET | Links
# Saturday, October 25, 2008

Cool, Microsoft decided to bring a fresh new .NET logo. The old .NET logo survived for about 8 years. I like the logo very much!

image

Saturday, October 25, 2008 12:27:52 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [0] -
.NET | Links
# Monday, October 20, 2008

I found a funny and interesting site called 99 Bottles of Beer. The purpose of the site is to have a wide range (> 1200) of programming languages that generate the lyrics of the song 99 Bottles of Bear. Take a look at the following examples

Monday, October 20, 2008 1:43:17 AM (Romance Daylight Time, UTC+02:00) -  # -  Comments [1] -
Internet | Programming

NHibernate uses an xml file to describe the mapping. Typically it is embedded as a resource file inside your project and it has a consistent filename convention, namely <classname>.hbm.xml. Typically an NHibernate project has the following structure

Structure 1

Would it not be nice if we can organize it in the following way? I found it always handy that related classes, like designer classes and resource files are grouped together.

Structure 2

To achieve this structure we can start from the first structure and nest the xml file trough a macro that I’ve written and can be downloaded here (there is also a video how it can be used).

The second step, is to make clear to NHibernate where the mapping files reside. Note that resources that are nested to a class are compiled differently and thus NHibernate will not recognize the mapping files anymore. Therefore we need to traverse manually the assembly and try each embedded resource file. Below you find the resulting code

var domainAssembly = typeof(MyDomain.Order).Assembly;
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();

foreach (var resourceName in domainAssembly.GetManifestResourceNames())
{
   try
   {
      cfg.AddResource(resourceName, domainAssembly);
   }
   catch (NHibernate.MappingException)
   {
      //ignore
   }
}
Monday, October 20, 2008 12:16:35 AM (Romance Daylight Time, UTC+02:00) -  # -  Comments [2] -
.NET | NHibernate
# Thursday, October 16, 2008

In some cases it can be useful to quickly run your Microsoft unit tests on a machine where Visual Studio is not installed. For example on an end-user machine and/or during acceptance testing. Microsoft unit tests have a great integration with Visual Studio and Team Foundation Server, but unfortunately the unit tests cannot be run as a standalone application.

I saw there was an open-source adapter for NUnit, called Microsoft Team System NUnit Adapter from Exact Magic Software that can run Microsoft unit tests inside NAnt. For my unit tests I had some problems with the ExpectedException attribute. Then I noticed there is a project called Gallio and it worked like a charm and it can do a lot more! I noticed that today a new version has been released, namely Gallio v3.0.4.

Gallio is a extensible , open and neutral test automation platform. It provides tools and services needed to run and manipulate tests written using a wide range of other frameworks. Gallio can run tests from

and it can integrate with the following tools

To run the the tests there is a command-line runner, called ‘Echo’ and a graphical user-interface, called ‘Icarus’.

image

Thursday, October 16, 2008 3:25:48 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [3] -
Unit Testing | Visual Studio
# Wednesday, October 08, 2008

Today I needed to install extra stuff on my VPC, but it turned out that there was not enough space. Donn Felker blogged a nice article how you can resize your VHD, I followed all the steps and It worked like a charm.

Wednesday, October 08, 2008 1:10:52 AM (Romance Daylight Time, UTC+02:00) -  # -  Comments [0] -
Links | Vitualization
# Tuesday, September 30, 2008
# Wednesday, August 06, 2008

SQL Server 2008 is now available on MSDN and TechNet, see the announcement here. To have an overview of the new features, you can have a look here and you may download the SQL Server 2008 Books Online. Apparently has SQL Server 2008 powershell support!

Wednesday, August 06, 2008 9:40:44 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [1] -
Links | SQL Server
# Friday, June 20, 2008

Version 0.28 of SyntaxColor4Writer has been compiled with the latest bits of Windows Live Writer 2008 (12.0.1370.325). You can download it from here.

Friday, June 20, 2008 10:20:31 PM (Romance Daylight Time, UTC+02:00) -  # -  Comments [5] -
.NET | SyntaxColor4Writer | Windows Live Writer
# Monday, May 19, 2008
# Wednesday, April 30, 2008
# Tuesday, April 01, 2008
# Sunday, March 23, 2008

The unity application block is a dependency injection container with support for constructor, property and method call injection. It simplifies the Inversion of Control (IoC) pattern and the Dependency Injection (DI) pattern. The Unity application block can be found on CodePlex.

The unity application block has two important methods for registering types and mappings into the container, namely RegisterType and RegisterInstance.

Method Default Lifetime Explanation
RegisterType Transient lifetime Container will create a new instance on each call to Resolve
RegisterInstance Container-controller lifetime Instance has the lifetime of the container

 

Below you find an example where we map the ILogger interface to ConsoleLogger (implements ILogger).

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>();
ILogger logger = container.Resolve<ILogger>();

Assume you have the following class that contains a dependency to ILogger as a parameter on the constructor.

public class MyClass
{
   ILogger _logger;

   public MyClass(ILogger logger)
   {
      _logger = logger;
   }
}

If we use the Resolve method of UnityContainer it will automatically inject the ILogger (ConsoleLogger) object. This is called constructor injection.

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>();
MyClass myClass = container.Resolve<MyClass>();

You can also map multiple types for the same interface. In that case you can use a key as a parameter.

UnityContainer container = new UnityContainer();
container.RegisterType<ILogger, ConsoleLogger>("console");
container.RegisterType<ILogger, EventLogger>("event");

If you now try to resolve MyClass you will get an exception, because it cannot resolve which type (ConsoleLogger or EventLogger) to use. Therefore you can use the Dependency attribute where you can denote a key. For example:

public class MyClass
{
   ILogger _logger;

   public MyClass([Dependency("console")] ILogger logger)
   {
      _logger = logger;
   }
}

Below you find an example of property injection:

public class AnotherClass
{
   ILogger _consoleLogger;
   ILogger _eventLogger;

   [Dependency("console")]
   public ILogger ConsoleLogger
   {
      get { return _consoleLogger; }
      set { _consoleLogger = value; }
   }

   [Dependency("event")]
   public ILogger EventLogger
   {
      get { return _eventLogger; }
      set { _eventLogger = value; }
   }
}

Note that you can also map and register your types through a configuration file.

<?xml version="1.0" encoding="utf-8" ?> 
<configuration>
  <configSections>
    <section name="unity"
            type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection,
                 Microsoft.Practices.Unity.Configuration" />
  </configSections>
  <unity>
    <containers>
      <container>
        <types>
          <type name="console" 
                type="IStaySharp.UnitySample.ILogger, IStaySharp.UnitySample" 
                mapTo="IStaySharp.UnitySample.ConsoleLogger, IStaySharp.UnitySample" />
          <type name="event"   
                type="IStaySharp.UnitySample.ILogger, IStaySharp.UnitySample" 
                mapTo="IStaySharp.UnitySample.EventLogger, IStaySharp.UnitySample" />
        </types>
      </container>
  </containers>
  </unity>
</configuration>

The following code shows you how to use a configuration file with UnityContainer.

UnityContainer container = new UnityContainer();
UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity");
section.Containers.Default.GetConfigCommand().Configure(container);

ILogger logger = container.Resolve<ILogger>("console");
Sunday, March 23, 2008 2:38:43 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [2] -
.NET | Unity
# Tuesday, March 18, 2008

When trying to edit some code during debug, I received the following dialog of Visual Studio:

EditContinue64

It appears that the edit and continue feature is not supported when the target is a 64-bit application. On this page you find a nice overview of the scenarios where the edit and continue features are not supported. To resolve the problem, you have to set the target to x86, which can be found in the project properties.

BuildSettingsPlatform

Tuesday, March 18, 2008 1:50:14 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
.NET | Visual Studio
# Friday, March 14, 2008

In my current sample project when the runtime tried to access the MyMeta library (see following post) I always get the following FatalExecutingEngineError exception:

FatalExecutionEngineError

It turns out that the problem is that the MyMeta library is compiled under a x86 platform whereas the application is running on a x64 platform. In the properties settings of your visual studio project you have to set the platform target to x86! It was set to 'Any CPU', but now everything works fine.

BuildSettingsPlatform

Friday, March 14, 2008 9:11:47 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [1] -
.NET | Visual Studio
# Thursday, March 13, 2008
# Tuesday, March 04, 2008

Component Dropper is a component that resides in the toolbox of VS.NET and enables you to choose a component (controls, datasets, providers, components, etc.) from the assemblies that are referenced in the current project.

In Visual Studio .NET you can auto populate the controls in the toolbox by setting the AutoToolboxPopulate property to true in menu Tools -> Options -> Windows Forms Designer.

AutoToolboxPopulate

Component Dropper is an alternative way for dropping a component on the designer surface. It gives you a dialog with all the components that reside in the assemblies that are referenced in the current project. This means that it is not limited to the assemblies that reside in the current solution. This way you can easily browse and search throughout the assemblies and controls, this is very handy if you have bunch of assemblies and controls. There is never a need to refresh the toolbox, because it dynamically searches throughout the references in the current project.

ComponentDropper09

Download: ComponentDropper v0.9 (35.04 KB)

There is also a demo (1.11 Mb) that illustrates the use of Component Dropper. Note that the demo uses an older version of Component Dropper, namely version 0.5, and it's not an VS add-in anymore.

If after installation you don't see the component dropper appearing in the toolbox, you can simply drag-and-drop the IStaySharp.RazorToolbox.dll to the toolbox.
Any suggestions or remarks are welcome!

Tuesday, March 04, 2008 5:28:38 PM (Romance Standard Time, UTC+01:00) -  # -  Comments [4] -
.NET | Component Dropper | Visual Studio
# Monday, March 03, 2008

PowerCommands is a set of useful extensions for the Visual Studio 2008 adding functionality to various area of the IDE.
The features I found very useful are:

  • Copy/Paste References
  • Edit Project File
  • Remove and Sort Usings

PowerCommands can be downloaded here and below you find the complete list of features:

  • Collapse Projects
    This command collapses a hierarchy in the solution explorer starting from the root selected node. It can be executed from three different places: solution, solution folders and project nodes respectively.
  • Copy Class
    This command copies a selected class entire content to the clipboard. It can be executed from a single project item or a project item with dependent sub items.
  • Paste Class
    This command pastes a class entire content from the clipboard. It can be executed from a project or folder node.
  • Copy References
    This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes.
  • Paste References
    This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node.
  • Copy As Project Reference
    This command copies a project as a project reference to the clipboard. It can be executed from a project node.
  • Edit Project File
    This command opens the MSBuild project file for a selected project inside Visual Studio. It can be executed from a project node.
  • Open Containing Folder
    This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node
  • Open Command Prompt
    This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively.
  • Unload Projects
    This command unloads all projects in a solution. It can be executed from the solution node.
  • Reload Projects
    This command reloads all unloaded projects in a solution. It can be executed from the solution node.
  • Remove and Sort Usings
    This command removes and sort using statements for all classes given a project. It can be executed from a solution node or a single project node.
    Note: The Remove and Sort Usings feature is only available for C# projects since the C# editor implements this feature as a command in the C# editor (which this command calls for each .cs file in the project). The Visual Basic IDE implements this functionality for Imports in an interactive way: Project properties, go to the References tab, then click the Unused References... button, then select which references you want removed via a listbox.
  • Extract Constant
    This command creates a constant definition statement for a selected text. It can be executed from the code window over a selected text.
  • Clear Recent File List
    This command clears the Visual Studio recent file list.
  • Clear Recent Project List
    This command clears the Visual Studio recent project list.
  • Transform Templates
    This command executes the associated custom tool with text templates items. It can be executed from a DSL project node or a folder node.
  • Close All
    This command closes all documents. It can be executed from a document tab.
Monday, March 03, 2008 11:42:58 AM (Romance Standard Time, UTC+01:00) -  # -  Comments [0] -
Links | Visual Studio
Navigation
Archive
<October 2008>
SunMonTueWedThuFriSat
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2010
Christoph De Baene
Sign In
Statistics
Total Posts: 176
This Year: 2
This Month: 0
This Week: 0
Comments: 249
All Content © 2010, Christoph De Baene
DasBlog theme 'Business' created by Christoph De Baene