About a month ago Aaron Marten wrote a post “CTC is dead…Long Live VSCT! (Part 1)” where he announced a new XML-based format called VSCT, which is far easier to work with than CTC. Two weeks ago James Lau announced VS SDK for Orcas Beta 1 (April CTP). One of the improvements of April CTP is that command table configuration (.ctc) files have been deprecated in favor of XML command table (.vsct) files and all samples that used .ctc files have been converted to use .vsct files.
Well, that is good but it is done for Visual Studio Codename Orcas only. The latest VS SDK 4.0 RTM for Visual Studio 2005 announced a little bit earlier still uses CTC but it includes VSCT compiler in pre-release state. You can find it here: C:\Program Files\Visual Studio 2005 SDK\2007.02\Prerelease\.
This post demonstrates how to add VSCT support for Whidbey (VS 2005) projects.
To demonstrate this we will use the C# Reference.MenuAndCommands sample included into Visual Studio SDK Version 4.0. You can find it in that directory: C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\. At the end of this tutorial, we will get this sample working with VSCT instead of CTC. Follow instructions below.
1. Before we will substitute CTC with VSCT let’s see how it looks now. Press F5 to run the MenuAndCommands sample in experimental hive and see some menu items added under main menu item ‘Tools’. Note command ‘C# Command Sample’ – it will be our marker in this tutorial.
![]()
2. The first thing we should care about is to obtain VSCT analogue for our CTC file. The easiest way to do that is to build the project to get .cto file compiled from current .ctc file and then create a .vsct file from an existing .cto file using VSCT.exe utility. I have used the following command to perform the conversion from <project_root>\obj\Debug\ directory where two input files PkgCmd.cto and PkgCmd.ctsym are located.
> “C:\Program Files\Visual Studio 2005 SDK\2007.02\Prerelease\VSCT\VSCT.exe” PkgCmd.cto PkgCmd.vsct -SPkgCmd.ctsym
3. Now let’s replace CTC part of the MenuAndCommands sample project with VSCT analogue. Create new folder VSCTComponents under project root directory and copy just generated PkgCmd.vsct file from obj\Debug\ there. Then make it part of the project. To be sure that we have no CTC here let’s remove all from CtcComponents folder except image GenericCmd.bmp, because it is still needed. Let’s also replace the text of the button ‘C# Command Sample’ with ‘C# Command Sample (VSTS)’ to have some differences in resulting UI. See what we have now.
![]()
Note: you can easily add IntelliSense for .vsct files via browsing for C:\Program Files\Visual Studio 2005 SDK\2007.02\Prerelease\VSCT\VSCT.xsd file in ‘Schemas’ property in Properties window (accessible by F4).
4. Rebuild the solution and then execute ‘devenv.exe /rootsuffix Exp /setup’ command to refresh Visual Studio UI. Then press F5 to see the result – all menus disappeared. To get all back in VSCT incarnation of menu items we need to write some code right in MenuAndCommands.csproj project file. To do that unload the project and open it for editing using ‘Edit MenuAndCommands.csproj’ command.
5. Add the following line importing .targets file as it is shown on the picture below. I have prepared the VSCT_overrides.targets file, so you just need to download it and save in the project root directory.
6. Now our PkgCmd.vsct file declared as <None Include=”VSCTComponents\PkgCmd.vsct” /> in MenuAndCommands.csproj file. Replace this line with the following code. Child node ResourceName specifies the name of CTO object which will be merged into assembly resources with.
![]()
7. Save the changes and reload the project. Select ‘Load project normally’ option in the Security Warning dialog which will be appeared. Rebuild the project and see results in output window. There are 4 errors that occurred due to automatic generation.
Note: make sure you use ‘Normal’ level of MSBuild build output verbosity.
8. You can easily fix them by adding 4 IDSymbol tags under according GuidSymbol tags or just download fixed version of PkgCmd.vsct file I have prepared. Then build the project again and verify that all errors go on.
![]()
9. Rebuild the solution and then execute ‘devenv.exe /rootsuffix Exp /setup’ command to refresh Visual Studio UI. Then press F5 to see the result – menus appeared again. Note the changed text ‘C# Command Sample (VSTS)’.
Enjoy!
~Dmitry
This is a really great step-by-step guide to doing the conversion in VS 2005. Thanks for putting it together!
Welcome!
There are some targets in Microsoft.VsSDK.targets file which also should be overriden for really smooth integration the VSCT compiler into Whidbey projects. But, that works good enough for now. And I also hope to see the next VS SDK version for VS 2005 with updated Microsoft.VsSDK.targets file as it done in VS SDK for Orcas.
[...] designed for Visual Studio 2005! I was going to write up instructions for this, but it looks like Dmitry Pavlov has beet me to the punch. He walks you through converting the C# Reference.MenuAndCommands sample in the VS 2005 SDK to use [...]
Thanks for the tutorial, it’s been very helpful.
For some reason the erorrs aren’t appearing in the build output (or the Errors tab),
Build output just says
—— Rebuild All started: Project: MenuAndCommands, Configuration: Debug Any CPU ——
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========
If I build with MSBuild I can see the errors from VSCT but the errors don’t seem to register with MSBuild:
msbuild MenuAndCommands.csproj /t:Rebuild /p:Configuration=Debug
Microsoft (R) Build Engine Version 2.0.50727.42
[Microsoft .NET Framework, Version 2.0.50727.42]
Copyright (C) Microsoft Corporation 2005. All rights reserved.
Build started 5/15/2007 12:37:40 PM.
__________________________________________________
Project “C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\MenuAndCommands.csproj” (Rebuild target(s)):
Target CoreClean:
Deleting file “obj\Debug\Microsoft.Samples.VisualStudio.MenuCommands.VSPackage.resources”.
Deleting file “obj\Debug\MenuAndCommands.csproj.GenerateResource.Cache”.
Target CoreResGen:
Processing resource file “VSPackage.resx” into “obj\Debug\Microsoft.Samples.VisualStudio.MenuCom
mands.VSPackage.resources”.
Target CtcCompile:
Skipping target “CtcCompile” because it has no outputs.
Target VSCTCompile:
Target C:\PROGRAM FILES\VISUAL STUDIO 2005 SDK\2007.02\VISUALSTUDIOINTEGRATION\SAMPLES\IDE\CSHARP\REFERENCE.MENUANDCOMMANDS\OBJ\DEBUG\PKGCMD.CTO does not exist: rebuilding…
C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\VSCTComponents\PkgCmd.vsct(9,40): error VSCT1103: Undefined ‘Parent/@id’ attribute ‘0×0001′ in a element
C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\VSCTComponents\PkgCmd.vsct(12,40): error VSCT1103: Undefined ‘Parent/@id’ attribute ‘0×0085′ in a element
C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\VSCTComponents\PkgCmd.vsct(15,40): error VSCT1103: Undefined ‘Parent/@id’ attribute ‘0×040D’ in a element
C:\Program Files\Visual Studio 2005 SDK\2007.02\VisualStudioIntegration\Samples\IDE\CSharp\Reference.MenuAndCommands\VSCTComponents\PkgCmd.vsct(19,40): error VSCT1103: Undefined ‘resID’ attribute
‘0×012C’ in a element
VSCT: errors = 4
VSCT: warnings = 0
Build FAILED.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.48
Is there some setting in the VSCTCompile target that I need to get the errors to appear?
Thanx
Hi Ian,
Thank you for your comment!
It seems due to bugs in VSCT.exe utility when you create .vsct file from existing .cto file – you need to perform some additional actions. Actually you need to add 3 IDSymbol tags under ‘guidSHLMainMenu’ GuidSymbol parent tag and 1 IDSymbol tag – under ‘guidGenericCmdBmp’ GuidSymbol parent tag.
Note 8th step and my post – I have written about it. To see the difference you can create a .vsct file from an existing .cto file (see step 2) and then download prepaired .vsct file (see link to ZIP file in steps 5 or 8), and then – compare these two .vsct files.
Regarding the Error List, I don’t think errors from VSCT compilation should appear there by design. But you can ask guys who developed VSCT.exe utility in Microsoft how to make it be posted into the Error List in Visual Studio. I would appreciate if they share this knowledge with me as well.
~ Dmitry
Sorry, guess I should’ve been clearer, there is an image in Step 7 that shows the errors displaying in the Build Output, and that wasn’t happening for me.
It’s hard to fix the errors if you can’t see them
.
After giving this some more thought I figured it out, I had to change MSBuild’s Verbosity level in
Tools->Options->Projects and Solutions->Build and Run
It was set at “Minimal” and I had to change it to “Normal”.
I will ask someone on the VS team about getting the errors promoted to the Errors Tab.
Something else I found, the dependency checking that VSCT.exe does, doesn’t seem to be working. Once I get a .vsct file to compile into a .cto, VSCT.exe always reports:
Target VSCTCompile:
No out of date dependancies, skipping execution.
Even if the .vsct file has changed.
Do you know if the dependency checking is working for you?
-Ian
I made a note about ‘Normal’ level of MSBuild build output verbosity it in step 7 (see just after the image).
Regarding dependency checking, yes – I have the same behavior on my side too. That is the think which still should be improved.
I think the easiest way is to look into Microsoft.VsSDK.targets from VS SDK version for Orcas. Or even compare it with Microsoft.VsSDK.targets file from VS SDK 4.0 RTM for Whidbey…
~ Dmitry