Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configuration filters don't work correctly for postbuildcommands in C# projects #2214

Open
jsmrcina opened this issue May 27, 2024 · 1 comment · May be fixed by #2215
Open

Configuration filters don't work correctly for postbuildcommands in C# projects #2214

jsmrcina opened this issue May 27, 2024 · 1 comment · May be fixed by #2215
Labels

Comments

@jsmrcina
Copy link

What seems to be the problem?
In the example below, I would expect there to be a PropertyGroup which contains the PostBuildEvent for each configuration. Instead, the generated csproj contains only a single un-filtered PropertyGroup that has the PostBuildEvent for echoing "Debug" and no PropertyGroup that has the PostBuildEvent for echoing "Release".

In contrast, the other properties, such as "symbols" and "optimize", are correctly placed into filtered property groups.

premake.lua

workspace "premaketest"
   configurations { "Debug", "Release" }
   platforms { "AnyCPU" }

project "testproject"
   kind "ConsoleApp"
   language "C#"

   files { "src/*.cs" }

   filter { "configurations:Debug" }
      symbols "On"
      optimize "Off"
      postbuildcommands {
         "{ECHO} Debug"
      }

   filter { "configurations:Release" }
      symbols "Off"
      optimize "On"
      postbuildcommands {
         "{ECHO} Release"
      }

Generated csproj

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{DC8BCD12-4841-4608-D135-40DF3DEA3C0C}</ProjectGuid>
    <OutputType>Exe</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>testproject</RootNamespace>
    <AssemblyName>testproject</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug AnyCPU|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <DebugSymbols>true</DebugSymbols>
    <Optimize>false</Optimize>
    <OutputPath>bin\AnyCPU\Debug\</OutputPath>
    <BaseIntermediateOutputPath>obj\AnyCPU\Debug\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
    <DefineConstants></DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release AnyCPU|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>none</DebugType>
    <DebugSymbols>false</DebugSymbols>
    <Optimize>true</Optimize>
    <OutputPath>bin\AnyCPU\Release\</OutputPath>
    <BaseIntermediateOutputPath>obj\AnyCPU\Release\</BaseIntermediateOutputPath>
    <IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
    <DefineConstants></DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug AnyCPU|AnyCPU' ">
  </ItemGroup>
  <ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release AnyCPU|AnyCPU' ">
  </ItemGroup>
  <ItemGroup>
  </ItemGroup>
  <ItemGroup>
  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <PropertyGroup>
    <PostBuildEvent>echo Debug</PostBuildEvent>
  </PropertyGroup>
</Project>

What did you expect to happen?
I expected to have two separate sets of post build commands that are filtered by each configuration.

What have you tried so far?
I verified that other properties are being filtered correctly, and I verified that this isn't an issue in C++ projects.

How can we reproduce this?
I am generating for VS2022, as follows:

>> .\premake5.exe vs2022
Building configurations...
Running action 'vs2022'...
Generated testproject.csproj...
Done (24ms).

What version of Premake are you using?

>> .\premake5.exe --help
Premake 5.0.0-beta2, a build script generator
Copyright (C) 2002-2021 Jason Perkins and the Premake Project
Lua 5.3 Lua 5.3.5  Copyright (C) 1994-2018 Lua.org, PUC-Rio

Anything else we should know?
Nothing else that I can think of. I looked through existing issues and didn't see one filed for this. Please let me know if there's anything else I can provide to help diagnose the problem. Thank you!

@jsmrcina jsmrcina added the bug label May 27, 2024
@mendsley
Copy link
Contributor

Looks like this is the main culprit

local cfg = project.getfirstconfig(prj)
if #cfg.prebuildcommands > 0 or #cfg.postbuildcommands > 0 then
_p(1,'<PropertyGroup>')
output("Pre", cfg.prebuildcommands)
output("Post", cfg.postbuildcommands)
_p(1,'</PropertyGroup>')
end

I'm guessing that should be looping over each configuration and adding the configuration's condition with something like:
p.push('<PropertyGroup %s>', dotnetbase.condition(cfg))

mendsley added a commit to mendsley/premake-core that referenced this issue May 28, 2024
mendsley added a commit to mendsley/premake-core that referenced this issue May 28, 2024
mendsley added a commit to mendsley/premake-core that referenced this issue May 28, 2024
@mendsley mendsley linked a pull request May 28, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants