Farravid
Farravid

Reputation: 41

Current solution contains incorrect configurations mapping using Premake5 with C#

I'm trying to develop an engine and I was looking for a GUI library in C# in order to build the editor for my engine. I found Avalonia but I'm having some problems setting up the whole environment.

I'm using Premake5 as build tool mixing C++ and C# but I think the problem here is not the languages mixing.

enter image description here

I'm getting this error when I generate my visual studio solution file. Sorry about the image, I needed to post it that way cause when I press the "Open Configuration Manager" the error is gone and exit the Configuration Manager window the compilation works as expected, quite weird.

Here's my code: This is the premake5 script I run:

include "Dependencies.lua"

workspace "LeafEngine"
    startproject "LeafEditor"

    configurations { "Debug", "Release" }
    platforms { "x64" }
    flags { "MultiProcessorCompile" }
    
    outputdir = "%{cfg.buildcfg}-%{cfg.system}-%{cfg.platform}"

group "Dependencies"
    include "Leaf/vendor/glfw"
    include "Leaf/vendor/imgui"
group ""

include "Leaf"
include "LeafEditor"
include "LeafGame"

Leaf is my C++ engine and LeafGame just a C++ test. Leaf editor is the C# project, which looks like this:

project "LeafEditor"
    kind "WindowedApp"
    language "C#"
    clr "On"

    targetdir   ("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
    objdir      ("%{wks.location}/bin-obj/" .. outputdir .. "/%{prj.name}")

    dotnetframework "net6.0"

    nuget { "Avalonia:0.10.13", "Avalonia.Desktop:0.10.13",
            "Avalonia.Diagnostics:0.10.13", "Avalonia.ReactiveUI:0.10.13",
            "XamlNameReferenceGenerator:1.3.4"
          }

    files
    {
        "src/**.cs",
        "src/**.xaml",
        "src/**.xaml.cs",
    }

    links
    {
        "Microsoft.CodeAnalysis.CSharp.NetAnalyzers",
        "Microsoft.CodeAnalysis.NetAnalyzers",
        "System.Text.Json.SourceGeneration",
        "Microsoft.NETCore.APP",
    }

filter "system:Windows"
    defines "LF_WINDOWS"
    
filter "system:Unix"
    defines "LF_LINUX"

filter "configurations:Debug"
    defines "LF_DEBUG"
    runtime "Debug"
    symbols "on"

filter "configurations:Release"
    defines "LF_RELEASE"
    runtime "Release"
    optimize "full"

Another curious thing about Avalonia: as you can see I only have one available platform ("x64") for building. Well, Avalonia compiles with ("Any CPU") platform and that also breaks my whole building set up. Besides, Avalonia gets compiled with Any CPU when I load the project not when I compile the project, is that right?

Thanks in advance, this error is killling me.

Upvotes: 1

Views: 2659

Answers (1)

TigerCipher
TigerCipher

Reputation: 63

I just had the same issue, both when my C# project was built with premake and with it as an external project.

The solution (granted I gave up on premake for C# so this may only apply to externalproject) is to not add architecture or any specific platform to your workspace, and instead add it to all but your C# project. I would leave a comment since this might not be the answer you're looking for, but I don't have enough reputation. Anyway, for example,

    workspace "Lotus"
    startproject "LotusEditor"

    configurations
    {
        "Debug",
        "Release"
    }
project "CppProject"
architecture "x86_64" -- sets CppProject as x64 but not the workspace
-- more project config

externalproject "CsProject" -- no architecture/platform set for this. Might work for non externalprojects too
location "path"
uuid "insert uuid"
kind "WindowedApp"
language "C#"

Even with my project made manually not with premake, and set with target platform as x64, it still seems to want "Any CPU" as the configuration, which premake can't do.

Upvotes: 1

Related Questions