Assembly References Getting Added to Every Platform in .NET MAUI

Devi Prasad 91 Reputation points
2022-05-25T06:13:31.5+00:00

If you add an assembly reference to one Platform , it gets added to every Platform.

Steps to Reproduce

Right click on Windows Dependencies
Add a new assembly reference (a local DLL, not a NuGet package)
Observe the assembly was also added to every Platform dependencies (Android, iOS)

Expected Behavior
The added assembly references should only be added to the selected Platform, not to all the Platforms

Basic Information
Visual Studio 2022 version 17.3 Preview 1.1

If you remove an assembly reference form one project, it also gets removed from the other Platforms dependencies.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,843 questions
{count} votes

Accepted answer
  1. Rob Caplan - MSFT 5,412 Reputation points Microsoft Employee
    2022-06-02T22:00:27.15+00:00

    Dependencies are managed at the project level, and adding to all targets is desirable in the common case - a frequent problem in Xamarin was people accidentally adding a reference to only one project and then having the others break.

    If you need to restrict a dependency to specific targets you can edit the csproj to add a condition. For example, this includes ClassLibrary1 only for windows:

    <ItemGroup Condition="$(TargetFramework.Contains('-windows')) != false ">
      <ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" />
    </ItemGroup>
    

    You can file a feature request to provide a way to manage this in the UI at https://developercommunity.visualstudio.com/search?space=8&q=maui

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful