visual-studio-2019monogameproject-templatepremake

Is there a way to make Premake use Visual-Studio Project templates?


I am trying to create a premake5.lua file for a Visual-Studio C# MonoGame project. I want to be able to make premake use the MonoGame project-template, instead of me having to manually dig through all the stuff that template creates for me and then putting that into premake. Currently I have the following premake5.lua file, which produces a project that compiles but has exceptions when running it...


workspace "TilemapEditor"
    architecture "x86"
    startproject "TilemapEditor"

    configurations
    {
        "Debug",
        "Release",
        "Distribution"
    }

outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.architecture}"

project "TilemapEditor"
    location "TilemapEditor"
    kind "WindowedApp"
    language "C#"
    links {"MonoGame.Framework", "System", "System.Windows.Forms", "System.Xml"}

    targetdir ("bin/" .. outputdir .. "/%{prj.name}")
    objdir ("bin-int/" .. outputdir .. "/%{prj.name}")

    files { "%{prj.name}/src/**.cs", "Properties/AssemblyInfo.cs" }

    defines { "WINDOWS" }
    dotnetframework ("4.5")

    filter "configurations:Debug"
        symbols "On"

    filter "configurations:Release"
        symbols "Off"

I haven't found any function in the premake wiki that can do this.


Solution

  • No, not really. Premake is writing the full project from scratch, and not "filling in the blanks" from an existing project. Your best bet will be to diff the projects generated from Premake and the MonoGame template and tweak the settings in your Premake script to match. Once you've done that, it is pretty easy to create a function you can reuse to apply the same settings to different projects. Maybe something like:

    function monoGameSettings()
       -- put your MonoGame baseline settings here
       filter {}  -- finish with this to close any opened filter blocks
    end
    
    -- use it like...
    project 'MyProject'
        monoGameSettings()