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

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

Open jsmrcina opened this issue 1 month ago • 1 comments

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 avatar May 27 '24 07:05 jsmrcina