IVsSingleFileGenerator.Generate Method (String, String, String, IntPtr[], UInt32, IVsGeneratorProgress)


Executes the transformation and returns the newly generated output file, whenever a custom tool is loaded, or the input file is saved.

Namespace:   Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)

int Generate(
	string wszInputFilePath,
	string bstrInputFileContents,
	string wszDefaultNamespace,
	IntPtr[] rgbOutputFileContents,
	out uint pcbOutput,
	IVsGeneratorProgress pGenerateProgress


Type: System.String

[in] The full path of the input file. May be null in future releases of Visual Studio, so generators should not rely on this value.

Type: System.String

[in] The contents of the input file. This is either a UNICODE BSTR (if the input file is text) or a binary BSTR (if the input file is binary). If the input file is a text file, the project system automatically converts the BSTR to UNICODE.

Type: System.String

[in] This parameter is meaningful only for custom tools that generate code. It represents the namespace into which the generated code will be placed. If the parameter is not null and not empty, the custom tool can use the following syntax to enclose the generated code.

' Visual Basic Namespace [default namespace]

... End Namespace

// Visual C#

namespace [default namespace] { ... }

Type: System.IntPtr[]

[out] Returns an array of bytes to be written to the generated file. You must include UNICODE or UTF-8 signature bytes in the returned byte array, as this is a raw stream. The memory for rgbOutputFileContents must be allocated using the .NET Framework call, System.Runtime.InteropServices.AllocCoTaskMem, or the equivalent Win32 system call, CoTaskMemAlloc. The project system is responsible for freeing this memory.

Type: System.UInt32

[out] Returns the count of bytes in the rgbOutputFileContent array.

Type: Microsoft.VisualStudio.Shell.Interop.IVsGeneratorProgress

[in] A reference to the IVsGeneratorProgress interface through which the generator can report its progress to the project system.

Return Value

Type: System.Int32

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

From vsshell.idl:

HRESULT IVsSingleFileGenerator::Generate(
   [in] LPCOLESTR wszInputFilePath,
   [in] BSTR bstrInputFileContents,
   [in] LPCOLESTR wszDefaultNamespace,
   [out] BYTE** rgbOutputFileContents,
   [out] ULONG* pcbOutput,
   [in] IVsGeneratorProgress* pGenerateProgress

For performance reasons, the project system reuses a single instantiation of a custom tool to handle multiple file transformations. Therefore, a custom tool should be designed to handle multiple calls to Generate during its lifetime.

The project system interprets the return value of Generate independently of errors reported through IVsGeneratorProgress. That is, if errors are reported through IVsGeneratorProgress, this method must still return FAILED for the overall generation process to fail.

Return to top