Click here to Skip to main content
13,254,366 members (62,656 online)
Click here to Skip to main content
Add your own
alternative version


2 bookmarked
Posted 25 Aug 2010

Automatic ResX Comment Checking with MSBuild Integration

, 25 Aug 2010
Rate this:
Please Sign up or sign in to vote.
Ensure that your resx file contains a valid comment for each entry with MSBuild integration


Application internationalization mostly uses resx file to store the various strings that need to be translated. This tool helps you to ensure that your resx file within a Visual Studio project are correctly filled with a comment value for each entry.

Here is a screenshot of the result.


How Does It Work ?

This tool uses two namespaces from MSBuild:

In order to implement a custom MSBuild task, all you need to do is to create a class that extends the Microsoft.Build.Utilities.Task abstract class and implement the task logic in the Execute method. The return value will indicate if the task failed or succeeded.

In this tool, all we want is just to add one warning by missing entry, so we will always return true.

using System;
using System.Collections;
using System.IO;
using System.Resources;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

namespace MSBuild.Tools.Tasks {

    public class ResXCommentCheck : Task {

        public override bool Execute() {
            foreach (string file in Directory.GetFiles(Environment.CurrentDirectory, 
                "*.resx", SearchOption.AllDirectories)) {
                using (ResXResourceReader reader = new ResXResourceReader(file)) {
                    reader.UseResXDataNodes = true;
                    foreach (DictionaryEntry entry in reader) {
                        ResXDataNode node = (ResXDataNode)entry.Value;
                        if (string.IsNullOrEmpty(node.Comment)) {
                                "{0} doesn't contain any comment for the key {1}.",
                                Path.GetFileName(file), node.Name);
            return true;

MSBuild Integration

The MSBuild integration has to be made within the Visual Studio project (.vbproj, .csproj file) with the help of the UsingTask node that helps you to load a specific task by its taskname (i.e. class FullName) and its location :

  • AssemblyFile attribute means a local reference
  • AssemblyName attribute means Global Assembly Cache
<Project ToolsVersion="4.0" DefaultTargets="Build" 

  <UsingTask TaskName="MSBuild.Tools.Tasks.ResXCommentCheck"  

    AssemblyFile="c:\MSBuild.Tools.Tasks.dll" />

The custom task can be called in the AfterBuild target.

<Target Name="AfterBuild">
    <UsingTask TaskName="MSBuild.Tools.Tasks.ResXCommentCheck" 

        AssemblyFile="C:\MSBuild.Tools.Tasks.dll" />

Points of Interest

This tool was my first experience with custom MSBuild tasks. As you can see, the API is very easy to use and it offers many possibilities to help developers to check their code.


  • 25th August, 2010: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Olivier Gaudefroy
Technical Lead KLEE Group
France France
No Biography provided

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171114.1 | Last Updated 25 Aug 2010
Article Copyright 2010 by Olivier Gaudefroy
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid