Project reference conditional include with multiple conditions
Asked Answered
T

1

95

Here's a snippet from my csproj file:

<ProjectReference Include="..\program_data\program_data.csproj" Condition="'$(Configuration)'=='Debug'">
      <Project>{4F9034E0-B8E3-448E-8794-CF9B9A5E7D46}</Project>
      <Name>program_data</Name>
</ProjectReference>

What I'd like to do is include program_data.dll for multiple build configurations, for example, both Release and Debug.

I tried doing the following

Condition="'$(Configuration)'=='Debug' || '$(Configuration)'=='Release'"

but Visual Studio chokes on this.

Is there a way I can do this, or must I have a separate <ProjectReference> for each build config?

Tiddly answered 10/6, 2011 at 21:10 Comment(0)
K
150

You should use Or, not ||:

Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'"
Kaye answered 10/6, 2011 at 21:13 Comment(8)
@Charlie - I have linked to the MSBuild conditionals documentation.Kaye
I noticed that, thanks. I find the MSDN library can be tricky unless you know what you're looking for.Tiddly
If you want your reference work for both Release and Debug, and you don't have any other configurations, it is simpler to make your ProjectReference unconditional by removing the "Condition" attribute.Toland
@Toland I would imagine they have more than just Debug and Release, otherwise no need for the question. I have a few solutions that also have Debug MONO and Release MONO.Fluoride
Can I have my own Condition? in case I only want to reference this library in case that condition is set? and if so how do I set itHemia
@SaherAhwal - I think this is possible. But you will need to pass in the conditions to the build. Your code would have to be able to compile differently as well, depending on this condition (which is not as straight forward, I believe). I suggest taking a deeper look into MSBuild, the build system that uses these.Kaye
thanks I was able to do it here #63541257Hemia
You can also use andFefeal

© 2022 - 2024 — McMap. All rights reserved.