premake-core icon indicating copy to clipboard operation
premake-core copied to clipboard

premake generating incorrect <TargetFramework/> for C++/CLI with .NET Core

Open ddobrev opened this issue 3 years ago • 3 comments

What seems to be the problem? Creating a C++/CLI project targeting .NET Core with premake produces <TargetFramework>vnetcoreapp3.1</TargetFramework> in the project file.

What did you expect to happen? premake produces <TargetFramework>netcoreapp3.1</TargetFramework> in the project file.

What have you tried so far?

premake.override(premake.vstudio.vc2010, "targetFramework", function(oldfn, prj)
  if string.endswith(prj.filename, ".CLI") then 
    local action = p.action.current()
    local tools = string.format(' ToolsVersion="%s"', action.vstudio.toolsVersion)
    local framework = prj.dotnetframework or action.vstudio.targetFramework or "4.0"
    p.w('<TargetFramework>%s</TargetFramework>', framework)  
  end
end)

How can we reproduce this? Any premake project for C++/CLI targeting .NET Core.

What version of Premake are you using? Latest master at the time of writing.

Anything else we should know? The problem, as evident by the successful workaround, is in your function of premake.vstudio.vc2010.targetFramework. It has a hard-coded v.

ddobrev avatar Nov 20 '20 20:11 ddobrev

In the C# net core support, I added dotnetbase.isNewFormatProject(cfg) to check whether we're targeting framework or net core. So maybe someone needs replace https://github.com/premake/premake-core/blob/c6580ff1cefa7660a0df59f3da90dff0bf1be417/modules/vstudio/vs2010_vcxproj.lua#L118 with the below

if framework and dotnetbase.isNewFormatProject(prj) then
	p.w('<TargetFrameworkVersion>%s</TargetFrameworkVersion>', framework)
else
	p.w('<TargetFrameworkVersion>v%s</TargetFrameworkVersion>', framework)  
end

I'd do it, but I don't have a working machine at the moment...

ClxS avatar Nov 26 '20 14:11 ClxS

Hi, I'm running into a similar issue now with the following being outputted and causing loading issues: <TargetFrameworkVersion>vnet5.0</TargetFrameworkVersion>

Instead of how it should be: <TargetFramework>net5.0</TargetFramework>

This is generated from the following premake script:

project "SHADE_Managed"
  kind "SharedLib"
  language "C++"
  clr "NetCore"
  dotnetframework "net5.0"
  cppdialect "C++17"

Pycorax avatar Sep 12 '22 08:09 Pycorax

@ClxS I have attempted a fix for this based on your suggestion and the expected fix for .NET 5.0. However, dotnetbase.isNewFormatProject(cfg) does not seem to be present. I'm not very familiar with Lua, would it be possible for you to share how I might go about adding that in?

Pycorax avatar Oct 15 '22 10:10 Pycorax

@Pycorax Is this using premake.override, or are you modifying the Premake code to submit a fix for this?

samsinsane avatar Oct 23 '22 06:10 samsinsane

@samsinsane I'm currently modifying the source code in the modules/vstudio/vs2010_vcxproj.lua file. I can verify that without the conditional check, it fixes this issue but ends up breaking existing test cases for non-.NET 5.0+ projects.

Pycorax avatar Oct 23 '22 06:10 Pycorax

You'll need to add local dotnetbase = p.vstudio.dotnetbase near the top of vs2010_vcxproj.lua.

samsinsane avatar Oct 23 '22 06:10 samsinsane