unoplatform / uno

Build Mobile, Desktop and WebAssembly apps with C# and XAML. Today. Open source and professionally supported.
https://platform.uno
Apache License 2.0
8.48k stars 690 forks source link

[SVG] Changing UnoImage to Content throws and error in Visual Studio #15863

Open mcNets opened 2 months ago

mcNets commented 2 months ago

Current behavior

Changing Build property from UnoImage to Content of a .svg image added to a new solution (Windows & Skia) throws and error:

Property value is not valid. An error has occurred while saving the edited properties listed below: Build Action One or more values are invalid. value is object

Expected behavior

Build property should change from UnoImage to Content.

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

  <ItemGroup>
    <Content Remove="Assets\Images\uno.svg" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="Assets\Images\uno.svg" />
  </ItemGroup>

Visual studio throws this error message:

Property value is not valid. An error has occurred while saving the edited properties listed below: Build Action One or more values are invalid. value is object

Workaround

You can manually change:

  <ItemGroup>
    <Content Remove="Assets\Images\uno.svg" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="Assets\Images\uno.svg" />
  </ItemGroup>

to

  <ItemGroup>
    <Content Include="Assets\Images\uno.svg" />
  </ItemGroup>
  <ItemGroup>
    <None Remove="Assets\Images\uno.svg" />
  </ItemGroup>

Works on UWP/WinUI

None

Environment

No response

NuGet package version(s)

No response

Affected platforms

No response

IDE

No response

IDE version

No response

Relevant plugins

No response

Anything else we need to know?

Uno templates: 5.1.25

Visual Studio 17.10 Prev. 1

agneszitte commented 2 months ago

@mcNets Thank you for opening the issue with the details. Really appreciated!

For anyone looking at this issue, there are two main things here: (Both of these related issues were reproduced with VS Stable 17.9.2 and VS Preview 17.10 Prev. 1 and while using cli or wizard)

    • When we add an svg file in the Assets folder, by default the "Build action" visible in the "Properties" is "UnoImage" and when we try to change "UnoImage" to "Content" while using the dropdown in VS, we are getting an error 'Property value is not valid'. image

    • Even though the "Build action" in "Properties" shows "UnoImage" as a value that we are not able to update with the dropdown, on the other hand in the ProjectName.csproj, the <Content /> is properly added by default but we need to manually update "Remove" for "Include" in the csproj to be able to properly include the svg.

      So we need to manually change this: <Content Remove="Assets\Images\uno.svg" />

      For this: <Content Include="Assets\Images\uno.svg" />

(cc @jeromelaban, @MartinZikmund, @nickrandolph)

jeromelaban commented 2 months ago

Thanks for the details. This looks like a visual studio issue we'll have to report, and as far as I know, UnoImage is listed as a supported item type, @dansiegel may confirm.

agneszitte commented 1 month ago

Thanks for the details. This looks like a visual studio issue we'll have to report, and as far as I know, UnoImage is listed as a supported item type, @dansiegel may confirm.

@jeromelaban, @dansiegel should I give it another try with latest VS stable and latest VS Preview?

jeromelaban commented 1 month ago

@agneszitte probably, but I do not believe anything changed regarding this issue.

agneszitte commented 3 weeks ago

@agneszitte probably, but I do not believe anything changed regarding this issue.

@jeromelaban, @dansiegel (cc @MartinZikmund as you opened https://github.com/unoplatform/uno.resizetizer/issues/264) Still happening lately even with the latest VS version, we should report the issue if it is related to VS

jeromelaban commented 3 weeks ago

This may somehow be related to https://github.com/unoplatform/uno/issues/16605

jeromelaban commented 2 weeks ago

The error is reported as https://developercommunity.visualstudio.com/t/Changing-the-build-action-of-a-globbed-i/10658712.

In the meantime, if you want to include an SVG as an actual SVG file, make sure to place it in a folder named Svg.

jeromelaban commented 4 days ago

The error was reported to be caused by:

https://github.com/unoplatform/uno/blob/519c422535527d70deda85e391b3a70b360c9481/src/Uno.Sdk/targets/Uno.DefaultItems.Resizetizer.targets#L37-L43

which forces the Content to be removed. We'll have to figure out a way to avoid doing so.