Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uno Class Library with non-Windows TFM can't use <Content Include="..."/> #8266

Closed
Arlodotexe opened this issue Mar 8, 2022 · 6 comments
Closed
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification

Comments

@Arlodotexe
Copy link
Contributor

Arlodotexe commented Mar 8, 2022

Current behavior

If you create an Uno Class Library with some code and a small addition to the .csproj:

image

<ItemGroup>
	<Content Include="**\*.xaml" Exclude="bin\**\*.xaml;obj\**\*.xaml" />
	<Content Include="**\*.cs" Exclude="bin\**\*.cs;obj\**\*.cs" />
</ItemGroup>

This content is included in the build output and can be accessed via StorageFile.GetFileFromApplicationUriAsync() under UWP and WinAppSDK (uap10.0.18362;net6.0-windows10.0.19041.0):

image
image

However, under any other TFMs where Uno.UI is used, including netstandard2.0, net6.0-ios, net6.0-macos ,net6.0-maccatalyst, net6.0-android, and older TFMs that don't use NET6, the content is neither included in the final build nor accessible with StorageFile.GetFileFromApplicationUriAsync():

image

Skia.WPF:
image

Skia.GTK: (WSL)
image

Droid:
image

WebAssembly:
image

Expected behavior

Behavior should be consistent between all platforms.

How to reproduce it (as minimally and precisely as possible)

Attached is a project with a complete, minimal repro of the issue, and should be ready-to-run assuming you've got the proper dependencies and tooling (.NET 6 / MAUI / VS 2022).

This is the same project used to create the screenshots above.
ConsistentContentIncludeBehavior.zip

Workaround

The only potential workaround is to create a custom MSBuild Target that

  1. Checks the head for all referenced projects
  2. Checks each referenced project for any usages of <Content Include="..."/>
  3. Manually copy the files to the project head's "Assets" folder

Then, modify all of your code to only use the Assets folder.

Works on UWP/WinUI

Yes

Environment

Uno.UI / Uno.UI.WebAssembly / Uno.UI.Skia, Uno.WinUI / Uno.WinUI.WebAssembly / Uno.WinUI.Skia

NuGet package version(s)

4.0.11

Affected platforms

iOS, Android, WebAssembly, WebAssembly renderers for Xamarin.Forms, macOS, Skia (WPF), Skia (GTK on Linux/macOS/Windows), Skia (Tizen)

IDE

Visual Studio 2022

IDE version

17.0.5

Relevant plugins

No response

Anything else we need to know?

No response

@Arlodotexe Arlodotexe added difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification labels Mar 8, 2022
@michael-hawker
Copy link

@Arlodotexe we don't need these to be in a library specifically, but just the head/app output right? (I mean ideally it should work for both, but we don't need to bundle them specifically in a library for our scenario.)

@Arlodotexe
Copy link
Contributor Author

Arlodotexe commented Mar 8, 2022

@Arlodotexe we don't need these to be in a library specifically, but just the head/app output right? (I mean ideally it should work for both, but we don't need to bundle them specifically in a library for our scenario.)

For our scenario, we don't need to bundle content as part of a nuget package, but we do need it accessible via StorageFile.GetFileFromApplicationUriAsync() in the compiled app.

@jeromelaban
Copy link
Member

This issue is related to #2502

@michael-hawker
Copy link

@jeromelaban @ajpinedam @MartinZikmund wondering if you had any insights on this issue (compared to the library specific one in #2502), since we just need it at the application level.

Is there some easier work-around we can do? We're concerned about switching/using embedded resources as we want to only access these files on demand for WASM vs. trying to load them all at application start. (As there'll be hundreds of files in our scenario for documentation/examples.)

@jeromelaban
Copy link
Member

@michael-hawker For now, the only way to fix this is to have Content items injected into the building project at build time. If it's for a local project, create a build.props file that you can reference from the different heads so that the content files can be properly injected at build time. If it's for a nuget package, it's quite similar, but it needs to be registered as a build folder props file.

@jeromelaban
Copy link
Member

I've added a more comprehensive workaround in #2502 (comment), so I'll close this issue as a duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification
Projects
None yet
Development

No branches or pull requests

4 participants
@jeromelaban @Arlodotexe @michael-hawker and others