You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have created a "multi-item" template, it's for an ascx file, so that when the user adds the ascx file to the project, it adds the designer and the code behind file as well.
This is working in that it adds the files, but they don't end up nested together in solution explorer, e.g they end up looking like this:
I followed these docs when defining the vstemplate file:
This way you just adding these items to the project file, but the project system doesn't know how to properly process them (that these files should be nested, compiled with specific build tool, etc).
What you need to do, is define custom item type. However the tutorial by this link doesn't describe how to add support for nested/dependent files.
I will post an with example of adding XAML Page item type to your project system (which has dependent .xaml.cs file and displayed as nested, it will also participate with MSBuild if you import common CSharp targets). You could implement support for ASCX items in a similar way.
First, you need to define a Xaml Rule to acknowledge Project System about the new item type:
(place into BuildSystem/Rules/PageXaml.xaml (better to use a Xaml Rule item template for this))
If you done this correctly, you could try to add existing UserControl XAML-file with its code-behind .XAML.CS-file and it will properly appear into the project tree and will be built by MSBuild (if you import common CSharp targets).
Second, you need to edit ProjectSchemaDefinitions.xaml and define ContentType, ItemType and FileExtension:
My project does not have this rule file. Should it be there by default, or do I just need to create this file? These are the rules in my project that were created by default:
I would also like the .cs file to be given a SubType of ASPXCodeBehind so it ends up looking like this in the project file - but I haven't figured out how to do that yet, as I can't find a place in the xaml to specify the SubType.
All in all I'm after this in the project file:
Activity
aienabled commentedon Dec 29, 2015
This way you just adding these items to the project file, but the project system doesn't know how to properly process them (that these files should be nested, compiled with specific build tool, etc).
What you need to do, is define custom item type. However the tutorial by this link doesn't describe how to add support for nested/dependent files.
I will post an with example of adding XAML Page item type to your project system (which has dependent .xaml.cs file and displayed as nested, it will also participate with MSBuild if you import common CSharp targets). You could implement support for ASCX items in a similar way.
First, you need to define a Xaml Rule to acknowledge Project System about the new item type:
(place into
BuildSystem/Rules/PageXaml.xaml(better to use a Xaml Rule item template for this))Second, you need to edit
ProjectSchemaDefinitions.xamland define ContentType, ItemType and FileExtension:(please note that here used "DependentFileExtensions" pair, it defines files nesting).
Third, you need to edit your targets-file to add support for properties browser for this item type:
If you done this correctly, you could try to add existing UserControl XAML-file with its code-behind .XAML.CS-file and it will properly appear into the project tree and will be built by MSBuild (if you import common CSharp targets).
Regards!
dazinator commentedon Dec 29, 2015
Vladimir Kozlov (@aienabled) - wow thank you so much for your help with this and putting me on track. I'll give this a go! :-)
dazinator commentedon Dec 29, 2015
Vladimir Kozlov (@aienabled) - I have go to this part:
My project does not have this rule file. Should it be there by default, or do I just need to create this file? These are the rules in my project that were created by default:
dazinator commentedon Dec 29, 2015
Vladimir Kozlov (@aienabled) ignore me - I can see that this file corresponds to the
ProjectItemsSchema.xamlfile from the link you provideddazinator commentedon Dec 29, 2015
Part way there!
Just need to figure out how get the designer file nested under the .cs file.
dazinator commentedon Dec 29, 2015
Found some more docs here: https://github.com/Microsoft/VSProjectSystem/blob/master/doc/extensibility/automatic_DependentUpon_wireup.md
dazinator commentedon Dec 29, 2015
This is working nicely.
I would also like the
.csfile to be given a SubType ofASPXCodeBehindso it ends up looking like this in the project file - but I haven't figured out how to do that yet, as I can't find a place in the xaml to specify the SubType.All in all I'm after this in the project file:
I'll raise a seperate issue for this if I can't figure it out.
dazinator commentedon Dec 29, 2015
Nope no joy. I'll raise a more concise issue.