Skip to content

PrivateAssets="All" breaks Android apps #47332

Open
@Kira-NT

Description

@Kira-NT

Description

Hi! I'm developing a hot reload plugin for a UI framework. Well, technically, it's already done, and now I'm faced with the real challenge - packaging it.

Naturally, since my package is designed as a development-only dependency, I pack it with -p:DevelopmentDependency=true. Thus, when users install it, the following snippet is added to their project file:

<PackageReference Include="Foo" Version="...">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>

which is equivalent to:

<PackageReference Include="Foo" Version="..." PrivateAssets="All" />

And everything behaves properly whenever the plugin is used with a desktop application, whether it's created via dotnet build or dotnet run.

However, the moment I try to run an Android app via dotnet run, it instantly crashes with a cryptic FileNotFoundException, signifying that the satellite library required for debug builds to function has not been included in the resulting bundle. As far as I understand after four days of digging through the best documentation I have on this topic (i.e., the sources of this repo and eight-year-old issues), this happens because dotnet run for Android builds actually uses the publish routine to generate the output that gets uploaded to the device; and the SDK by default sets Publish="false" for every PackageReference that has its PrivateAssets set to all, causing development-only dependencies to go missing, even though the intent was not to publish the app, but to create a development build for debugging purposes.

Workarounds

The ugly workaround would be to ask users to install the plugin by manually editing their project files and inserting the following snippet there:

<PackageReference Include="Foo" Version="..." PrivateAssets="All" Publish="True" />

It's "ugly" because:

  1. Nobody reads documentation these days, so this will just lead to an endless stream of "No work! Crash! How fix?" issues in my repo.
  2. This doesn't actually represent the proper intent of what I'm trying to achieve. I do not want my satellite library to be copied to users' published builds. It's only needed for regular debug builds, which I expect Android builds created by dotnet run to be. However, those unexpectedly differ in semantics from the desktop ones.

Sooooo... Are there any somewhat proper workarounds I can employ within the .props/.targets distributed with my nuget, so that users can simply run dotnet add package Foo and expect everything to work as intended?

Related Issues

#27211
#1019
#952

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions