Skip to content

Hello World

Guilherme Oliveira edited this page Mar 14, 2019 · 5 revisions

Create a new project

In an empty folder:

dotnet new console

Add reference to Carlo#

dotnet add package CarloSharp

Create a index.html in a new folder named wwwroot

<!DOCTYPE html>
<html>
    <head>
        <title>Carlo# - Hello World</title>
    </head>
    <body>
        Hello World!
    </body>
</html>

Modify the .csproj to copy the html file to the output folder

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>
 
  <!-- Copies wwwroot to the output folder -->
  <ItemGroup>
    <Content Include="wwwroot\*.*">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </Content>  
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="CarloSharp" Version="1.0.4" />
  </ItemGroup>

</Project>

Modify the Program.cs to start Carlo#

using System;
using System.Threading;

namespace CarloSharp.Samples.HelloWorld
{
    class Program
    {
        private static ManualResetEvent _exitEvent = new ManualResetEvent(false);
        
        static void Main(string[] args)
        {
            var app = Carlo.Launch(new Options());

            app.ServeFolder("./wwwroot");

            app.Load("index.html");

            app.Exit += OnAppExit;

            _exitEvent.WaitOne();
        }

        private static void OnAppExit(object sender, EventArgs args)
        {
            _exitEvent.Set();
        }
    }
}

Run the project

dotnet run