I've been running BlogEngine.NET on this Blog since its birth. Started on version 1.5 and recently this year the BlogEngine team released version 2.0.
I decided to migrate to this new version and before doing that I needed to convert the source files to the Web Application Project format. For me, the WAP format makes more sense that the Web Site model introduced with Visual Studio 2005. Since this is not a post on comparing the two alternatives I'll just let you follow this link that does exactly that.
Moving on.
For version 1.5 I proceeded and converted the solution to WAP also. In this blog post from a fellow developer I found the instructions on how to do so. The instructions were almost perfect and only few things needed attention to have the BlogEngine running as it should.
This time, for version 2.0, the BlogEngine.NET Codeplex site had the instructions to complete the process on this page . The instructions are now less in number and they even look a lot cleaner that what we had for version 1.5. At the end of the step by step instructions, in the Conclusion section, it says that "you don't need to make any changes to the code itself as it was a case in earlier versions". In my case I did have to make changes to the code in order to make the application work. Here is my list of changes:
- Open the property page for the BlogEngine.NET project and set the new name for the Assembly and Namespace. Let's agree on "BlogEngine".

- In the Utils.cs file in the BlogEngine.Core project locate the line that sets the assemblyName variable and set its value to the Assembly name that was selected in the previous step. "BlogEngine". Do the same for the line that sets the Assembly Name when the check for "IsMono" is made.
public static IEnumerable<Assembly> CodeAssemblies()
{
var codeAssemblies = new List<Assembly>();
CompilationSection s = null;
//WAP FIX
//var assemblyName = "__code";
var assemblyName = "BlogEngine";
try
{
try
{
s = (CompilationSection)WebConfigurationManager.GetSection("system.web/compilation");
}
catch (SecurityException)
{
// No read permissions on web.config due to the trust level (must be High or Full)
}
if (s != null && s.CodeSubDirectories != null && s.CodeSubDirectories.Count > 0)
{
for (var i = 0; i < s.CodeSubDirectories.Count; i++)
{
assemblyName = string.Format("App_SubCode_{0}", s.CodeSubDirectories[i].DirectoryName);
codeAssemblies.Add(Assembly.Load(assemblyName));
}
}
else
{
if (!IsMono)
{
//WAP FIX
//assemblyName = "App_Code";
assemblyName = "BlogEngine";
}
codeAssemblies.Add(Assembly.Load(assemblyName));
}
codeAssemblies.AddRange(GetCompiledExtensions());
}
catch (FileNotFoundException)
{
/*ignore - code directory has no files*/
}
return codeAssemblies;
}
- Please note that I include the "WAP FIX" comment anywhere I make a fix in order to make this WAP work. In the Web.Config file make the following addition of the assembly name in the Pages section:
<pages enableSessionState="false" enableViewStateMac="true" enableEventValidation="true" controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID">
<controls>
<!--WAP FIX-->
<!--<add namespace="App_Code.Controls" tagPrefix="blog"/>-->
<add assembly="BlogEngine" namespace="App_Code.Controls" tagPrefix="blog"/>
</controls>
</pages>
- In order to make the extensions work again you need to make a change in the Editor.ascx.cs file in the "admin\Extension Manager" folder. Since the App_Code folder had to be renamed to something else you need to let the engine know where to find the extensions now. In my case I named the folder "Classes". Neat huh? Here's the change in the file:
protected static string GetExtFileName()
{
var fileName = HttpContext.Current.Request.PhysicalApplicationPath;
var codeAssemblies = Utils.CodeAssemblies();
foreach (Assembly a in codeAssemblies)
{
var types = a.GetTypes();
foreach (var type in types.Where(type => type.Name == ExtensionName))
{
var assemblyName = type.Assembly.FullName.Split(".".ToCharArray())[0];
assemblyName = assemblyName.Replace("App_SubCode_", "App_Code\\");
var fileExt = assemblyName.Contains("VB_Code") ? ".vb" : ".cs";
//WAP FIX
//fileName += Path.Combine(Path.Combine(assemblyName, "Extensions"), ExtensionName + fileExt);
fileName += Path.Combine("Classes\\Extensions", ExtensionName + fileExt);
}
}
return fileName;
}
- Now, that should do it. But no. we're not done yet. Somehow, the classes and files in the admin folder have the classes names and namespaces messed up! For example, the menu.ascx.cs file had the namespace set to "admin.Settings" when it should be "Admin.Posts". Note the casing there as well. Even the casing in the naming was confusing. Check the namespaces, classes names, and the inherits value in the page directive of the ascx files also. They should match the directory where they are at least.
Menu.ascx.cs file under Admin/Posts folder:
//WAP FIX
namespace Admin.Posts // Namespaces were a mess. This was "admin.Settings". Everything inside the admin folder
// had to be checked and corrected.
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Menu : System.Web.UI.UserControl
Comments.ascx.cs file under Admin/Settings folder:
//WAP FIX
namespace Admin.Settings //This was "Admin.Comments". I won't comment the other changes in namespaces in the admin folder.
{
using System;
using System.Data;
using System.Web.UI.WebControls;
using BlogEngine.Core;
using BlogEngine.Core.Web.Extensions;
using App_Code;
//WAP FIX -> Fixed Class Name which was 'Settings'.
public partial class Comments : System.Web.UI.Page
And that's it! That's all we need to make the WAP Project for BlogEngine.NET. But I'm a lot nicer. Please download the whole BlogEngine.NET Project in WAP Format below. The Web.Config in the project is the one for SQL Server. The original one I named "Web ORIGINAL.config". See what I did there?
Update: Forgot to mention that the download below has the BlogEngine.NET Project now targeting .NET Framework 4.0 instead of 3.5. Enjoy!
Download BlogEngine.NET 2.0 WAP Source Code
Cheers!