If I have a <ProjectReference>
reference, is there any way to pass a conditional compilation value to that project? Something like this (I know <DefineConstants>
doesn't exist like this, it's just to illustrate the need):
<ProjectReference Include="..\DataProducer\DataProducer.csproj">
<DefineConstants>WAS_SET</DefineConstants>
<ProjectReference>
Therefore, if there's a class in that project like this:
public sealed class ProduceValue
{
public string Produce()
{
#if WAS_SET
return "WAS SET";
#else
return "NOTHING WAS SET";
#endif
}
}
Then by passing that value during compilation or not, I could get different output.
A project reference is a link from the current Studio project to another project. The reference makes certain resources in the referenced project become available for use in the current project.
The ProjectReference
item allows adding the metadata fields Properties
and UndefineProperties
to allow maninpulating the set of "global" properties that are used to build project references. You could make use of this by passing in a global property to the referenced project like this:
<ProjectReference Include="..\DataProducer\DataProducer.csproj">
<Properties>DefineConstants=WAS_SET</Properties>
<ProjectReference>
The effect of this now being a global property to the referenced project is that it will override any definition/update of DefineConstants
defined statically in the project - this may also include any added configuration constant (DEBUG
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With