Visual Studio Plugin



VS2019 Arduino vMicro. Download & Install Visual Studio from Microsoft for free. Download & Install an Arduino Compatible IDE for full compatability (Arduino/Energia) 3. Install the Arduino Extension from within Visual Studio. Start developing your next Arduino project at the click of a button. The Visual Studio Plugin adds a number of tasks to your project. The main tasks that you will use are the visualStudio, cleanVisualStudio and openVisualStudio tasks. The following diagram shows the relationships between tasks added by this plugin. Visual Studio Plugin default task graph.

  1. Visual Studio Plugin Parallels
  2. Visual Studio Plugin Development
  3. Visual Studio Plugins Must Have
  4. Visual Studio Plug-ins
-->

Extensions are code packages that run inside Visual Studio and provide new or improved features. Extensions may be controls, samples, templates, tools, or other components that add functionality to Visual Studio, for example, Live Share or Visual Studio IntelliCode.

For information about creating Visual Studio extensions, see Visual Studio SDK. For information about using extensions, see the individual extension page on Visual Studio Marketplace.

Extensions and Updates dialog box

Use the Extensions and Updates dialog box to install and manage Visual Studio extensions. To open the Extensions and Updates dialog, choose Tools > Extensions and Updates, or type Extensions in the Quick Launch search box.

Manage Extensions dialog box

Use the Manage Extensions dialog box to install and manage Visual Studio extensions. To open the Manage Extensions dialog, choose Extensions > Manage Extensions. Or, type Extensions in the search box and choose Manage Extensions.

The pane on the left categorizes extensions by those that are installed, those available on Visual Studio Marketplace (Online), and those that have updates available. Roaming Extension Manager keeps a list of all the Visual Studio extensions you've installed on any machine or instance of Visual Studio. It's designed to let you find your favorite extensions more easily.

Find and install extensions

You can install extensions from Visual Studio Marketplace or the Extensions and Updates dialog box in Visual Studio.

To install extensions from within Visual Studio:

  1. From Tools > Extensions and Updates, find the extension you want to install. If you know the name or part of the name of the extension, you can search in the Search window.

  2. Select Download.

    The extension is scheduled for install. Your extension will be installed after all instances of Visual Studio have been closed.

If you try to install an extension that has dependencies, the installer verifies whether they're already installed. If they aren't installed, the Extensions and Updates dialog box lists the dependencies that must be installed before you can install the extension.

Install without using the Extensions and Updates dialog box

Extensions that have been packaged in .vsix files may be available in locations other than Visual Studio Marketplace. The Tools > Extensions and Updates dialog box can't detect these files, but you can install a .vsix file by double-clicking the file or selecting the file and pressing Enter. After that, just follow the instructions. When the extension is installed, you can use the Extensions and Updates dialog box to enable it, disable it, or uninstall it.

Note

  • Visual Studio Marketplace contains both VSIX and MSI extensions. The Extensions and Updates dialog box can't enable or disable MSI-based extensions.
  • If an MSI-based extension includes an extension.vsixmanifest file, the extension appears in the Extensions and Updates dialog box.

You can install extensions from Visual Studio Marketplace or the Manage Extensions dialog box in Visual Studio.

Plugin

To install extensions from within Visual Studio:

  1. From Extensions > Manage Extensions, find the extension you want to install. (If you know the name or part of the name of the extension, you can search in the Search window.)

  2. Select Download.

    The extension is scheduled for install. Your extension will be installed after all instances of Visual Studio have been closed.

If you try to install an extension that has dependencies, the installer verifies whether they're already installed. If they aren't installed, the Manage Extensions dialog box lists the dependencies that must be installed before you can install the extension.

Install without using the Manage Extensions dialog box

Extensions that have been packaged in .vsix files may be available in locations other than Visual Studio Marketplace. The Extensions > Manage Extensions dialog box can't detect these files, but you can install a .vsix file by double-clicking the file or selecting the file and pressing Enter. After that, just follow the instructions. When the extension is installed, you can use the Manage Extensions dialog box to enable it, disable it, or uninstall it.

Note

  • Visual Studio Marketplace contains both VSIX and MSI extensions. The Manage Extensions dialog box can't enable or disable MSI-based extensions.
  • If an MSI-based extension includes an extension.vsixmanifest file, the extension appears in the Manage Extensions dialog box.

Uninstall or disable an extension

If you want to stop using an extension, you can either disable it or uninstall it. Disabling an extension keeps it installed but unloaded. Find the extension and click Uninstall or Disable. Restart Visual Studio to unload a disabled extension.

Note

You can disable VSIX extensions but not extensions that were installed using an MSI. MSI-installed extensions can only be uninstalled.

Per-user and administrative extensions

Most extensions are per-user and are installed in the %LocalAppData%MicrosoftVisualStudio<Visual Studio version>Extensions folder. A few extensions are administrative extensions and are installed in the <Visual Studio installation folder>Common7IDEExtensions folder.

To protect your system against extensions that may contain errors or malicious code, you can restrict per-user extensions to load only when Visual Studio is run with normal user permissions. This means that per-user extensions are disabled when Visual Studio is run with elevated permissions.

Visual Studio Plugin Parallels

To restrict when per-user extensions load:

  1. Open the extensions options page (Tools > Options > Environment > Extensions).

  2. Clear the Load per user extensions when running as administrator check box.

  3. Restart Visual Studio.

Automatic extension updates

Extensions are updated automatically when a new version is available on Visual Studio Marketplace. The new version of the extension is detected and installed in the background. The next time you open Visual Studio, the new version of the extension will be running.

If you wish to disable automatic updates, you can disable the feature for all extensions or only for specific extensions.

  • To disable automatic updates for all extensions, choose the Change your Extensions and Updates settings link in the Tools > Extensions and Updates dialog box. In the Options dialog, uncheck Automatically update extensions.

  • To disable automatic updates for a specific extension, uncheck the Automatically update this extension option in the extension's details pane on the right side of the Extensions and Updates dialog.

  • To disable automatic updates for all extensions, choose the Change your settings for Extensions link in the Extensions > Manage Extensions dialog box. In the Options dialog, uncheck Automatically update extensions.

  • To disable automatic updates for a specific extension, uncheck the Automatically update this extension option in the extension's details pane on the right side of the Manage Extensions dialog.

Crash and unresponsiveness notifications

Visual Studio notifies you if it suspects that an extension was involved in a crash during a previous session. When Visual Studio crashes, it stores the exception stack. The next time Visual Studio launches, it examines the stack, starting with the leaf and working towards the base. If Visual Studio determines that a frame belongs to a module that is part of an installed and enabled extension, it shows a notification.

Visual Studio Plugin

Visual Studio Plugin Development

Visual Studio also notifies you if it suspects an extension is causing the UI to be unresponsive.

When these notifications are shown, you can ignore the notification or take one of the following actions:

  • Choose Disable this extension. Visual Studio disables the extension and lets you know whether you need to restart your system for the disabling to take effect. You can re-enable the extension in the Tools > Extensions and Updates dialog box if you want.
  • Choose Disable this extension. Visual Studio disables the extension and lets you know whether you need to restart your system for the disabling to take effect. You can re-enable the extension in the Extensions > Manage Extensions dialog box if you want.
  • Choose Never show this message again.

    • If the notification concerns a crash in a previous session, Visual Studio no longer shows a notification when a crash associated with this extension occurs. Visual Studio will still show notifications when unresponsiveness can be associated with this extension, or for crashes or unresponsiveness that can be associated with other extensions.
    • If the notification concerns unresponsiveness, the integrated development environment (IDE) no longer shows a notification when this extension is associated with unresponsiveness. Visual Studio will still show crash-related notifications for this extension and crash- and unresponsiveness-related notifications for other extensions.
  • Choose Learn more to navigate to this page.

  • Choose the X button at the end of the notification to dismiss the notification. A new notification will appear for future instances of the extension being associated with a crash or UI unresponsiveness.

Note

A UI unresponsiveness or crash notification means only that one of the extension’s modules was on the stack when the UI was unresponsive or when the crash occurred. It does not necessarily mean that the extension itself was the culprit. It's possible that the extension called code that's part of Visual Studio, which in turn resulted in unresponsive UI or a crash. However, the notification may still be useful if the extension which led to the UI unresponsiveness or crash is not important to you. In this case, disabling the extension avoids the UI unresponsiveness or the crash in the future, without impacting your productivity.

Samples

When you install an online sample, the solution is stored in two locations:

  • A working copy is stored in the location that you specified when you created the project.

  • A separate master copy is stored on your computer.

You can use the Tools > Extensions and Updates dialog box to perform these samples-related tasks:

You can use the Extensions > Manage Extensions dialog box to perform these samples-related tasks:

  • List the master copies of samples that you have installed.

  • Disable or uninstall the master copy of a sample.

  • Install Sample Packs, which are collections of samples that relate to a technology or feature.

  • Install individual online samples.

  • View update notifications when source code changes are published for installed samples.

  • Update the master copy of an installed sample when there is an update notification.

See also

-->

Note

Unsure about entity vs. table? See Developers: Understand terminology in Microsoft Dataverse.

This tutorial is the first in a series that will show you how to work with plug-ins. This tutorial is a pre-requisite for the following tutorials:

For detailed explanation of supporting concepts and technical details see:

Goal

Create an asynchronous plug-in registered on the Create message of the account table. The plug-in will create a task activity that will remind the creator of the account to follow up one week later.

Note

This goal can be easily achieved using a workflow without writing code. We are using this simple example so that we can focus on the process of creating and deploying a plug-in.

Prerequisites

  • Administrator level access to a Microsoft Dataverse environment
  • A model-driven app that includes the account and task tables.
    • If you don't have a model-driven app that includes these, see Build your first model-driven app from scratch for steps to make one in just a few minutes.
  • Visual Studio 2017 (or later version)
  • Knowledge of the Visual C# programming language
  • Download the Plug-in Registration tool.
    • Information about downloading the Plug-in registration tool is at : Download tools from NuGet. That topic includes instructions to use a PowerShell script to download the latest tools from NuGet.

Create a plug-in project

You need to use Visual Studio to write a plug-in. Use these steps to write a basic plug-in. Alternately, you can find the complete plug-in solution files here: Sample: Create a basic plug-in.

Create a Visual Studio project for the plug-in

  1. Open Visual Studio and open a new Class Library (.NET Framework) project using .NET Framework 4.6.2

    The name used for the project will be the name of the assembly. This tutorial uses the name BasicPlugin.

  2. In Solution Explorer, right-click the project and select Manage NuGet Packages… from the context menu.

  3. Select Browse and search for Microsoft.CrmSdk.CoreAssemblies and install the latest version.

  4. You must select I Accept in the License Acceptance dialog.

    Note

    Adding the Microsoft.CrmSdk.CoreAssemblies NuGet package will include these assemblies in the build folder for your assembly, but you will not upload these assemblies with the assembly that includes your logic. These assemblies are already present in the sandbox runtime.

    Do not include any other NuGet packages or assemblies to the build folder of your project. You cannot include these assemblies when you register the assembly with your logic. You cannot assume that the assemblies other than those included in the Microsoft.CrmSdk.CoreAssemblies NuGet package will be present on the server and compatible with your code.

  5. In Solution Explorer, right-click the Class1.cs file and choose Rename in the context menu.

  6. Rename the Class1.cs file to FollowupPlugin.cs.

  7. When prompted, allow Visual Studio to re-name the class to match the file name.

Visual studio plugin development

Edit the class file to enable a plug-in

Studio
  1. Add the following using statements to the top of the FollowupPlugin.cs file:

  2. Implement the IPlugin interface by editing the class.

    Note

    If you just type : IPlugin after the class name, Visual Studio will auto-suggest implementing a stub for the Execute Method.

  3. Replace the contents of the Execute method with the following code:

About the code

  • The ITracingService enables writing to the tracing log. You can see an example in the final catch block. More information: Use tracing
  • The IPluginExecutionContext provides access to the context for the event that executed the plugin. More information: Understand the execution context.
  • The code verifies that the context InputParameters includes the expected parameters for the CreateRequest that this plug-in will be registered for. If the Target property is present, the Entity that was passed to the request will be available.
  • The IOrganizationServiceFactory interface provides access to a service variable that implements the IOrganizationService interface which provides the methods you will use to interact with the service to create the task.

Add business logic

The plug-in will create a task activity that will remind the creator of the account to follow up one week later.

Add the following code to the try block. Replace the comment: // Plug-in business logic goes here. with the following:

About the code

  • This code uses the late-bound style to create a task and associate it with the account being created. More information: Create tables using the Organization service
  • Early bound classes can be used, but this requires generating the classes for the tables and including the file defining those classes with the assembly project. This is mostly a personal preference, so those steps have been left out of this tutorial for brevity. More information: Late-bound and early-bound programming using the Organization service
  • The Id of the account being created is found in the context OutputParameters and set as the regardingobjectid lookup column for the task.

Build plug-in

In Visual Studio, press F6 to build the assembly. Verify that it compiles without error.

Sign the plug-in

  1. In Solution Explorer, right click the BasicPlugin project and in the context menu select Properties.

  2. In the project properties, select the Signing tab and select the Sign the assembly checkbox.

  3. In the Choose a strong name key file: dropdown, select <New…>.

  4. In the Create Strong Name Keydialog, enter a key file name and deselect the Protect my key file with a password checkbox.

  5. Click OK to close the Create Strong Name Key dialog.

  6. In the project properties Build tab, verify that the Configuration is set to Debug.

  7. Press F6 to build the plug-in again.

  8. Using windows explorer, find the built plug-in at: binDebugBasicPlugin.dll.

Note

Build the assembly using Debug configuration because you will use the Plug-in Profiler to debug it in a later tutorial. Before you include a plug-in with your solution, you should build it using the release configuration.

Register plug-in

To register a plug-in, you will need the Plug-in Registration tool

Connect using the Plug-in Registration tool

  1. After you have downloaded the Plug-in registration tool, click the PluginRegistration.exe to open it.

  2. Click Create new Connection to connect to your instance.

  3. Make sure Office 365 is selected. If you are connecting using a Microsoft account other than one you are currently using, click Show Advanced.

  4. Enter your credentials and click Login.

  5. If your Microsoft Account provides access to multiple environments, you will need to choose an environment.

  6. After you are connected, you will see any existing registered plug-ins & custom workflow activities

Register your assembly

  1. In the Register drop-down, select New Assembly.

  2. In the Register New Assembly dialog, select the ellipses () button and browse to the assembly you built in the previous step.

  3. For Microsoft 365 users, verify that the isolation mode is set to sandbox and the location to store the assembly is Database.

    Note

    Other options for isolation mode and location apply to on-premises Dynamics 365 deployments. For the location, you can specify the D365 server's database, the server's local storage (disk), or the server's Global Assembly Cache. For more information see Plug-in storage.

  4. Click Register Selected Plug-ins.

  5. You will see a Registered Plug-ins confirmation dialog.

  6. Click OK to close the dialog and close the Register New Assembly dialog.

  7. You should now see the (Assembly) BasicPlugin assembly which you can expand to view the (Plugin) BasicPlugin.FollowUpPlugin plugin.

Register a new step

  1. Right-click the (Plugin) BasicPlugin.FollowUpPlugin and select Register New Step.

  2. In the Register New Step dialog, set the following fields:

    SettingValue
    MessageCreate
    Primary Entityaccount
    Event Pipeline Stage of ExecutionPostOperation
    Execution ModeAsynchronous
  3. Click Register New Step to complete the registration and close the Register New Step dialog.

  4. You can now see the registered step.

Note

At this point the assembly and steps are part of the system Default Solution. When creating a production plug-in, you would add them to the unmanaged solution that you will distribute. These steps are not included in this tutorial. See Add your assembly to a solution and Add step to solution for more information.

Test plug-in

  1. Open a model-driven app and create an account table.

  2. Within a short time, open the account and you can verify the creation of the task.

What if the task wasn't created?

Because this is an asynchronous plug-in, the operation to create the task occurs after the account is created. Usually, this will happen immediately, but if it doesn't you may still be able to view the system job in the queue waiting to be applied. This step registration used the Delete AsyncOperation if StatusCode = Successful option which is a best practice. This means as soon as the system job completes successfully, you will not be able to view the system job data unless you re-register the plug-in with the Delete AsyncOperation if StatusCode = Successful option unselected.

However, if there was an error, you can view the system job to see the error message.

View System jobs

Use the Dynamics 365 --custom app to view system jobs.

Visual Studio Plugins Must Have

  1. In your model-driven app, navigate to the app

  2. In the Dynamics 365 --custom app, navigate to Settings > System > System Jobs.

  3. When viewing system jobs, you can filter by Table (Entity). Select Account.

  4. If the job failed, you should see a record with the name BasicPlugin.FollowupPlugin: Create of account

  5. If you open the system job, you can expand the Details section to view the information written to the trace and details about the error.

Visual Studio Plug-ins

Query System jobs

You can use the following Web API query to return failed system jobs for asynchronous plug-ins.

More information: Query data using the Web API

Or use the following FetchXml:

More information: Use FetchXML with FetchExpression

Visual

View trace logs

The sample code wrote a message to the trace log. The steps below describe how to view the logs.

By default, plug-in trace logs are not enabled.

Tip

IF you prefer to change this setting in code:This setting is in the Organization table PluginTraceLogSetting column.

The valid values are:

ValueLabel
0Off
1Exception
2All

Use the following steps to enable them in a model-driven app.

  1. Open the Dynamics 365 - custom app.

  2. Navigate to Settings > System > Administration.

  3. In Administration, select System Settings.

  4. In the System Settings dialog, in the customization tab, set Enable logging to plug-in trace log to All.

    Note

    You should disable logging after you are finished testing your plug-in, or at least set it to Exception rather than All.

  5. Click OK to close the System Settings dialog.

  6. Repeat the steps to test your plug-in by creating a new account.

  7. In the Dynamics 365 -- custom app, navigate to Settings > Customization > Plug-In Trace Log.

  8. You should find that a new plug-in trace Log record has been created.

  9. If you open the record you might expect that it would include the information you set in your trace, but it does not. It only verifies that the trace occurred.

  10. To see the details, it is easier to query this data using the Web API in your browser using the following query with the plugintracelog EntityType, using the typename property to filter results in the messageblock property based on the name of the plug-in class:

    GET <your org uri>/api/data/v9.0/plugintracelogs?$select=messageblock&$filter=typename eq 'BasicPlugin.FollowUpPlugin'

  11. You can expect to see the following returned with the Web API query:

Next steps

In this tutorial you have created a simple plug-in and registered it. Complete Tutorial: Debug a plug-in to learn how to debug this plug-in.

Note

Can you tell us about your documentation language preferences? Take a short survey.

The survey will take about seven minutes. No personal data is collected (privacy statement).