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

Add configuration condition to VS csproj references ItemGroup #1723

Merged
merged 1 commit into from
Oct 20, 2021

Conversation

cicanci
Copy link
Contributor

@cicanci cicanci commented Sep 28, 2021

What does this PR do?

Consider the following premake5.lua script line:

links { "bin/%{cfg.platform}/%{cfg.buildcfg}/MyLib.Sharp.dll" }

If you have more than one optimizations it will only consider the first one found. So, for example, if you have Debug and Release optimizations, the only DLL linked will be the Debug one, resulting in the following VS csproj configuration:

<ItemGroup>
  <Reference Include="MyLib.Sharp">
  <HintPath>..\..\bin\x64\Debug\MyLib.Sharp.dll</HintPath>
  </Reference>
</ItemGroup>

The changes in this PR make it possible to apply the same condition used in the <PropertyGroup> to the <ItemGroup> when linking a DLL in a VS csproj, resulting in the following VS csproj configuration (considering the previous example).

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <Reference Include="MyLib.Sharp">
  <HintPath>..\..\bin\x64\Debug\MyLib.Sharp.dll</HintPath>
  </Reference>
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
  <Reference Include="MyLib.Sharp">
  <HintPath>..\..\bin\x64\Release\MyLib.Sharp.dll</HintPath>
  </Reference>
</ItemGroup>

How does this PR change Premake's behavior?

After this PR, any VS csproj that links a DLL will have the condition applied for each optimization defined. For example, if only Debug is used, the VS csproj will change from this:

<ItemGroup>
  <Reference Include="MyLib.Sharp">
  <HintPath>..\..\bin\x64\Debug\MyLib.Sharp.dll</HintPath>
  </Reference>
</ItemGroup>

To this:

<ItemGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
  <Reference Include="MyLib.Sharp">
  <HintPath>..\..\bin\x64\Debug\MyLib.Sharp.dll</HintPath>
  </Reference>
</ItemGroup>

Anything else we should know?

Not really, the changes are pretty straight forward.

Did you check all the boxes?

  • Focus on a single fix or feature; remove any unrelated formatting or code changes
  • Add unit tests showing fix or feature works; all tests pass
  • Mention any related issues (put closes #XXXX in comment to auto-close issue when PR is merged)
  • Follow our coding conventions
  • Minimize the number of commits
  • Align documentation to your changes

You can now support Premake on our OpenCollective. Your contributions help us spend more time responding to requests like these!

@nickclark2016
Copy link
Member

Looks like we have tests failing here. Please investigate why these tests are failing, resolve the failures, and then add unit testing for the new piece of functionality.

@starkos starkos changed the title Adds condition to the VS csproj ItemGroup when linking with a DLL Add configuration condition to VS csproj references ItemGroup Sep 30, 2021
@starkos
Copy link
Member

starkos commented Sep 30, 2021

Also, if you could squash your changes down to a single commit (you can force push to this branch to overwrite the previous commits) it will make it easier for us to merge it. Thanks!

@cicanci cicanci force-pushed the feature/vs-item-group-condition branch from a59bc4b to cd276f8 Compare October 18, 2021 20:41
@cicanci cicanci requested a review from starkos October 18, 2021 20:43
@starkos starkos merged commit 50051b9 into premake:master Oct 20, 2021
@starkos
Copy link
Member

starkos commented Oct 20, 2021

Merged, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants