다음을 통해 공유


IVsSolution.CreateProject Method

Definition

Creates or opens a project.

public:
 int CreateProject(Guid % rguidProjectType, System::String ^ lpszMoniker, System::String ^ lpszLocation, System::String ^ lpszName, System::UInt32 grfCreateFlags, Guid % iidProject, [Runtime::InteropServices::Out] IntPtr % ppProject);
public int CreateProject (ref Guid rguidProjectType, string lpszMoniker, string lpszLocation, string lpszName, uint grfCreateFlags, ref Guid iidProject, out IntPtr ppProject);
abstract member CreateProject : Guid * string * string * string * uint32 * Guid * nativeint -> int
Public Function CreateProject (ByRef rguidProjectType As Guid, lpszMoniker As String, lpszLocation As String, lpszName As String, grfCreateFlags As UInteger, ByRef iidProject As Guid, ByRef ppProject As IntPtr) As Integer

Parameters

rguidProjectType
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
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
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 null (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
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 null (for open project). The project name does not include a file extension.

grfCreateFlags
UInt32

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

iidProject
Guid

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

ppProject
IntPtr

nativeint

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

Returns

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

Remarks

COM Signature

From vsshell.idl:

HRESULT IVsSolution::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 null.

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 VSPackage 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.

Applies to