premake / premake-core

Premake
https://premake.github.io/
BSD 3-Clause "New" or "Revised" License
3.13k stars 611 forks source link

Generating C# projects does not set the platform target correctly #1963

Open Pycorax opened 1 year ago

Pycorax commented 1 year ago

What seems to be the problem? Generating a C# project using premake does not specify the "Platform Targets" property for the project when an architecture is specified. This results in projects being still marked as "AnyCPU" regardless of the specified architecture.

What did you expect to happen? The generated csproj should contain a "Platforms" tag in the condition-less PropertyGroup. For example, if the architecture is x64, it should have the following tag: <Platforms>x64</Platforms>.

What have you tried so far? Manually inserting the <Platforms>x64</Platforms> tag.

How can we reproduce this? Only tested with VS 2019 so far with the following premake file.

project "SHADE_CSharp"
  architecture "x64"
  kind "SharedLib"
  language "C#"
  clr "NetCore"
  dotnetframework "net5.0"
  targetdir (outputdir)
  objdir    (interdir)
  systemversion "latest"

  files  
  {
    "%{prj.location}/src/**.cs",
    "%{prj.location}/src/**.tt"
  }

  flags
  {
    "MultiProcessorCompile"
  }

  dependson
  {
    "SHADE_Engine"
  }

  warnings 'Extra'

  filter "configurations:Debug"
    symbols "On"
    defines {"_DEBUG"}

  filter "configurations:Release"
    optimize "On"
    defines{"_RELEASE"}

What version of Premake are you using? 5.0.0-beta2

Anything else we should know? None

samsinsane commented 1 year ago

Does using x86_64 for the architecture instead of x64 work?

Pycorax commented 1 year ago

@samsinsane Nope, that doesn't seem to work either

samsinsane commented 1 year ago

I've had a look into this and it looks like we don't support the platforms/architecture APIs for the new .NET project format. As a workaround, you can inject the element using:

require "vstudio"

local platformsElement(cfg)
  _p(2,'<Platforms>x64</Platforms')
end

premake.override(premake.vstudio.cs2005.elements, "projectProperties", function (oldfn, cfg)
  return table.join(oldfn(cfg), {
    platformsElement,
  })
end)
Pycorax commented 1 year ago

@samsinsane Thanks! I looked into overrides and I got an idea of what you're suggesting here. I've appended it to the bottom of my file but, it is indicating that _p inside platformsElement() seems to be undefined?

The error: premake5.lua:40: syntax error near 'p'

Pycorax commented 1 year ago

After looking into it further, I managed to fix it by replacing the local keyword for platformsElement()'s definition with function. I'm not sure if this is the correct way though.

JohnathanRvT commented 1 year ago

Any idea if it will be implemented? @samsinsane

samsinsane commented 1 year ago

@Pycorax Sorry about that, looks like I made a typo while typing up the snippet - I think I meant to do local function which limits the function to the current .lua file. Glad you were able to figure out the problem with it and get it working.

@JohnathanRvT It's been awhile since I've looked at this, but I think #1899 fixes this. So, should be "soon".