Using BlogEngine.NET 2.0 with .NET 4.0 framework
BlogEngine 2.0 is .NET 3.5 application, but you can use it with .NET framework 4.0 with little effort by compiling source code as .NET 4.0 assembly. You can do it with free Visual Web Developer Express 2010 which can be downloaded as stand alone or installed with MS web platform installer, whichever you prefer. Here is short walk through.
Initial setup
At first we want to set up and compile default .NET 3.5 install to make sure we not missing files, download is not corrupted etc. Just a precaution.
- Get latest source code here. Click download latest version link in the right side bar and pull zip file to your local drive.
- Unzip it to any local directory, launch VS or web developer and open solution file (BlogEngine/BlogEngine.sln).
- Right-click BlogEngine.Net project in the solution explorer and click “set as startup project”, then right-click default.aspx and click “set as start page”.
- Ctrl+F5 to build and run the project just to make sure all set up properly. You should see BlogEngine site running in your default browser.
.NET 4.0 tweaks
Now as you got default 3.5 install running, lets set it up to use .NET 4.0 instead.
- Right click BlogEngine.Core project in solution explorer and select “properties”. In the properties dialog, change target framework from 3.5 to 4.0. Click ok and confirm selection.
- Right click website project and select “property pages”. Also change it from 3.5 to 4.0.
- Again right-click Core project and select “add reference”. In the add reference dialog, select System.Web.ApplicationServices namespace to add it to the project references. We need this due to slight change in the ASP.NET membership interface in .NET 4.0, otherwise you’ll get lots of compilation errors about namespaces not found.
Open setup/ASP.NET_4.0_Web.Config and copy all its content, then open Web.Config and paste it there to override existing configuration file. Save all.
Click Ctrl+F5 to build the project. Application should compile as .NET 4.0 with no errors.
If all went well, you are ready to deploy project to any .NET 4.0 web hosting. To run it on the host, you’ll need to copy (FTP) all files in the BlogEngine.Net folder to directory that configured as web application and set write permissions on App_Data folder in the hosting site. In the next post we’ll deploy it to GoDaddy shared hosting running .NET 4.0 as an example.
Update:
If you get"Unable to load one or more of the requested types" error, modify this function in Utils.cs in the core project, just replace what you have with code below:
private static IEnumerable<Assembly> GetCompiledExtensions()
{
var assemblies = new List<Assembly>();
var s = Path.Combine(HttpContext.Current.Server.MapPath("~/"), "bin");
var fileEntries = Directory.GetFiles(s);
foreach (var asm in from fileName in fileEntries
where fileName.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)
select Assembly.LoadFrom(fileName)
into asm
let attr = asm.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false)
where attr.Length > 0
let aca = (AssemblyConfigurationAttribute)attr[0]
where aca != null && aca.Configuration == "BlogEngineExtension"
select asm)
{
assemblies.Add(asm);
}
return assemblies;
}