Update CompiledDomainModel from Visual Studio

Posted by Robin Hermanussen on April 05, 2011 · 3 mins read

My friend and I were talking about the CompiledDomainModel module the other day. He suggested that it would be a little easier if you could update the code from Visual Studio.

A few options were discussed, until we arrived at a rather nifty one. The generated code would start with a certain prefix, followed by a url that can be used to regenerate the code. Then, a Visual Studio plugin or macro could refresh the code by downloading it from that location.

Well, I’ve implemented just that! The code needed in CompiledDomainModel can be found in the current trunk version in SVN and I´ll add it to the release notes for the next release. The macro for updating generated code can be found on this page.

The following steps should be taken to generate code from Visual Studio (I’ve tested this with VS2010, and I’m not sure if it will work with VS2008):

  1. Make sure you have the CompiledDomainModel version from the trunk (or the release after, when it’s released)
  2. Generate the code and paste it into a file in your solution in Visual Studio
  3. Install the macro
    Now, you’re all set up to use the macro, so you can skip the first 3 steps next time
  4. Open the generated file from the Solution Explorer and make sure it is checked out of source control (if configured)
  5. Run the macro
  6. Choose to reload the file from the file system when asked about it

You may notice a few things that are not that convenient yet:

  • You have to actually open the file before regenerating it – This was the quickest way I could figure this out. If anyone knows how to get the selected file from the solution explorer, then please let me know!
  • You have to check out the file from source control – The file must be writable. The macro writes the generated code directly to the filesystem, because writing it in the editor turned out te be way too slow. Perhaps source control can be controlled from the macro as well, but I don’t know how to do that.
  • The module needs to be accessible to anonymous users, as the macro isn’t authenticated in Sitecore. But this is not really a problem in a development environment. This does mean that the comment always says “User ‘sitecore\Anonymous’ generated this file.”.

I’ve never coded a macro before; I’ve never even coded in VB.NET before (yes, I said the UGLY word). But even with these minor issues, the macro does seem to make things a little easier if you need to regenerate the code often.

Here’s the code for the macro. Have fun!