Aug 2 2010

Cleaning a VS2010 solution with a sledgehammer

Category: .Net | My SoftwareRory Primrose @ 07:11

My workplace has been having issues with VS2010 picking up old assemblies since we have been using VS2010 on a complex services solution. The issue usually pops up when executing test runs with the built in support for MSTest. This occasionally happened in VS2008 but is much more prevalent in 2010. The scenario seems to be that somewhere between the IDE and MSTest is picking up assemblies from prior TestResults directories if the assembly can’t be found in bin\Debug or bin\Release directories. This means that the normal clean operation under the build menu is not sufficient to get rid of this problem.

Enter the sledgehammer. I wrote a little utility that will recursively go through each bin, obj and TestResults folder under the solution path and delete everything it can (including read-only files). Any exceptions encountered will be output to the console. The code itself is really simple.

namespace Neovolve.SolutionCleaner
{
    using System;
    using System.IO;

    internal class Program
    {
        private static void DeleteDirectory(String directoryPath)
        {
            String[] directories = Directory.GetDirectories(directoryPath);

            for (int index = 0; index < directories.Length; index++)
            {
                String childDirectory = directories[index];

                DeleteDirectory(childDirectory);
            }

            Console.WriteLine("Cleaning directory " + directoryPath);

            String[] files = Directory.GetFiles(directoryPath);

            for (Int32 index = 0; index < files.Length; index++)
            {
                String file = files[index];

                Console.WriteLine("Deleting file " + file);

                try
                {
                    FileInfo fileInfo = new FileInfo(file);

                    if (fileInfo.IsReadOnly)
                    {
                        fileInfo.IsReadOnly = false;
                    }

                    fileInfo.Delete();
                }
                catch (IOException ex)
                {
                    Console.WriteLine(ex);
                }
                catch (UnauthorizedAccessException ex)
                {
                    Console.WriteLine(ex);
                }
            }

            Console.WriteLine("Deleting directory " + directoryPath);

            try
            {
                Directory.Delete(directoryPath, true);
            }
            catch (IOException ex)
            {
                Console.WriteLine(ex);
            }
            catch (UnauthorizedAccessException ex)
            {
                Console.WriteLine(ex);
            }
        }

        private static void Main(String[] args)
        {
            foreach (String argument in args)
            {
                if (Directory.Exists(argument))
                {
                    ProcessDirectory(argument);
                }
            }

            Console.WriteLine("Completed");
        }

        private static void ProcessChildDirectory(String directoryPath, String childDirectory)
        {
            String[] directories = Directory.GetDirectories(directoryPath, childDirectory, SearchOption.AllDirectories);

            foreach (String directory in directories)
            {
                DeleteDirectory(directory);
            }
        }

        private static void ProcessDirectory(String directoryPath)
        {
            ProcessChildDirectory(directoryPath, "bin");
            ProcessChildDirectory(directoryPath, "obj");
            ProcessChildDirectory(directoryPath, "TestResults");
        }
    }
}

The best way to hook this up is via the Visual Studio External Tools dialog by passing in the current solutions directory path.

image

This method also allows you to output the console results to the Output window for a more integrated experience.

NOTE: It’s a good idea to run a Visual Studio clean from the build menu before running this tool to get Visual Studio to release any locks it has on files in these directories. We haven’t had any assembly version conflicts since running this tool.

You can either compile the above yourself or grab the executable below.

Neovolve.SolutionCleaner.zip (2.61 kb)

Tags:

Feb 26 2010

Updated Neovolve BE support in CodePlex

Category: My Software | .NetRory Primrose @ 15:37

I have released the new versions of my BE related projects in CodePlex.

Neovolve.BlogEngine.Web 1.1

Neovolve.BlogEngine.Net.Web 1.1 contains a redirector module that translates Community Server url formats into BlogEngine.Net urls. This module will redirect Community Server pages, posts, month post lists, day post lists, tags, syndication and tagged syndication urls to the most appropriate location in BlogEngine.Net. BlogEngine.Net relies on its own friendly written urls when the urls are processed. This module cannot rewrite Community Server urls as BlogEngine.Net will not be able to understand what the requested resource is. The module must redirect requests to the equivalent BlogEngine.Net friendly url so that BlogEngine.Net url writing can occur such that resources are resolved correctly.

In Community Server, tags and categories are the same thing and it supports tag filtering by allowing multiple tags to be defined. BlogEngine.Net supports both tags and categories as separate entities and has a concept of a category hierarchy, but doesn't support tag filtering. When a Community Server url is encountered where multiple tags are defined, the first Community Server tag in the url that can be matched to either a BlogEngine.Net category or tag will be the resource used to response to the client request. Preference is given to categories over tags.

Neovolve.BlogEngine.Extensions 1.2

Contains updated CatTagLink, Snippets and SyntaxHighlighter extensions.

Tags: ,

Jul 12 2009

Neovolve ReSharper Plugins 1.1 Released

Category: My SoftwareRory Primrose @ 18:10

I have just released a new version of ReSharper Plugins. This version updates the identification and conversion of value types in cref xml documentation references and now supports ReSharper 4.5

Get the goods here.

Tags:

Jan 19 2009

Neovolve.BlogEngine.Extensions 1.1 released

Category: .Net | My SoftwareRory Primrose @ 08:10

This release contains bug fixes and added features for CatTagLinker and Snippets BlogEngine.Net extensions. See Neovolve BlogEngine Extensions 1.1 Help for further information. The release can be downloaded from here.

Tags: ,

Dec 23 2008

ReflectorLink 1.0.1 released

Category: My SoftwareRory Primrose @ 10:33

ReflectorLink 1.0.1 is a minor update to 1.0. It fixes the issue where ReflectorLink wasn't able to resolve the Reflector window in order to ask it to load specific assemblies as determined from the selected context in Visual Studio. The issue was that the title of the window was changed when the application was bought by Red Gate.

You can grab 1.0.1 from the CodePlex project release page here.

Tags:

Oct 15 2008

Supporting Community Server urls in BlogEngine.Net

Category: .Net | Applications | My SoftwareRory Primrose @ 08:23

One of the parts of my migration from CS to BlogEngine.Net was to continue support for CS url formats. Primarily, this is because I have lots of Google traffic and people who are subscribed to syndication feeds on those urls. Writing an http module was the easiest way to provide support for these existing urls.

I have released the first version of this module which is being used on this site currently. You can get the binaries and source from the CodePlex project here.

The following are the release notes which are also found in the comments in the code:

Neovolve.BlogEngine.Net.Web 1.0 contains a redirector module that translates Community Server url formats into BlogEngine.Net urls. This module will redirect Community Server pages, posts, month post lists, day post lists, tags, syndication and tagged syndication urls to the most appropriate location in BlogEngine.Net. BlogEngine.Net relies on its own friendly written urls when the urls are processed. This module cannot rewrite Community Server urls as BlogEngine.Net will not be able to understand what the requested resource is. The module must redirect requests to the equivalent BlogEngine.Net friendly url so that BlogEngine.Net url writing can occur such that resources are resolved correctly.

In Community Server, tags and categories are the same thing and it supports tag filtering by allowing multiple tags to be defined. BlogEngine.Net supports both tags and categories as separate entities and has a concept of a category hierarchy, but doesn't support tag filtering. When a Community Server url is encountered where multiple tags are defined, the first Community Server tag in the url that can be matched to either a BlogEngine.Net category or tag will be the resource used to response to the client request. Preference is given to categories over tags.

To use this module, put the release binary into your bin directory and add the following to the httpModules section in web.config.

<add name="CSUrlRewrite" type="Neovolve.BlogEngine.Web.CSUrlRedirector, Neovolve.BlogEngine.Web"/>

Download from here.

Tags: ,

Oct 6 2008

Snippets 1.2 released

Category: .Net | Applications | My SoftwareRory Primrose @ 07:45

Snippets 1.2 contains two bug fixes for BlogEngine.Net. The first bug was serious in that the extension was stripping contents that occur before the first html tag for snippets that don't require brackets. The second bug was minor in that the extension would not inject snippets which don't require brackets when the content doesn't contain any html tags.

Get the latest code from here.

Tags: ,

Sep 26 2008

Snippets 1.1 released

Category: Applications | My Software | .NetRory Primrose @ 07:29

I have updated my Snippets BlogEngine.Net extension to have better handling of html tags. Fragments are now only injected into the contents of html tags rather than their definitions. The contents of anchor tags are skipped if the fragment itself contains an anchor tag.

You can grab the latest version from here.

Tags: ,

Jul 8 2008

Visual Studio Addin - No such interface supported

Category: .Net | My SoftwareRory Primrose @ 11:00

I'm working on a new Visual Studio addin that launches a profiling application that in turn runs unit and load tests. I can't recall how I created the project, but it must not have been by using the addin wizard. When I debugged the addin in another instance of Visual Studio, I got an error indicating that the addin couldn't be loaded or threw an exception. The additional information it gave was "No such interface supported".

After pulling my hair out for quite a while, the answer was that the AssemblyInfo.cs contained the following:

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

Visual Studio is written mostly in the COM world, including the functionality that resolves and loads addins. This attribute hides the addin from Visual Studio. It therefore can't find the interface it is expecting when it attempts to load the addin from the configured type information. Removing this attribute from AssemblyInfo.cs (it is included by default) or setting its value to true will allow Visual Studio to correctly load the addin.

Tags:

Jul 6 2008

Neovolve ReSharper Plugins 1.0 released

Category: .Net | My Software | ApplicationsRory Primrose @ 10:42

I have just released the ReSharper Plugins 1.0 in my NeovolveX extensibility project on CodePlex. This plugin formats code as part of the ReSharper code format profiles.

The following is a copy of the Using ReSharper Plugins 1.0 documentation on the project site

Value Type Alias Formatter

The ReSharper Plugins project currently contains a single plugin that provides C# code formatting functionality. This formatting function allows for type declarations to be formatted between their alias type and their CLR type. For example, depending of the format settings defined in a code cleanup profile, bool can be converted to Boolean or Boolean converted to bool.

Configuration

The following displays the normal code format profile dialog.

ProfileSettings.jpg

When the plugin is installed, the code format profile dialog will include an additional format option called Type alias conversion.

CustomFormatProfile.jpg

The type conversion options are:
  • Do not change - No change is made to the code
  • Convert to alias type - References of CLR types are converted to their alias types (Boolean to bool for example)
  • Convert from alias type - References of alias types are converted to their CLR types (bool to Boolean for example)
The Do not change setting is the default value.

Type mappings

The following are the type mappings that are supported for converting types between alias types and their CLR types.

Alias type CLR type
object Object
char Char
string String
bool Boolean
byte Byte
short Int16
int Int32
long Int64
ushort UInt16
uint UInt32
ulong UInt64
double Double
decimal Decimal
float Single
sbyte SByte

Code examples

Code formatted to use alias types

AliasCode.jpg

Code formatted to use CLR types

CLRTypeCode.jpg

Grab it from here.

Tags: ,