RTUR.NET

.NET and Open Source: better together

NAVIGATION - SEARCH

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.

  1. Get latest source code here. Click download latest version link in the right side bar and pull zip file to your local drive.
  2. Unzip it to any local directory, launch VS or web developer and open solution file (BlogEngine/BlogEngine.sln).
  3. 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”.
  4. 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.

1. 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.

fr4-1

2. Right click website project and select “property pages”. Also change it from 3.5 to 4.0.

ppages

3. 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.

Reference

4. 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.

5. Click Ctrl+F5 to build the project. Application should compile as .NET 4.0 with no errors.

vs

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;
}

Comments (15) -

It's probably worth mentioning that the .NET 3.5 compiled BlogEngine.Core.dll will work under .NET 4.0 without being recompiled.  There are BE users running 2.0 RC with the .NET 3.5 compiled DLL (including myself, just during testing).  It's noted at the link below that:

"Compiled (binary) files that were created using earlier versions of ASP.NET will also run without errors on ASP.NET 4"

http://www.asp.net/learn/whitepapers/aspnet4/breaking-changes

But if the person is going to be doing development with BE 2.0 and .NET 4.0, then this recompilation to .NET 4.0 is of course a very good idea.

For some reason, I'm having issues using the ASP.NET Admin panel to add users to the site... It's having issues with the web.config line pertaining to the XmlRoleProvider.

Any ideas on how I can fix this problem? IIS is working, and the blog appears to be rendering just fine, but I can't add administrators or editors to get this thing deployable.

Yes, agree. Or, as in my case - when you need integration with another application that uses .NET 4.0

Just make sure to point out that people who commit changes to the project shouldn't commit the project as .Net 4, or include .Net 4 specific features!

Thank you for your help. I followed your directions on discountASP.net and it worked well. This was my first time ever to work with ASP pages and Visual Studio and the hosting service and am pleased that things went quite well. Thank you.

Hi Ruslan,

Perhaps you could explain the changes to web.config and why are they are necessary?

Cheers

I haven't look into it closely yet, just took configuration file created by Ben and use it. I've seen discussions on Codeplex where people were running into issues with .net 4.0 and this config file was created based on those issues and supposed to fix them.
Wanted link to discussion thread, but couldn't find - search function on Codeplex useless, sometimes I feel as getting random results.

United States Kris Golko (neuromancer)

It worked for me without any modification while using ASP.NET 4.0 Classic. Switching to ASP.NET 4.0 gave the bloody mess as reported on Codeplex (related to "rights" attribute in the sitemap.

Cheers

I am now running 4 blog engine sites on Server 2008 R2 with IIS 7.5 and ASP 4.  The system uses Plesk which made a few things tricky.

1)  The new version of Blog Engine includes an ASP.NET 4 web config. file.  Use it and it works perfectly.
2)  If running Plesk be sure the Plesk WP User is the account that has write access to the 'ap data' folder.

Check out the site:  www.greenbenefits.org - ASP.NET4.

jch

Thanks for this post.

I get an error: Unable to load one or more of the requested types

I've added update to the post about this error. It could be that I made this change just to the fork I've been working with or it got overridden later on.

Ruslan, thank you very much.  Works like a charm!

Thanks so much, got me up and running without a hitch! Much appreciated.

Ruslan,

I downloaded the latest build for 2.5.  I opened the solution in VS2010 and compiled. Everything went well.

Moved it over to my host, ran the SQL 2.5 script.  Page comes up, but it will not login.

Any suggestions?

Make sure you are using database provider for Membership and Roles in the web.config. Although, Ben is still working on 2.5 scripts - could be something he did not implemented yet.

Pingbacks and trackbacks (2)+

Comments are closed