Search code examples
.netvisual-studioxamarin.net-standard

ignore NuGet package from .netstandard ProjectReference


i have the following project structure in a Xamarin project. project structure

a .netstandard library contains NuGet package X which should also be available in project B and C which reference A via ProjectReference in the .csproj.

In Project D i would ignore or exclude the NuGet package coming from the .netstandard A because i have my own implementation for this platform (custom X). How would one set up a scenario like this is the project settings?

EDIT: more info

Package X is a multitargeted NuGet package which has support for the platform of B and C but on D I want to reference my own code.


Solution

  • i ended up using ItemGroup conditions in my .csproj files to include / exclude packages based on the TargetFramework. Works fine for this usecase

    <ItemGroup Condition=" $(TargetFramework.StartsWith('A')) ">
        <PackageReference Include="package-for-A-and-B Version="1.2.3">
        </PackageReference>
    </ItemGroup>
    
    <ItemGroup Condition=" $(TargetFramework.StartsWith('B')) ">
        <PackageReference Include="package-for-A-and-B Version="1.2.3">
        </PackageReference>
    </ItemGroup>
    
    <ItemGroup Condition=" $(TargetFramework.StartsWith('D')) ">
        <PackageReference Include="package-for-D Version="1.2.3">
        </PackageReference>
    </ItemGroup>