Linked Files within a Folder Structure

你离开我真会死。 提交于 2019-12-19 10:39:09

问题


In Visual Studio when I linked a file from one project to the next, I get the following error when an attempt is made to load the linked resource. This only happens when the linked file is within a folder(s).

Error:

Message="'pack://application:,,,/projectName ;component/ResourceDictionary .xaml' value cannot be assigned to property 'Source' of object 'System.Windows.SharedResourceDictionary'.

Example:

Project1.Resources
           |
           |--> MergedResourceDictionary.xaml
           |--> ProjectResourceDictionary.xaml
           |--> Folder
                     |
                     |--> SharedResourceDictionary.xaml           


Project2.Resources
           |
           |--> MergedResourceDictionary.xaml
           |--> ProjectResourceDictionary.xaml
           |--> Folder
                     |
                     |--> SharedResourceDictionary.xaml  **LINKED**

If in the MergedResourceDictionary.xaml we merged these dictionaries, then the "SharedResourceDictionary.xaml in Project2 will not be found. However, if the SharedResourceDictionary.xaml is linked at the root of the project then the resource is found at runtime.

**NOTE: In the "obj/debug" of project2, all linked resources are at the root directory, whereas in project1 resources remain within the folder structure assigned in the project.

Steps to recreate This happens at runtime. Steps are as follows (using files listed in original post).

1) Create SharedResourceDictionary in Project1, within "Folder" 2) Create "Folder" in Project2, then add "as link" SharedResourceDictionary within the folder 3) Build and run app 4) App will not be able to find the SharedResourceDictionary.xaml, due to it residing within the Folder. Removing the file from the folder structure will work fine as a linked file.

I appreciate any assistance,

Chris


回答1:


I spent sometime working with Microsoft support on this problem. It is a bug with MsBuild and doubtful to be something they fix in the future.

I have found a workaround for anyone that is interested:

Create a PostBuild event that runs LocBaml and creates the folder structure that you require and places the files in the correct folder.

Hope this helps.



来源:https://stackoverflow.com/questions/917285/linked-files-within-a-folder-structure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!