Help with Hello World Module

Topics: General, Troubleshooting
Aug 3, 2011 at 5:55 PM

Hi, I tried to start out trying the Hello World sample module but unable to get the CodeGeneration step working.  Here are the steps that I did:

1 - Loaded the Solution file in VS 2010 and pressed Ctrl + F5 to run.
2 - I followed the Command-Line Code Gen direction page (which has old version screen shots, I believe).  I went into the Modules | Gallery and installed the Code Gen module.  It stated that it installed properly
3 - I see the new module Orchard.CodeGeneration and files inside VS2010 but when I went into Windows Explorer, there is no such folder or module existed.
4 - I tried saving the project after exiting browser that ran from Ctrl + F5 but it wouldn't let me, saying no such folder existed.
5 - So I created the Folder Orchard.CodeGeneration manually but the only thing saved are 2 files, which had the .proj file extension in 1
6 - I tried Ctrl + F5 again but this time the compiler errored out and asked if I want to run the previous good compiled version. 
7 - I chose Yes, and now exited the browser after failing to reinstall the CodeGeneration module.  In Windows Explorer, the folder I manually created: Orchard.CodeGeneration is now gone.

What do I need to do to properly install the CodeGeneration tool and get the source files for it?

Thank you

Coordinator
Aug 3, 2011 at 6:43 PM

The module is under src/Orchard.Web/Modules but that's not how you run it. You need to open a command-line, go to the src/Orchard.Web directory and type bin\orchard. From that point on, you can enter Orchard commands, including the code generation ones.

Aug 3, 2011 at 7:10 PM

I reset my solution file, loaded in VS 2010 and did the initial setting with Ctrl + F5.  It asks for the initial settings and then I ran the command-line.  It reported this error:

Y:\Orchard 1.2.41\src\Orchard.Web>bin\orchard
Initializing Orchard session. (This might take a few seconds...)
log4net:ERROR [OrchardFileAppender] Unable to acquire lock on file Y:\Orchard 1.
2.41\src\Orchard.Web\App_Data\Logs\orchard-error-2011.08.03.log. The process can
not access the file 'Y:\Orchard 1.2.41\src\Orchard.Web\App_Data\Logs\orchard-err
or-2011.08.03.log' because it is being used by another process.
log4net:ERROR OrchardFileAppender: Failed to open [Y:\Orchard 1.2.41\src\Orchard
.Web\App_Data\Logs\orchard-error]. Attempting [Y:\Orchard 1.2.41\src\Orchard.Web
\App_Data\Logs\orchard-error-1] instead.
log4net:ERROR [OrchardFileAppender] Unable to acquire lock on file Y:\Orchard 1.
2.41\src\Orchard.Web\App_Data\Logs\orchard-debug-2011.08.03.log. The process can
not access the file 'Y:\Orchard 1.2.41\src\Orchard.Web\App_Data\Logs\orchard-deb
ug-2011.08.03.log' because it is being used by another process.
log4net:ERROR OrchardFileAppender: Failed to open [Y:\Orchard 1.2.41\src\Orchard
.Web\App_Data\Logs\orchard-debug]. Attempting [Y:\Orchard 1.2.41\src\Orchard.Web
\App_Data\Logs\orchard-debug-1] instead.
Type "?" for help, "exit" to exit, "cls" to clear screen

Did I do something incorrectly?

Coordinator
Aug 3, 2011 at 7:14 PM

No, that sometimes happen and can be safely ignored. These are warnings, not errors.

Aug 3, 2011 at 7:27 PM

Perfect!  It worked! :D Thanks!  See below (well, I'm sure it's no surprise to you but still... :D) :

orchard> feature enable Orchard.CodeGeneration
Enabling features Orchard.CodeGeneration
Code Generation was enabled

orchard> codegen module HelloWorld
Creating Module HelloWorld
Module HelloWorld created successfully

Coordinator
Aug 3, 2011 at 8:01 PM

Great!

Aug 3, 2011 at 9:01 PM
Edited Aug 3, 2011 at 9:12 PM

I noticed your instruction online to create the HomeController for HelloWorld has this much codes:

    [Themed]
    public class HomeController : Controller {
        public ActionResult Index() {
            return View("HelloWorld");

versus the one in the sample downloaded project has more:

    [Themed]
    public class HomeController : Controller {
        public IOrchardServices Services { get; set; }

        public HomeController(IOrchardServices services) {
            Services = services;
            T = NullLocalizer.Instance;
        }

        public Localizer T { get; set; }

        public ActionResult Index() {
            return View("HelloWorld");
        }

Is there something different changed that is required to be implemented; is that why the extra methods?

Does this mean future modules will go through the same steps in terms of adding those changes to the "csproj" file as well?  No extra steps for adding a module that uses a Model?

Thank you

Coordinator
Aug 3, 2011 at 9:21 PM

No, the difference is essentially plumbing that will become useful at the moment you go beyond hello world. T is going to make text localizable, and services will give you access to some useful Orchard environmental objects. In any case, you will also be able to inject implementations of many other interfaces into your code using similar techniques.

Aug 3, 2011 at 9:41 PM

I followed the instructions and enabled HelloWorld.  But everytime I ran the project using Ctrl + F5, I get this error:

The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly.

Requested URL: /OrchardLocal/helloworld

I do notice a difference in your instructions online and the codes in the project file:

- HelloWorld.csproj in the Source Codes has:
  <ItemGroup>
    <None Include="Views\HelloWorld.cshtml" />

- Online Instructions said to add:
    <Content Include="Views\Home\HelloWorld.cshtml" />

I modified my HelloWorld.csproj to say:
    <Content Include="Views\HelloWorld.cshtml" />
since the .cshtml is in the Views folder and not under Views\Home

Did I do something incorrectly?

Coordinator
Aug 3, 2011 at 9:43 PM

It doesn't find your controller for some reason.

Aug 3, 2011 at 9:52 PM

Yes, and I don't know why.  Been searching where I went wrong but not seeing it at the moment.  Did I do the modification correctly since the project source codes and the online tutorial are different?

Aug 3, 2011 at 11:06 PM

Started over and got it working!  Thanks, Bertrandleroy! :D  I see how it shows up at least