Wednesday, April 23, 2008

DotNetNuke custom modules in C#, develop and debug

So for my first blog entry I decided to share my expertise with developing DotNetNuke custom modules in C#.

When I was deciding on architecture for one big DotNetNuke based project I wanted to create custom modules in C# but I had a problem of creating solution i Visual Studio that could be easily debugged and did not require manual coping of *.ascx files.

We used "DotNetNuke C# Compiled Module" that can be downloaded at THIS address

Anyway we had a problem of continuous development, debug and manual copying of the files

So we used Visual Studio projects "Pre build event" property in order to integrate custom module in to DNN solution.

HOW IT WORKS?
  • Create a solution and add DNN as a web site (lets say the DNN folder is "SolutionDir\DNN")
  • Add you custom DNN C# module project
  • Go to the custom module project properties (right click on project etc.)
  • Go to "Build Events"
  • Click "Edit pre-builde..."
  • Insert this script in to the dialog window
rd /S /Q "$(SolutionDir)DNN\DesktopModules\$(ProjectName)"
md "$(SolutionDir)DNN\DesktopModules\$(ProjectName)"
md "$(SolutionDir)DNN\DesktopModules\$(ProjectName)\App_LocalResources"

copy "$(ProjectDir)App_LocalResources\" "$(SolutionDir)DNN\DesktopModules\$(ProjectName)\App_LocalResources"
copy "$(ProjectDir)*.ascx" "$(SolutionDir)DNN\DesktopModules\$(ProjectName)"
copy "$(ProjectDir)*.dnn" "$(SolutionDir)DNN\DesktopModules\$(ProjectName)"
copy "$(ProjectDir)uninstall.*" "$(SolutionDir)DNN\DesktopModules\$(ProjectName)"

What dose this do?
Every time you do a build of the solution you this script will remove the module directory from /DesktopModules/ then create it again with /App_LocalResources/ sub folder, copy all the resx, ascx, dnn and uninstall files to you /DesktopModule/ folder

Restrictions and pitfalls
  • In this scenario your DotNetNuke folder is /DNN/ if it's different just replace "DNN" in the script with your own folder name.
  • Also name of the project must be the same as the module definition name of the folder in DNN if it's different just replace $(ProjectName) with the name of your folder.
  • Also you should put the build path for your custom module in DNN/bin folder
Conclusion
In this way you can use your module as separate project debug them and create a solution that has logical structure.

Write comments I will help you with your problems, I'm that good.

Special tnx to Curia Damiano

DotNetNuke Outsourcing

No comments: