87

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?

Charlie Salts
  • 13,109
  • 7
  • 49
  • 78

1 Answers1

141

You should use Or, not ||:

Condition="'$(Configuration)'=='Debug' Or '$(Configuration)'=='Release'"
Oded
  • 489,969
  • 99
  • 883
  • 1,009
  • @Charlie - I have linked to the MSBuild conditionals documentation. – Oded Jun 10 '11 at 21:16
  • I noticed that, thanks. I find the MSDN library can be tricky unless you know *what* you're looking for. – Charlie Salts Jun 10 '11 at 21:29
  • 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. – Oleg Mar 16 '16 at 18:50
  • 1
    @Oleg 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`. – DJH Mar 24 '16 at 10:38
  • 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 it – Saher Ahwal Aug 22 '20 at 20:07
  • @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. – Oded Aug 27 '20 at 18:31
  • thanks I was able to do it here https://stackoverflow.com/questions/63540757/user-defined-condition-variable-for-package-referencing-in-c-sharp-net-core – Saher Ahwal Aug 27 '20 at 23:23
  • You can also use `and` –  Sep 08 '22 at 11:25