All for .net, .net for all!

MPFProj Tales #1: Refactoring MPFProj into a library

In my previous post I announced that I downloaded the MPFProj source code and added it to VSXtra as a new class library called VSXtra.ProjectSystem. I like the idea that MPFProj is a framework, but I do not prefer it as a bunch of source files to be added to my own custom project system source. In my mind MPFProj should be implemented in an assembly that can be referenced from my custom project package assembly.

After downloading the source code I managed to refactor MPFProj into a separate class library and I also did the first steps to create the suitable refactoring environment. In this post I briefly describe how I turned MPFProj into a library.

With VSXtra my aim is to improve the developer experience related to VSX and that is why I started to deal with MPFProj. In the downloaded source code there are two sample project systems with source code. I picked up the CustomProject sample with its unit tests and also moved them to a solution together with the VSXtra and VSXtra.ProjectSystem projects to create a refactoring environment. I created the VSXtra.ProjectSystem class library so that it contains all the source files of the MPFProj framework.

The real work started at this point: the original CustomProject sample compiled successfully but stopped to work, only four of the 25 unit test methods ran successfully. In about an hour later I managed to find the reason of failures:

The MPFProj source code wired the name of the embedded resources both in the project file and both into the code. The embedded resources did not use their default resource name (as the C# compiler creates them by default) but had explicit resource name declarations in the project file. To make it even harder to discover, the CustomProject sample’s project file did not explicitly named all the project files but it imported the MPFProj part thought the ProjectBase.files list. This file was the key where I could discover how embedded resources are explicitly named:


    <EmbeddedResource Include="$(ProjectBasePath)\VisualStudio.Project.resx">






The LogicalName element is the one that explicitly names the embedded resource.

After struggling with the resource name issue the CustomProject sample and all the unit tests started to work. At this point I wanted more: I decided that I will change the MPFProj code to use the VSXtra.PackageBase class in the project system packages instead of the Microsoft.VisualStudio.Shell.Package class. It was not easy! I managed to make all the necessary syntax changes in the code in an hour and made the code compile. However, the CustomProject sample only partially worked and majority of unit test failed. Another fight started “against the code” and I had to make other changes “to convince” the whole code it should work again:

—  There were “hidden” Shell.Package references not correctly changed to VSXtra.PackageBase

—  I had to struggle some resource name issues again

—  Some unit test cases did not worked because of the mocks, so I had to change the mocks to reflect the changes from Shell.Package to VSXtra.PackageBase.

After coping with the code I am very satisfied with the fact that MPFProj contains unit test cases. These tests helped me a lot to establish my refactoring environment and integrate MPFProj with VSXtra!

If you are interested in the results, download the VSXtra source code and open the CustomProject.sln file in the VSXtra\Sample\ProjectSystem folder. Please note, that in the future this file can be moved or renamed. Check my future posts with the MPFProj tag about latest information.

Posted Sep 05 2008, 07:44 AM by inovak
Filed under: ,


buy stendra wrote re: MPFProj Tales #1: Refactoring MPFProj into a library
on Fri, Feb 15 2013 21:14

dLZkgH I think this is a real great blog post.Really thank you! Really Great.

Clomiphene 50 mg wrote re: MPFProj Tales #1: Refactoring MPFProj into a library
on Thu, Feb 28 2013 10:19

Z3jPCM Thanks so much for the post.Thanks Again. Cool.