Skip to content

The MSBuild target AssignLinkMetadata is missing the Resource item group #9120

@matherm-aboehm

Description

@matherm-aboehm

Description

I have a shared project with XAML files and where some image files were added to a subdirectory "Resources". I tried to embed these images with the "Resource" build action to use them as source for BitmapImages. I've done this by manually editing the .projitems file and changing the "Content" tags to "Resource" for the image files.
So far this works for the WPF designer: You can chose the images from the dropdown in the property grid and then it will be shown in the preview area of the WPF designer.
But when you run the app, it will throw an IOException with the message that the "Resource 'resources/xx' cannot be found".

Reproduction Steps

  • create a new WPF-App project
  • create a new shared project
  • add a reference to the shared project from the WPF-App project
  • add a WPF UserControl to the shared project
  • add an image to a subdirectory of the shared project
  • open the .projitems file of the shared project in a text editor.
  • change the "None" or "Content" tag of the image to "Resource"
  • back to Visual Studio, open the XAML file of the new UserControl in the editor/designer
  • add a Image tag to the code with the Source property set to the image from the subdirectory
  • see the image in the preview area
  • add this UserControl into the MainWindow.xaml of the WPF-App project.
  • compile and run the app
  • the IOException is thrown

Expected behavior

WPF app shows the image instead of throwing an exception.

Actual behavior

The app throws an exception of type System.IO.IOException with the message about the missing resource.

Regression?

No response

Known Workarounds

You can define and schedule your own MSBuild target in each and every project which references the shared project, so that it includes the missing tasks for Resource items.

Impact

No response

Configuration

  • .NET Framework 4.8
  • Windows 10 Pro 22H2
  • x64
  • No, it is not specific to this configuration.

Other information

When you look into the ".g.ressources" item in the compiled assembly you can see the image file, but without any folder name.
This is caused by the missing tasks of the MSBuild target "AssignLinkMetadata" in "Microsoft.Common.CurrentVersion.targets". There are tasks for Page and ApplicationDefinition items, but not for Resource items.

Was that intentional or just oversight? I can't find any documentation about it.

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions