= Creating a New Project in Xamarin Studio = == Introduction == Let's say: * You're developing a new project in Cobra * You're using the XamarinStudio IDE * Your company name is '''!MyCompany''' * Your new project will be 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 done with XamarinStudio 4.2.3 on Windows. == Create a New Solution with Library Project == * Launch Xamarin Studio * File > New > Solution * Choose Cobra > Library 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: {{{ #!cobra class Thing test pass 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": {{{ #!cobra 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 "Build" > "Compiler" * Make sure "Embed Run Time" is unchecked * Add "-copy-core" to the "Cobra Arguments:" * Click "OK" == Run It == Try running the project. * Choose from the menu, Run > Start Without Debugging * If you get an error about System.Core, expand the References of the Console project in the solution outline, right click and choose "Delete". You should see output like: {{{ Hello, world! trace : t.two=2 - at Program.cobra:14 - in Program.main }}} Press "Return" to continue. == Build Files == In the file system, you will now have these files: {{{ > cd MyCompany.MyProject\MyCompany.MyProject.Console\bin\Debug > dir Cobra.Core.dll MyCompany.MyProject.Console.exe MyCompany.MyProject.Console.pdb MyCompany.MyProject.Lib.dll MyCompany.MyProject.Lib.pdb }}} You can run the program outside of Xamarin Studio and Cobra: {{{ > MyCompany.MyProject.Console Hello, world! trace : t.two=2 - at Program.cobra:14 - in Program.main }}} Press "Return" to continue. You can remove the "Console.readLine" from the program. It's there so that when you run the program from the IDE, the new output window will be "paused" so you can read it. == Default Namespaces == The Cobra language has [wiki:Namespace namespaces] which are either declared in code: {{{ #!cobra namespace MyCompany.MyProject.Lib class Thing pass }}} Or specified on the command line: {{{ cobra -default-namespace:MyCompany.MyProject.Lib ... }}} In the IDE, you can right click the project and choose "Options" > "General" > "Main Settings" and see a field for "Default Namespace". New projects in Xamarin Studio have this configured to match the project name. You can change it or clear it out as you prefer. == Where to go from here == * You can now start fleshing out your library. * You can use that library from the console program. * You can later use that library in a web site, web service or GUI app. * Explore the right click menus in Xamarin Studio. * Try out some breakpoint debugging. * If you get stuck or experience bugs, get on the Cobra discussion forums. * If you see errors on this page, or you have additional tips, edit this page. That's the "wiki way". == See Also == * XamarinStudio * [wiki:IDESupport]