There are some scenarios where we need to detect the installed VS edition for our VS Package licence purposes.
The following snippet shows how to detect it and act accordingly.
private SKUEdition GetSKUEdition(IServiceProvider serviceProvider)
{
var shell = serviceProvider.GetService(typeof(IVsShell)) as IVsShell;
object sku;
shell.GetProperty((int)__VSSPROPID2.VSSPROPID_SKUEdition, out sku);
return (SKUEdition)Enum.Parse(typeof(SKUEdition), sku.ToString());
}
internal enum SKUEdition
{
Standard = 1000,
Professional = 2000,
Enterprise = 3000,
}
Pablo
Visual Studio ships with an assembly to compress and decompress files. This assembly is used in the Export Template feature for example.
The assembly is Microsoft.VisualStudio.Zip.9.0.dll and its located in the GAC.
The two main classes that we need to use are ZipFileCompressor and ZipFileDecompressor.
The API is really simple:
To compress a file:
var pathRoot = @"C:\MyPath";
var files = Directory.GetFiles(pathRoot, "*.*", SearchOption.AllDirectories);
files = files.Select(file => file.Replace(pathRoot, string.Empty)).ToArray();
// This doesn't follow any design guidelines, but all the logic for compressing a list of files
// is in the constructor, so the only thing that we need to do to compress is to create an
// instance of ZipFileCompressor.
var comp =
newZipFileCompressor(@"C:\Foo.zip", pathRoot, files, true);
To decompress a file:
var decomp = newZipFileDecompressor(@"C:\Foo.zip");
decomp.UncompressToFolder(@"C:\Foo", true);
Just zip it,
Pablo
Today I received the confirmation email from the latin american MVP lead. Thank you Microsoft for the award!!!
I also would like to give special thanks to the VSX Team.
Thanks,
Pablo
The new redistributable packages are significantly smaller. In the case of the Isolated mode, the size was reduced from ~400Mb to ~126Mb.
The main size reduction is because of the .Net Framework redist. The packages now include a small bootstrapper that will download the .Net Framework if necessary.
Links:
Visual Studio 2008 Shell (integrated mode)
Visual Studio 2008 Shell (isolated mode)
Pablo
As pointed out by Quan a new version of the VS SDK that targets VS 2008 SP1 beta 1 was released yesterday.
Links:
VS 2008 SP1 Beta 1
VS SDK 1.1 Beta
Pablo
István has written a series of awesome posts about PowerCommands. He called them PowerCommands deep dive series. The currently published are:
PowerCommands Deep Dive — Commands and UI
PowerCommands Deep Dive — Command Architecture
As I said they are great and a must read...
Pablo
Today I look at the release section of PowerCommands and I noticed that the number of downloads was 10.102. (and counting ...)
If you don't download it yet, go ahead a give it a try. :)
Pablo
PowerCommands 1.1 was released today on code.msdn.com
The new features available in 1.1 version are:
Enable/Disable PowerCommands in Options dialog
This feature allows you to select which commands to enable in the Visual Studio IDE. Point to the Tools menu, then click Options. Expand the PowerCommands options, then click Commands. Check the commands you would like to enable.
Format document on save / Remove and Sort Usings on save
The Format document on save option formats the tabs, spaces, and so on of the document being saved. It is equivalent to pointing to the Edit menu, clicking Advanced, and then clicking Format Document. The Remove and sort usings option removes unused using statements and sorts the remaining using statements in the document being saved.
Clear All Panes
This command clears all output panes. It can be executed from the button on the toolbar of the Output window.
Copy Path
This command copies the full path of the currently selected item to the clipboard. It can be executed by right-clicking one of these nodes in the Solution Explorer:
The solution node; A project node; Any project item node; Any folder.
Email CodeSnippet
To email the lines of text you select in the code editor, right-click anywhere in the editor and then click Email CodeSnippet.
Insert Guid Attribute
This command adds a Guid attribute to a selected class. From the code editor, right-click anywhere within the class definition, then click Insert Guid Attribute.
Show All Files
This command shows the hidden files in all projects displayed in the Solution Explorer when the solution node is selected. It enhances the Show All Files button, which normally shows only the hidden files in the selected project node.
Undo Close
This command reopens a closed document , returning the cursor to its last position. To reopen the most recently closed document, point to the Edit menu, then click Undo Close. Alternately, you can use the CtrlShiftZ shortcut.
To reopen any other recently closed document, point to the View menu, click Other Windows, and then click Undo Close Window. The Undo Close window appears, typically next to the Output window. Double-click any document in the list to reopen it.
ScottGu also mentioned PowerCommands in his last post.
Enjoy,
Pablo
I have released a new installer for IronPythonStudio targeting the VS Shell Integrated mode.
You can download it from here.
Pablo
As pointed out by
Quan, the
VSCTPowerToy was released on code.msdn.com.
It is a read-only viewer that you
can use to explore the commands associated with a VSPackage, and with Visual
Studio itself. You can quickly search for any existing commands in the Visual
Studio IDE. By browsing through the command groups, GUIDs and IDs, priorities,
and other properties of existing commands, you can more easily place and
integrate the commands of your own VSPackage.
You can download it from
herePablo
LinqToCodeModel is a sample library on top of the EnvDTE.FileCodeModel API to provide Linq queries and facilities on FileCodeModel object graphs.
A
SourceCodeOutliner Lite version is provided as sample of usage of the API. You can also check the
Samples section to get an idea on how to use it.
It can be downloaded from
here.Pablo
VSShell Assist is a visual toolset of utilities to create VS Shell applications. It seamlessly integrates with his big brother VSSDK Assist
The current features are:
- Create:
- VS Shell Setup project (wix based)
- Test:
- Test SLK/PLK
- Test VS Splash Screen
- Utility:
- Create VS Package pkgdef file
The pre-requisites are:
You can download it from here
Pablo
If you have downloaded StickyNotes you already noticed that the main toolwindow is hosting a WPF control.
Let see the steps needed to host a WPF control in a VS Toolwindow:
- Add a reference to C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsFormsIntegration.dll
- Add a WPF user control
- Add a class that inherits from ToolWindowPane (our ToolWindow)
- Modify the ToolWindowPane class as follows:
using System;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.VisualStudio.Shell;
[Guid("2070F92C-0843-4ba2-A46E-D559B1F03B2F")]
public class MyToolwindow : ToolWindowPane
{
private ElementHost elementHost;
public MyToolwindow:
base(null)
{
this.Caption = "My Tool Window";
}
protected override void Initialize()
{
base.Initialize();
elementHost = new ElementHost();
elementHost.Child = new MyWPFControl();
}
override public IWin32Window Window
{
get
{
return (IWin32Window)elementHost;
}
}
}
That's all you need,
Pablo
Today I found that the VS 2008 new wizard template engine supports $if$ directives. This was supported in the old .vsz format but now it is also available in vstemplates.
If we take a look at the existing windows form item template provided with VS 2008 we can see:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
$if$ ($targetframeworkversion$ == 3.5)using System.Linq;
$endif
$using System.Text;
using System.Windows.Forms;
namespace $rootnamespace$
{
public partial class $safeitemrootname$: Form
{
public $safeitemrootname$()
{
InitializeComponent();
}
}
}
Really cool, isn't it?
Pablo
This new version includes several bug fixes and it is compatible with GAX February 2008 RTM.
You can download it from here.
Pablo
Finally PowerCommands is OUT and part of the Visual Studio Gallery.
PowerCommands is a set of useful extensions for the Visual Studio 2008 adding additional functionality to various areas of the IDE.
List of features:
- Collapse Projects
This command collapses a hierarchy in the solution explorer starting from the root selected node. It can be executed from three different places: solution, solution folders and project nodes respectively. - Copy Class
This command copies a selected class entire content to the clipboard. It can be executed from a single project item or a project item with dependent sub items. - Paste Class
This command pastes a class entire content from the clipboard. It can be executed from a project or folder node. - Copy References
This command copies a reference or set of references to the clipboard. It can be executed from the references node, a single reference node or set of reference nodes. - Paste References
This command pastes a reference or set of references from the clipboard. It can be executed from different places depending on the type of project. For CSharp projects it can be executed from the references node. For Visual Basic and Website projects it can be executed from the project node. - Copy As Project Reference
This command copies a project as a project reference to the clipboard. It can be executed from a project node. - Edit Project File
This command opens the MSBuild project file for a selected project inside Visual Studio. It can be executed from a project node. - Open Containing Folder
This command opens a Windows Explorer window pointing to the physical path of a selected item. It can be executed from a project item node - Open Command Prompt
This command opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively. - Unload Projects
This command unloads all projects in a solution. It can be executed from the solution node. - Reload Projects
This command reloads all unloaded projects in a solution. It can be executed from the solution node. - Remove and Sort Usings
This command removes and sort using statements for all classes given a project. It can be executed from a solution node or a single project node. - Extract Constant
This command creates a constant definition statement for a selected text. It can be executed from the code window over a selected text. - Clear Recent File List
This command clears the Visual Studio recent file list. - Clear Recent Project List
This command clears the Visual Studio recent project list. - Transform Templates
This command executes the associated custom tool with text templates items. It can be executed from a DSL project node or a folder node. - Close All
This command closes all documents. It can be executed from a document tab.
You can download it from here.
Pablo
As Soma announced it the new Visual Studio Gallery is live. You can also check the official announcement for the VSX team.
The Visual Studio Gallery is a resource center for all Visual Studio extensions and includes everything from free VS PowerToys like tools to VSIP products.
TTxGen and StickyNotes are already part of the gallery.
Pablo
These are huge news on the Software factory space, GAX is not a CTP anymore.
Apart from this news, the new features are:
The February 2008 Release of the Guidance Automation Extensions and Guidance Automation Toolkit has the following improvements to the earlier release, the July 2007 Community Technology Preview:
-
Support for Visual Studio 2005 and/or Visual Studio 2008. This version of GAX will run on either version of Visual Studio. If you don't have GAX installed, you can install GAX to support Visual Studio 2005 or Visual Studio 2008 or both. The installer will automatically determine which versions of Visual Studio you have installed.
- Updating GAX.
- If you have a previous version of GAX installed on Visual Studio 2005, it will be updated to the February 2008 release of GAX. You are no longer required to uninstall GAX and the corresponding guidance packages.
- Guidance packages that are registered with the previous version of GAX will automatically be registered with the current version of GAX (GAT, however, will require an update - see the information below).
-
Visual Studio side-by-side support. If you have Visual Studio 2005 and Visual Studio 2008 running side-by-side, you can have GAX running against both versions. Guidance packages developed and registered through GAT for a specific version of Visual Studio (2005 or 2008) will only be available in that version. Guidance packages designed for Visual Studio 2005 and installed through an MSI will only be available in Visual Studio 2005. Installation of any guidance package through an MSI that does not explicitly prompt for the version of Visual Studio to install to, will install to Visual Studio 2005 by default.
-
Improved Uninstaller. During GAX uninstallation, you can click the Check Installed Packages button for the list of all registered guidance packages. If you proceed with GAX removal, the uninstaller will only attempt to automatically uninstall those guidance packages that were registered manually using GAT. If you have guidance packages that were installed through an MSI(s), you should not proceed with removing GAX. Instead, you should use the Add or Remove Programs tool to uninstall these guidance packages.
You can download it from here.
Pablo
TTxGen is a generic single file generator based on the text templating engine.
What is that???, Some background:
Single file generators or custom tools are COM components registered with Visual Studio that generate code.
To implement a custom tool you basically need to implement the IVsSingleFileGenerator interface. For more detail you can read kzu's post
A custom tool also needs to be registered and associated to file a extension.
The IVsSingleFileGenerator interface declares two methods:
int DefaultExtension (
out string pbstrDefaultExtension
)
This method is used to specify the extension of the generated file.
int Generate (
[InAttribute] string wszInputFilePath,
[InAttribute] string bstrInputFileContents,
[InAttribute] string wszDefaultNamespace,
[OutAttribute] IntPtr[] rgbOutputFileContents,
out uint pcbOutput,
[InAttribute] IVsGeneratorProgress pGenerateProgress
)
This method is used to generate the code that we want. It receives the name of the file associated with custom tool, the content of the file and it returns a Byte[] with the generated code.
One serious drawback is that we need to implement, register and deploy one custom tool for each representation of custom code that we want to generate.
Ok that's all for custom tools, now the funny part...
As you may know the text templating (t4) engine is now part of Visual Studio 2008. Based on this I created an implementation of a generic single file generator using t4.
The idea here is to have the same context as in custom tools. For that I have created a custom directive processor that injects the context needed on the tt:
<#@ output extension=".xml" #>
<#@ ParentFileInjector processor="TTxGenDirectiveProcessor" requires="fileName='Sample.xml'" #>
<#= this.ParentFileName #>
<#= this.ParentFileContent #>
If we want to access the parent file name we can use the ParentFileName variable, and for the content we can use the ParentFileContent.
TTxGen comes with some tooling to create a xGen template with the proper directives and context to start generating code:
The Create xGen Template command unfold a tt template, default the extension to the extension of the parent file and it automatically replace the requires argument.
You can download TTxGen from codegallery.
Pablo
I have created a small sample application to provide sticky notes capabilities to Visual Studio 2008.
The application is hosted at MSDN Code Gallery. If you want to find out more about MSDN Code Gallery check Soma's announcement.
The UI is based on WPF and it mimics the iphone Notes application.
This sample shows many VSX assets like:
- Hosting a WPF toolwindow
- Selection events
- ProjectDocument events
- ProjectItem events
- RDT events
- Project persistence
Link:
http://code.msdn.microsoft.com/StickyNotes
Pablo