Version 3 (modified by Charles, 5 years ago)



Let's say your company name is MyCompany and your project is called MyProject. You want to put most of your code for the project in a library, with a small console program to provide a command line interface to it.

Here are the steps.

Create a New Solution with Library Project

  • Launch Xamarin Studio 4.2.3
  • File > New > Solution
  • Choose Cobra > Console Project
  • Give a name like "MyCompany.MyProject.Lib" in the "Name:" field
  • Edit the "Solution name:" field to chop off the ".Lib" to make it "MyCompany.MyProject"
  • Leave "Create directory for solution" checked.
  • Click "OK"
  • Edit the class:
class Thing


    get two as int
        return 2

Create Console Project

  • In the solution outline, the very top node says "MyCompany.MyProject"
  • Right click it and choose Add > Add New Project
  • Choose Cobra > Console Project
  • Give a name like "MyCompany.MyProject.Console" in the "Name:" field.
  • Right click in the new project in the solution outline and choose "Set As Startup Project"
  • Open Program.cobra in the solution outline and add "Console.readLine":
Replace this text with a description of your program.

class Program

    def main
        print 'Hello, world!'
        Console.readLine  # <--- add this

Copy the Core

I like to copy Cobra's core library to co-reside with my program. This insulates it from the environment.

  • Right click "MyCompany?.MyProject?.Console" and choose "Options"
  • Choose "Compiler"
  • Make sure "Embed Run Time" is unchecked
  • Add "-copy-core" to the "Cobra Arguments:"
  • Click "OK"

Run It

  • Try running the project.
    • If you get an error about System.Core, expand the References of the Console project in the solution outline, right click and choose "Delete".