简体   繁体   中英

Why can't I add certain file types to VS2010 projects?

I'm trying to add a WPF ResourceDictionary to a C# project that was created a while ago. The project was not originally a WPF project, but now I need to include some WPF resources in it.

When I right click the project and select "Add", ResourceDictionary is not an option. Even if I open the Modal dialog box and navigate to where the ResourceDictionary type should be (along side the other WPF types), it is not present.

Also, when I manually add a XAML file that has ResourceDictionary syntax to the project, I can't programmatically load it using WPF Application.Load(uri) syntax, so I feel VS2010 is preventing me from adding the file for a reason.

How can I make my project "able" to have a ResourceDictionary added without recreating the entire project from scratch as a WPF project and re-adding every file from scratch?

Additionally, what defines the file types that can be added to projects so I can avoid similar problems in the future? Hopefully it's something simple like a line I need to add to my AssemblyInfo.cs file.

Close the project. Create a new project that is of the type of WPF project you would have used. Then open the new .csproj file in notepad. Find the ProjectTypeGuids element. Copy those GUIDs to clipboard. Open your existing .csproj file in notepad. Append those GUIDs into this file's ProjectTypeGuids element. (Check for dupes.) Reload your project in Visual Studio. You should be able to add all the WPF file types now.

PS: I haven't done this with WPF specifically, but I have with other project types and it has worked without issue.

I believe the GUIDS are the same for everyone so the values you need should be: {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} ... this should save you the step of creating a new project.

I think your best bet is to create a new WPF project and copy everything across. If it is a very large project (and you are feeling adventurous) you might open the XML of the project files (Unload the project, then edit the original csproj file in XML)

在此输入图像描述

Then copy across the ItemGroup sections, and ensure the corresponding source files exist under the new project directory. Good luck!

Try creating a blank WPF project and then diff the .csproj files (they're just plain XML) for that and your project to see what differences there are - apart from the file lists and the odd compiler setting, you may well find a GUID or other entry that identifies the type of the project, which you will be able to copy/paste across to "upgrade" your project (after taking a backup of your existing project file of course!)

Alternatively, you can copy and paste the file/folder XML (carefully) between the csproj files to quickly "rebuild the entire project from scratch", so this needn't be something to be afraid of doing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM