Compartilhar via


IVsSolution2.CreateProject Method

Creates or opens a project.

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

Syntax

'Declaration
Function CreateProject ( _
    ByRef rguidProjectType As Guid, _
    lpszMoniker As String, _
    lpszLocation As String, _
    lpszName As String, _
    grfCreateFlags As UInteger, _
    ByRef iidProject As Guid, _
    <OutAttribute> ByRef ppProject As IntPtr _
) As Integer
int CreateProject(
    ref Guid rguidProjectType,
    string lpszMoniker,
    string lpszLocation,
    string lpszName,
    uint grfCreateFlags,
    ref Guid iidProject,
    out IntPtr ppProject
)
int CreateProject(
    [InAttribute] Guid% rguidProjectType, 
    [InAttribute] String^ lpszMoniker, 
    [InAttribute] String^ lpszLocation, 
    [InAttribute] String^ lpszName, 
    [InAttribute] unsigned int grfCreateFlags, 
    [InAttribute] Guid% iidProject, 
    [OutAttribute] IntPtr% ppProject
)
abstract CreateProject : 
        rguidProjectType:Guid byref * 
        lpszMoniker:string * 
        lpszLocation:string * 
        lpszName:string * 
        grfCreateFlags:uint32 * 
        iidProject:Guid byref * 
        ppProject:IntPtr byref -> int
function CreateProject(
    rguidProjectType : Guid, 
    lpszMoniker : String, 
    lpszLocation : String, 
    lpszName : String, 
    grfCreateFlags : uint, 
    iidProject : Guid, 
    ppProject : IntPtr
) : int

Parameters

  • rguidProjectType
    Type: Guid%

    [in] Unique identifier for the project type obtained when the project factory is registered. Can be GUID_NULL, if a value for lpszMoniker is specified. This parameter indicates the type of project to create or to add to the solution. If the value is GUID_NULL, then the environment attempts to determine the project type based on the extension of the file.

  • lpszMoniker
    Type: String

    [in] Pointer to the file moniker. If this method is used to open a project, then specify the path to the project on disk (including project name and file extension). If the method is being used to create a project, then specify the full path to the template file that will be cloned.

  • lpszLocation
    Type: String

    [in] Pointer to the path specifying the location for the new project. This parameter is used only when CPF_CLONEFILE is specified for the grfCreateFlags parameter; otherwise it is nulla null reference (Nothing in Visual Basic) (for open project). If the project is a directory-based project, then this is the directory for the project. The project file for the project is saved in this directory. If the project is not directory-based, then this location is used only to save the project file and perhaps as the default directory for newly created items. The szLocation parameter is defined to always include the trailing slash (\). Then, the project factory does not have to look for paths that look like "C:\" versus "C:\MyProjects\Project1" when constructing the path name of the project file.

  • lpszName
    Type: String

    [in] Pointer to the new project name. This parameter is used only when CPF_CLONEFILE is specified for the grfCreateFlags parameter; otherwise it is nulla null reference (Nothing in Visual Basic) (for open project). The project name does not include a file extension.

  • grfCreateFlags
    Type: UInt32

    [in] Controls how a project is created or opened. For a list of grfCreateFlags values, see __VSCREATEPROJFLAGS.

  • iidProject
    Type: Guid%

    [in] Interface identifier of the returned ppProject. This value can be iid_NULL to specify no return.

  • ppProject
    Type: IntPtr%

    [out, iid_is(iidProject)] Pointer to the newly created project.

Return Value

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

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsSolution2::CreateProject(
   [in] REFGUID rguidProjectType, 
   [in] LPCOLESTR lpszMoniker, 
   [in] LPCOLESTR lpszLocation, 
   [in] LPCOLESTR lpszName, 
   [in] VSCREATEPROJFLAGS grfCreateFlags, 
   [in] REFIID iidProject, 
   [out, iid_is(iidProject)] void **ppProject
);

If you are using this method to create a new project, then provide values for lpszMoniker, lpszLocation, and lpszName. If you are using this method to open an existing project, then lpszLocation, and lpszName are nulla null reference (Nothing in Visual Basic).

This method handles creating and opening project files only and does not support the opening of a solution file, that is, files with a SLN, DSW, or VBG extension. Opening of these file types is handled by the OpenSolutionFile method.

Creating a new project is accomplished by cloning an existing project that is empty. The environment determines which IVsPackage calls this method based on the file extension.

If both CPF_CLONEFILE and CPF_OVERWRITE are specified, the project overwrites the destination project file. If CPF_OVERWRITE is not specified, a specific HRESULT, VS_E_PROJECTALREADYEXISTS, is returned from this method. The environment then displays the This Project Already Exists dialog box. If the user chooses to overwrite the project file, the environment calls the CreateProject method again, specifying both CPF_CLONEFILE and CPF_OVERWRITE.

This method can display the user interface unless the CPF_SILENT flag is specified. This method should not report error messages to the user. This method uses the standard error-reporting conventions of the environment; it calls the SetErrorInfo method to record any error that occurs, and then returns an error HRESULT. The caller ultimately calls the ReportErrorInfo method to display the error message.

When this method returns an error HRESULT, it calls the SetErrorInfo method to supply information about which VSPackage or project could not be loaded and why. The caller of this method can use the ReportErrorInfo method to show this error message to the user.

.NET Framework Security

See Also

Reference

IVsSolution2 Interface

Microsoft.VisualStudio.Shell.Interop Namespace