views:

393

answers:

2

In a VS Package (Visual Studio Extensibility), I have a custom extension registered (for ex ".custx") with XamlLanguageService, so that in Visual Studio when the user opens .custx, it opens up in Xaml Designer/editor just like a .xaml file.

However when I compile it as "Page" (BuildAction), the WINFX targets / Compiler errors out with the following error message.

MySample\Page1.custx : error : Markup file is not valid. Specify a source markup file with an .xaml extension.

I am looking for a solution, so that .custx pages compile as page, just like the .xaml pages in a WPF application

Any help is greatly appreciated

+1  A: 

I would suggest simply reusing the XAML file extension (there is no way to work around this check in the targets). Is there a reason you need your own file extension?

Aaron Marten
Yes, a lot of things depend on the custom extension - handlers, a special designer etc, so custom extension is the way forward
Vin
You shouldn't need your own file extension for a custom designer. VS supports the concept of multiple editor/designers registering for a single file extension (with a priority). Then, in the IVsEditorFactory's CreateEditorInstance method, the editor factory can inspect the document its being requested to open to ensure that its compatible.This is the way the Windows Workflow designer works in VS 2010. They register for .XAML also, but inspect the document first to ensure it's a workflow document (and not WPF or some other kind of XAML).
Aaron Marten
This should be (as in aught to be even though it isn't) supported. I'm running into the same thing. Did you ever find a solution?
justin.m.chase
The primary issue preventing this is the MSBuild task that compiles XAML->BAML actually checks that the file extension is ".xaml". If it isn't exactly ".xaml", it won't even attempt to process the file.
Aaron Marten
Thanks for your comments, looks like there is no way of doing this, and using a custom designer as an alternate designer can be one option. Other option as you mentioned would be to call it .xaml
Vin
A: 

Hello,

The fix for this issue is pretty easy. Basically I'm betting you are using a custom build action and your setting it with an integer like this:

Property property = projectItem.Properties.Item("BuildAction"); property.Value = 4; //0-3 are reserved, custom actions will be 4 or greater.

These integer values change per machine and per project type... So this error can be caused by the ItemType being set to ApplicationDefinition.

To fix this issue you need to set the ItemType to your custom action like this:

projectItem.Properties.Item("ItemType").Value = "MyCustomActionName".

Thanks

-Blake Niemyjski

Blake Niemyjski