Custom actions are used to extend the Built-in actions.


Both VB.NET and C# are supported as .NET languages for defining custom actions.

Hello world example


VB.NET

#If GUI_FRAMEWORK Then

Imports VSGuiApi

#End If


#If BG_FRAMEWORK Then

Imports VSBgApi

#End If


#If GUI_CORE Then

Imports VSGuiCoreApi

#End If


#If BG_CORE Then

Imports VSBgCoreApi

#End If



Imports System.DateTime

Imports System.Threading.Tasks


Public Class VSRegisteredActions

    Inherits VSRegisteredActionsBase


    Const provider As String = "External1"


    Public Sub New()

        Try

            Me.DoRegister()

        Catch ex As Exception

            MsgBox("Exception during registration of script actions: " & ex.Message)

        End Try


    End Sub


    Public Overrides Sub DoRegister()

        Me.Categories = New Dictionary(Of String, VSScriptCategory)

        Me.Actions = New Dictionary(Of String, VSScriptAction)


        Me.Register_Misc()


    End Sub

    Private Sub Register_Misc()

        Dim action As VSScriptAction = Nothing

        Dim cat As String = "Misc"

        Dim logicalGroup As String = "Prompts"


        Me.RegisterExternalCategory(provider, cat)


        action = Me.RegisterExternalDllAction(provider, cat, "SayHiVB", "VSMisc_SayHiVB", "Display a message to the user", logicalGroup)

        action.RegisterField(New VSFieldDefinition("TextExpression", "Text expression", VSFieldType.StringEditor_Multi, Nothing, "TextExpression", True, True, VSFieldValidation.None))


        action = Me.RegisterExternalDllAction(provider, cat, "SayHiAgainVB", "VSMisc_SayHiAgainVB", "Display a message to the user", logicalGroup)

        action.RegisterField(New VSFieldDefinition("TextExpression", "Text expression", VSFieldType.StringEditor_Multi, Nothing, "TextExpression", True, True, VSFieldValidation.None))


    End Sub

End Class


Public Class VSMisc_SayHiVB

    Inherits VSAction_Base_With_Expressions


    Public Property TextExpression As New VSMultiPropertyValue("", VSVariableDataType.String, VSPropertyValueType.Value)


    Public Overrides ReadOnly Property ContextData As List(Of VSContextDataProvider)

        'Used to by ContextDataManager in order to retrieve ContextData

        Get

            Return Nothing

        End Get

    End Property


    Public Sub New()

        MyBase.New()

    End Sub

    Public Overrides Sub Execute(ByVal scriptMgr As VSScriptManager)

        'Flee expression

        Dim actualTextExpression As String = ""


        Me.ScriptManager = scriptMgr 'This is the scriptManager that requested the NotifyText to Execute

        Me.ScriptManager.ExecutingObject = Me.Process 'Process being executed


        If Me.GetActualValue_RunTime(Me.TextExpression, VSVariableDataType.String, actualTextExpression) Then

            'Ok

            If Not Me.ScriptManager.RunTimeError Then


                Dim welcome As String = String.Format("Hi from external DLL: {0}", actualTextExpression)

                MsgBox(welcome)

                Console.WriteLine(welcome)


                Me.ScriptManager.ReportSuccessfulCompletion()


                If Not Me.ScriptManager.RunTimeError Then

                    Me.ScriptManager.LogMessage(VSSeverity.Informational, String.Format("Expression result of {0} = {1}", actualTextExpression, Me.TextExpression.Value))

                End If

            End If


        Else

            'Error, could not determine text expression

            Me.ScriptManager.LogMessage(VSSeverity.Error, String.Format("Unable to determine expression {0}", actualTextExpression))

        End If



    End Sub

End Class

Public Class VSMisc_SayHiAgainVB

    Inherits VSAction_Base_With_Expressions


    Public Property TextExpression As New VSMultiPropertyValue("", VSVariableDataType.String, VSPropertyValueType.Value)


    Public Overrides ReadOnly Property ContextData As List(Of VSContextDataProvider)

        'Used to by ContextDataManager in order to retrieve ContextData

        Get

            Return Nothing

        End Get

    End Property


    Public Sub New()

        MyBase.New()

    End Sub

    Public Overrides Sub Execute(ByVal scriptMgr As VSScriptManager)

        'Flee expression

        Dim actualTextExpression As String = ""


        Me.ScriptManager = scriptMgr 'This is the scriptManager that requested the NotifyText to Execute

        Me.ScriptManager.ExecutingObject = Me.Process 'Process being executed


        If Me.GetActualValue_RunTime(Me.TextExpression, VSVariableDataType.String, actualTextExpression) Then

            'Ok

            If Not Me.ScriptManager.RunTimeError Then


                MsgBox(String.Format("Hi again from external DLL: {0}", actualTextExpression))

                Console.WriteLine(String.Format("Hi again from external DLL: {0}", actualTextExpression))


                Me.ScriptManager.ReportSuccessfulCompletion()


                If Not Me.ScriptManager.RunTimeError Then

                    Me.ScriptManager.LogMessage(VSSeverity.Informational, String.Format("Expression result of {0} = {1}", actualTextExpression, Me.TextExpression.Value))

                End If

            End If


        Else

            'Error, could not determine text expression

            Me.ScriptManager.LogMessage(VSSeverity.Error, String.Format("Unable to determine expression {0}", actualTextExpression))

        End If



    End Sub

End Class



C#

#if GUI_FRAMEWORK 

using VSGuiApi;

using System.Windows.Forms;

#endif


#if BG_FRAMEWORK 

using VSBgApi;

#endif


#if GUI_CORE 

using VSGuiCoreApi;

#endif


#if BG_CORE 

using VSBgCoreApi;

#endif


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.IO;

using System.IO.Compression;


namespace VSDllExtensionCSharp

{

    public class VSRegisteredActions : VSRegisteredActionsBase

    {

        private const string provider = "External1";


        public VSRegisteredActions()

        {

            try

            {

                DoRegister();

            }

            catch (Exception ex)

            {

#if GUI_FRAMEWORK

                MessageBox.Show("Exception during registration of script actions: " + ex.Message);

#else

                Console.WriteLine("Exception during registration of script actions: " + ex.Message);

#endif

            }

        }


        public override void DoRegister()

        {

            Categories = new Dictionary<String, VSScriptCategory>();

            Actions = new Dictionary<String, VSScriptAction>();


            Register_Misc();

            //Register_File();

        }



        private void Register_Misc()

        {

            VSScriptAction action = null;

            string cat = "Misc";

            string logicalGroup = "Prompts";


            RegisterExternalCategory(provider, cat);


            action = RegisterExternalDllAction(provider, cat, "SayHiCSharp", "VSMisc_SayHiCSharp", "Display a message to the user", logicalGroup);

            action.RegisterField(new VSFieldDefinition("TextExpression", "Text expression", VSFieldType.StringEditor_Multi, null, "TextExpression", true, true, VSFieldValidation.None));


            action = RegisterExternalDllAction(provider, cat, "SayHiAgainCSharp", "VSMisc_SayHiAgainCSharp", "Display a message to the user", logicalGroup);

            action.RegisterField(new VSFieldDefinition("TextExpression", "Text expression", VSFieldType.StringEditor_Multi, null, "TextExpression", true, true, VSFieldValidation.None));


        }

        private void Register_File()

        {

            VSScriptAction action = null;

            string cat = "File";

            string logicalGroup = "Archiving.Gzip";


            RegisterExternalCategory(provider, cat);


            action = RegisterExternalDllAction(provider, cat, "GzipCompress", "VSFile_GzipCompress", "Compress using Gzip", logicalGroup);

            action.RegisterField(new VSFieldDefinition("SourceFolder", "Source folder", VSFieldType.PathPicker_Folder_Multi, null, "SourceFolder", true, true, VSFieldValidation.None));


            action = RegisterExternalDllAction(provider, cat, "GzipDecompress", "VSFile_GzipDecompress", "Decompress using Gzip", logicalGroup);

            action.RegisterField(new VSFieldDefinition("SourceFolder", "Source folder", VSFieldType.PathPicker_Folder_Multi, null, "SourceFolder", true, true, VSFieldValidation.None));

        }

    }


#region "Test"

    public class VSMisc_SayHiCSharp : VSAction_Base_With_Expressions

    {

        public VSMultiPropertyValue TextExpression { get; set; } = new VSMultiPropertyValue("", VSVariableDataType.String, VSPropertyValueType.Value);


        public override List<VSContextDataProvider> ContextData

        {

            get

            {

                List<VSContextDataProvider> list1 = new List<VSContextDataProvider>();

                return list1;

            }


        }


        public VSMisc_SayHiCSharp() : base()

        {


        }


        public override void Execute(VSScriptManager scriptMgr)

        {

            //Flee expression

            object actualTextExpression = (string)"";


            ScriptManager = scriptMgr; //This is the scriptManager that requested the NotifyText to Execute

            ScriptManager.ExecutingObject = Process; //Process being executed


            if (GetActualValue_RunTime(TextExpression, VSVariableDataType.String, ref actualTextExpression))

            {

                // Ok

            }

            else

            {

                //Error, could not determine text expression

                ScriptManager.LogMessage(VSSeverity.Error,

                    String.Format("Unable to determine expression {0}", actualTextExpression));

            }



            if (!(ScriptManager.RunTimeError))

            {

                string welcome = String.Format("Hi from external DLL: {0}", actualTextExpression);

#if GUI_FRAMEWORK

                MessageBox.Show(welcome);

#else

                Console.WriteLine(welcome);

#endif

  

                ScriptManager.ReportSuccessfulCompletion();


                if (!(ScriptManager.RunTimeError))

                {

                    ScriptManager.LogMessage(VSSeverity.Informational,

                        String.Format("Expression result of {0} = {1}", actualTextExpression, TextExpression.Value));

                }


            }


        }

    }

    public class VSMisc_SayHiAgainCSharp : VSAction_Base_With_Expressions

    {

        public VSMultiPropertyValue TextExpression { get; set; } = new VSMultiPropertyValue("", VSVariableDataType.String, VSPropertyValueType.Value);



        public override List<VSContextDataProvider> ContextData

        {

            get

            {

                List<VSContextDataProvider> list1 = new List<VSContextDataProvider>();

                return list1;

            }


        }


        public VSMisc_SayHiAgainCSharp() : base()

        {

        }


        public override void Execute(VSScriptManager scriptMgr)

        {

            //Flee expression

            object actualTextExpression = (string)"";


            ScriptManager = scriptMgr; //This is the scriptManager that requested the NotifyText to Execute

            ScriptManager.ExecutingObject = Process; //Process being executed


            if (GetActualValue_RunTime(TextExpression, VSVariableDataType.String, ref actualTextExpression))

            {

                // Ok

            }

            else

            {

                //Error, could not determine text expression

                ScriptManager.LogMessage(VSSeverity.Error,

                    String.Format("Unable to determine expression {0}", actualTextExpression));

            }



            if (!(ScriptManager.RunTimeError))

            {

                string welcome = String.Format("Hi again from external DLL: {0}", actualTextExpression);

#if GUI_FRAMEWORK

                MessageBox.Show(welcome);

#else

                Console.WriteLine(welcome);

#endif

               

                ScriptManager.ReportSuccessfulCompletion();


                if (!(ScriptManager.RunTimeError))

                {

                    ScriptManager.LogMessage(VSSeverity.Informational,

                        String.Format("Expression result of {0} = {1}", actualTextExpression, TextExpression.Value));

                }


            }


        }

    }

#endregion

      

}