Mixing C# and VB.NET in one assembly

Development, MSBuild, CSMVPs Comments

A couple of weeks ago Jayson Knight invited me to join the CSMVP's' CSModules package. This project was created to incorporate several CSModules written by CS MVP's. So I bought into that project by bringing along my Akismet spam rule.

At that point in time, for each CSModule there was a single Visual Studio project, all bound together in a Visual Studio solution. But our goal was to incorporate all modules into a single assembly, so the user only has to copy one DLL to his /bin web folder.

My first idea was to put all sources into a single project. However, since every CS MVP wrote his module in his favorite language, there were both C# and VB.NET projects. Unfortunately, in Visual Studio projects have a certain type supporting only a single language.

But luckily, even if there's no support by the IDE, you still can compile different .NET languages into one assembly. The solution are modules. A module is a unit of compilation, comparable to .obj files in C++. It can't stand by its own, but must be linked into an assembly before it can be used. Basically, a module is an assembly without a manifest. You can get more details on MSDN at .netmodule Files as Linker Input. Additionally I recommend reading Junfeng Zhang's Netmodule vs. Assembly and Multimodule Assemblies.

Knowing the concept of modules, I was able to write a MSBuild project file to compile all CSModules into a single assembly. Here's an (extremely) simplified version:

<Project
  DefaultTargets="build"
  xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
        
  <!-- Target folders -->
  <PropertyGroup>
    <SourcePath>src</SourcePath>
  </PropertyGroup>

  <!-- Specify the sources to include, excluding any assembly info's -->
  <ItemGroup>
    <CSFiles
      Include="$(SourcePath)/**/*.cs"
      Exclude="$(SourcePath)/**/assemblyinfo.cs"/>
    <VBFiles 
      Include="$(SourcePath)/**/*.vb" 
      Exclude="$(SourcePath)/**/assemblyinfo.vb;$(SourcePath)/**/My Project/*"/>
  </ItemGroup>

  <!-- Specify all referenced assembly -->
  <ItemGroup>
    <References Include="lib/2.1 RTM/*.dll" />
  </ItemGroup>

  <!-- Target files -->
  <PropertyGroup>
    <OutputModule>MyModule</OutputModule>
  </PropertyGroup>

  <!-- builds the CSMVPs.CSModules assembly -->
  <Target 
    Name="build"
    Inputs="@(CSFiles);@(VBFiles);@(References)" 
    Outputs="$(OutputModule).dll">

    <!-- compile C# sources -->
    <CSC
      Sources="@(CSFiles)"
      References="@(References)" 
      OutputAssembly="$(OutputModule).CS.netmodule"
      TargetType="module">
    </CSC>
      
    <!-- compile VB.NET sources -->
    <VBC
      Sources="@(VBFiles)"
      References="@(References)" 
      OutputAssembly="$(OutputModule).VB.netmodule"
      TargetType="module">
    </VBC>

    <!-- link the C# and VB.NET modules -->
    <Exec 
      Command="link /dll /ltcg /out:$(OutputModule).dll *.netmodule" />
  </Target>
</Project>

Pimp my Community Server

Yesterday I upgraded my site to Community Server 2.1 RTM. I'm astonished how many additional mods I'm already using:

Community Server MVP's Alabaster CSModule Package 
A collection of CSModules written by CS MVPs and myself. (I contributed the Akismet spam rule btw)

Qgyen.AllCommentRss
Provides a secure RSS feed for all comments within a certain blog. It also provides information like if it is an actual comment or a trackback, the post's name, URL, if it is approved, and then it gives quick links to approve/disapprove, view, or delete the comment.

Qgyen.Lightbox
A Lightbox module for any photo from the gallery, an URL or Flickr.

Improved version of Scott's Flickr for Community Server
Add a Flickr area to the content selector, which enables you to select images from your Flickr account.

Qgyen.ExtendedUrlMapping
This module allows you to easily map one URL within Community Server to another. I for instance use it to map both my blog and my gallery to the root.

Syntax Highlighting module
Formats code snippets with syntax highlighting. I cannot give you any link, because I'm using a modified version of a CS1.1 module, and I don't know the original author anymore.

CommunityServer OpenSearch Handler
Adds OpenSearch support to your blog, allowing IE7 users to search your site from their toolbar without any installation.

CoComment support
Tracks your comments across the blogosphere.

I just noticed that three and a half modules of the modules are written by Ken Robertson. Seems as he is the most active guy on the Community Server community. [;)]

Server Outage

Site news Comments

As my two readers may already have noticed, my site wasn't accessible for the last 24hrs. The SQL Server hosting my Community Server database had a hard disk failure, and it took them some time to find the backup tapes [:S]

Apparently they found the backup, and my site is alive again. I used the time to change the skin of my blog to Paperclip with a custom header image as described by Keyvan.

Community Server 2.1 Beta 2

I just upgraded my site with Community Server 2.1 Beta 2, which was published yesterday.

The upgrade went pretty good. I only had to re-compile my custom Akismet spam rule and Ken Robertson's Qgyen.ExtendedUrlMapping module (which source code he fortunately published as well.)

Though I'll stay with the default skin until its final release, I'd like to mention that there are four new blog skins included in Beta 2. Awesome work, Jaxon.