In .csproj
files one can specify that specific files should not be compiled when a defined condition is met. For example the following code would exclude (thus not compile) SomeFileA, B and C if the target framework is net35.
<ItemGroup Condition=" '$(TargetFramework)' == 'net35'"><Compile Remove="Some\Folder\SomeFileA.cs" /><Compile Remove="Some\Folder\SomeFileB.cs" /><Compile Remove="Some\Folder\SomeFileC.cs" /></ItemGroup>
My question is if something like this can somehow also be achieved for if a specific NuGet package is referenced in a project referencing this project.
Background: I'm developing a library (further calling it FW) that I want to publish as a NuGet package in a private package source. All but one file (X) in FW work without references to any other NuGet package. This one file needs the NuGet package ABC to work. FW should later be referenced by various of my (and my coworkers) projects. But not all of these projects will need the functionality provided by file X. Therefore my idea was that I let the creator of a project (referencing FW) decide if he wants to use the functionality of file X by manually referencing NuGet package ABC or not. Depending on this (existing or missing) reference to ABC I want the file X to be compiled (existing) or not (missing).
I know, the bestestest way would propably be to create a separate project (FW.X) that references FW and ABC and create a separate NuGet package for it, so the project creator can decide to reference FW or FW.X but that's too much overhead for my use-case.