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

fix: Fixed bug with Additional Files metadata override. #8561

Draft
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

HavenDV
Copy link
Member

@HavenDV HavenDV commented Apr 17, 2022

GitHub Issue (If applicable): closes #8176

PR Type

What kind of change does this PR introduce?

Bugfix

What is the current behavior?

At the moment the Uno package does not take into account that the user may have other generators that have metadata in AdditionalFiles

What is the new behavior?

_InjectAdditionalFiles Target will correctly take into account the presence of AdditionalFiles by comparing them by full path. This will simply add new metadata to existing files that are also Page/ApplicationDefinition/PRIResource/TSBindingAssemblySource without losing the existing metadata.

PR Checklist

Please check if your PR fulfills the following requirements:

Other information

Internal Issue (If applicable):

@HavenDV HavenDV requested a review from a team April 17, 2022 21:18
@gitpod-io
Copy link

gitpod-io bot commented Apr 17, 2022

@HavenDV
Copy link
Member Author

HavenDV commented Apr 29, 2022

It's not entirely clear to me what caused the tests to crash after the last change. Everything works correctly in VS 2022 preview 4.0, but the CI environment may have a different msbuild that doesn't support this (or a nested %()). Should I undo the change?

@jeromelaban
Copy link
Member

This caused by:

The expression """.Contains()" cannot be evaluated. Method 'System.String.Contains' not found.

Most likely because _Pages or others can be null. Either check for empty in the expression, or make it non-empty before getting to the ItemGroup creation,

@HavenDV
Copy link
Member Author

HavenDV commented Apr 29, 2022

This caused by:

The expression """.Contains()" cannot be evaluated. Method 'System.String.Contains' not found.

Most likely because _Pages or others can be null. Either check for empty in the expression, or make it non-empty before getting to the ItemGroup creation,

In addition to this message, there is also such a message here, so I do not think that this is the reason

src\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props(365,47): Error MSB4184: The expression ""C:\a\1\s\src\Uno.UI.FluentTheme.v2\themeresources_v2.xaml".Contains()" cannot be evaluated. Method 'System.String.Contains' not found.

@jeromelaban
Copy link
Member

In addition to this message, there is also such a message here, so I do not think that this is the reason

src\SourceGenerators\Uno.UI.SourceGenerators\Content\Uno.UI.SourceGenerators.props(365,47): Error MSB4184: The expression ""C:\a\1\s\src\Uno.UI.FluentTheme.v2\themeresources_v2.xaml".Contains()" cannot be evaluated. Method 'System.String.Contains' not found.

It's likely because the parameter is null or empty, and there's no signature that matches Contains without parameters.

@HavenDV
Copy link
Member Author

HavenDV commented Jun 27, 2022

I have updated the code according to the latest changes in the master branch. I also added the necessary checks.

@HavenDV
Copy link
Member Author

HavenDV commented Jun 29, 2022

There are errors in the build that I don't understand. Perhaps they are caused by the fact that the full path is always used to avoid collisions.

@MartinZikmund
Copy link
Member

@HavenDV I'm seeing for example:

System.InvalidOperationException: Cannot locate resource from 'ms-resource:///Files/App/Linked/Test_Dictionary_Linked.xaml'

During When_Implicit_Style_And_Programmatic_Explicit_Style. You should be able to reproduce it locally when you select net461 as target and using the UnitTests-only.slnf

@HavenDV
Copy link
Member Author

HavenDV commented Jul 15, 2022

I checked, the error is caused by the fact that data with an absolute path was added to the dictionary instead of a relative one, as it was before. I will try to find an alternative solution instead of changing the current tests.

@HavenDV
Copy link
Member Author

HavenDV commented Jul 22, 2022

I made some edits to make the final output match the current one. Here is a project where you can experiment and evaluate the changes.
https://github.com/HavenDV/Uno.Issues/tree/main/uno_removes_additional_files_metadata
Ultimately, the problem was not that Uno was removing metadata, but that Uno was adding duplicate values with other metadata, causing other generators that could work with these files to only get the element with Uno's metadata (the second an element with the same FullPath and other metadata was lost)
There was also a problem with finding resources after testing on a real project, but this has also been fixed.

</PropertyGroup>

<ItemGroup Label="Add SourceItemGroup metadata to existing additional files">
<AdditionalFiles SourceItemGroup="Page" Condition="$(_UnoPages) == '' AND $(_Pages) != '' AND $(_AdditionalFiles) != '' AND $(_Pages.Contains(%(AdditionalFiles.FullPath)))" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be able to add a regression test in the runtimetests csproj (for instance), which create a custom AdditionalFile item, then validates that after the build, it's still set properly (with the right metadata)? Adding two targets, one beforebuild and one after compile that fails the build, would make it easier to ensure we're not breaking later on. Thanks!

Copy link
Member Author

@HavenDV HavenDV Aug 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to note that the syntax for updating metadata through Condition looks erroneous if you don’t know about it (because you expect an explicit Update, but I couldn’t make code through Update at the time of the PR, although I think it’s possible, I just need something like this filter the collection). Here are some examples that this is a valid code and it works:
https://github.com/MicrosoftDocs/visualstudio-docs/blob/main/docs/msbuild/msbuild-items.md#updating-metadata-on-items-in-an-itemgroup-of-a-target
dotnet/msbuild#1618 (comment)

P.S. I'll add tests a bit later when I have time.

@jeromelaban jeromelaban marked this pull request as draft August 9, 2022 18:10
@MartinZikmund
Copy link
Member

@HavenDV Is this PR still applicable?

@github-actions github-actions bot added the area/code-generation Categorizes an issue or PR as relevant to code generation label May 15, 2024
@HavenDV
Copy link
Member Author

HavenDV commented May 15, 2024

Hi @MartinZikmund, I've resolved the conflict so it may still be relevant/working, but I don't have the free time to test it right now

@unodevops
Copy link
Contributor

🤖 Your Docs stage site is ready! Visit it here: https://unodocsprstaging.z13.web.core.windows.net/pr-8561/index.html

@unodevops
Copy link
Contributor

🤖 Your WebAssembly Sample App stage site is ready! Visit it here: https://unowasmprstaging.z20.web.core.windows.net/pr-8561/index.html

@jeromelaban
Copy link
Member

jeromelaban commented May 22, 2024

Thanks for the update. It's still causing issues at this time with some combinations in regression testing.

Aside from this, would you know of a known generator that would break when using Uno?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/code-generation Categorizes an issue or PR as relevant to code generation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Generation] AdditionalFiles should not be removed if not added by uno
4 participants