mocha-dotnet/mocha-dotnet-new

67 lines
2.1 KiB
Bash
Executable File

#!/bin/bash
# mocha-dotnet-new
# creates a new DotNet project and adds all the references needed to use
# Mocha from within .NET
MOCHA_DOTNET_LIBRARIES_PATH=/usr/lib/mocha/dotnet
MOCHA_MOCHA_LIBRARIES_PATH=/home/beckermj/Documents/Projects/mochapowered/mocha-dotnet/mocha-common/mocha-common/output
dotnet new console
# dotnet add reference /usr/lib/mocha/dotnet/Mocha.Core.dll
# dotnet add reference /usr/lib/mocha/dotnet/MBS.Core.dll
# link a reference to mocha system libraries
ln -s $MOCHA_MOCHA_LIBRARIES_PATH system
# since we cannot 'dotnet add reference', do it manually - it still works
FILE=*.csproj
ROOT_NAMESPACE=MochaTest1
echo """
<Project Sdk=\"Microsoft.NET.Sdk\">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>$ROOT_NAMESPACE</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Reference Include=\"MBS.Core\">
<HintPath>$MOCHA_DOTNET_LIBRARIES_PATH/MBS.Core.dll</HintPath>
</Reference>
<Reference Include=\"Mocha.Core\">
<HintPath>$MOCHA_DOTNET_LIBRARIES_PATH/Mocha.Core.dll</HintPath>
</Reference>
<Reference Include=\"Mocha.Plugins.Libraries.McxMini\">
<HintPath>$MOCHA_DOTNET_LIBRARIES_PATH/Mocha.Plugins.Libraries.McxMini.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include=\"system\\net.alcetech.Mocha.System.mcl\" />
</ItemGroup>
</Project>
""" > $FILE
FILE=Program.cs
echo """
// See https://get.mochapowered.com/mocha-dotnet-new for more information
Mocha.Core.OmsImplementations.EmbeddedMiniOms oms = new Mocha.Core.OmsImplementations.EmbeddedMiniOms();
oms.SystemLibraryResourceName = null; // \"mocha_test.resources.net.alcetech.Mocha.System.mcl\";
oms.Initialize();
Mocha.Core.LibraryHandle lh = oms.LoadLibrary(\"system/net.alcetech.Mocha.System.mcl\");
oms.AddLibraryReference(lh);
Mocha.Core.InstanceHandle ih = oms.GetInstance(Mocha.Core.KnownInstanceGuids.Classes.Class);
Console.WriteLine(\"Hello, World! The \`Class\` GID is {0}\", oms.GetGlobalIdentifier(ih));
""" > $FILE