Workspace build
Build support in Open Folder scenarios requires an extender to supply indexed and file context data for the workspace, as well as the build action to run.
Below is an outline of what your extension will need.
Build file context
- Provider factory
ExportFileContextProviderAttribute
attribute withsupportedContextTypeGuids
as all applicablestring
constants fromBuildContextTypes
- Implements
IWorkspaceProviderFactory<IFileContextProvider>
- File context provider
- Return a
FileContext
for each build operation and configuration supportedcontextType
from BuildContextTypescontext
implements IBuildConfigurationContext with theConfiguration
property as the build configuration (for example"Debug|x86"
,"ret"
, ornull
if not applicable). Alternatively, use an instance of BuildConfigurationContext. The configuration value must match the configuration from the indexed file data value.
- Return a
Indexed build file data value
- Provider Factory
ExportFileScannerAttribute
attribute withIReadOnlyCollection<FileDataValue>
as a supported type- Implements
IWorkspaceProviderFactory<IFileScanner>
- File scanner on
ScanContentAsync<T>
- Returns data when
FileScannerTypeConstants.FileDataValuesType
is the type argument - Returns a file data value for each configuration constructed with:
type
asBuildConfigurationContext.ContextTypeGuid
context
as your build configuration (for example"Debug|x86"
,"ret"
, ornull
if not applicable). This value must match the configuration from the file context.
- Returns data when
Build file context action
- Provider factory
ExportFileContextActionProvider
attribute withsupportedContextTypeGuids
as all applicablestring
constants fromBuildContextTypes
- Implements
IWorkspaceProviderFactory<IFileContextActionProvider>
- Action provider on
IFileContextActionProvider.GetActionsAsync
- Return an
IFileContextAction
that matches the givenFileContext.ContextType
value
- Return an
- File context action
- Implements
IFileContextAction
and IVsCommandItem CommandGroup
property returns16537f6e-cb14-44da-b087-d1387ce3bf57
CommandId
is0x1000
for build,0x1010
for rebuild, or0x1020
for clean
- Implements
Note
Since the FileDataValue
needs to be indexed, there will be some amount of time between opening the workspace and the point at which the file is scanned for full build functionality. The delay will be seen on the first opening of a folder because there is no previously cached index.
Reporting messages from a build
The build can surface information, warning, and error messages to users one of two ways. The simple way is to use the IBuildMessageService and provide a BuildMessage, like so:
using Microsoft.VisualStudio.Workspace;
using Microsoft.VisualStudio.Workspace.Build;
private static void OutputBuildMessage(IWorkspace workspace)
{
IBuildMessageService buildMessageService = workspace.GetBuildMessageService();
if (buildMessageService != null)
{
// Example error build message. See the documentation for BuildMessage for more information.
var message = new BuildMessage()
{
Type = BuildMessage.TaskType.Error,
Code = "MY1001",
TaskText = "This is a sample error",
ProjectFile = "buildfile.bld",
File = "sourcefile.src"
LogMessage = $"This is sample text that will only go to the Build output window pane.\n"
// And any other properties to set
};
buildMessageService.ReportBuildMessages(new BuildMessage[] { message });
}
}
BuildMessage.Type
and BuildMessage.LogMessage
control the behavior of where information is presented to the user. Any BuildMessage.TaskType
value other than None
will produce an Error List entry with the given details. LogMessage
will always be output in the Build pane of the Output tool window.
Alternatively, extensions can directly interact with the Error List or Build pane. A bug exists in versions prior to Visual Studio 2017 Version 15.7 where the pszProjectUniqueName
argument of OutputTaskItemStringEx2 is ignored.
Warning
Callers of IFileContextAction.ExecuteAsync
can provide arbitrary underlying implementations for the IProgress<IFileContextActionProgressUpdate>
argument. Never invoke IProgress<IFileContextActionProgressUpdate>.Report(IFileContextActionProgressUpdate)
directly. There are currently no general guidelines for using this argument, but these guidelines are subject to change.
Build related APIs
- IBuildConfigurationContext provides build configuration details.
- IBuildMessageService shows BuildMessages to users.
tasks.vs.json and launch.vs.json
For information on authoring a tasks.vs.json or launch.vs.json file, see Customize build and debug tasks.
Related content
- Language Server Protocol - Learn how to integrate language servers into Visual Studio.