I'd like to add two buttons to my studio extension which unload/load all test projects of an open solution. After a lot of hassle, the unload works fine. Now I still have troubles loading them.
Somehow I cannot figure out how to correctly use IVsSolution.CreateProject() and I don't find any examples. Here is what I have so far, which always returns me VS_E_PROJECTALREADYEXISTS:
internal sealed class ProjInfo
{
public ProjInfo(Guid guid, string name, string uniqueName)
{
Guid = guid;
Name = name;
UniqueName = uniqueName;
}
public Guid Guid { get; private set; }
public string Name { get; private set; }
public string UniqueName { get; private set; }
}
//....
private static void LoadProject(ProjInfo project, IVsSolution solutionService)
{
IVsHierarchy selectedHierarchy;
string solPath;
string solFileName;
string opstName;
solutionService.GetSolutionInfo(out solPath, out solFileName, out opstName);
string projRef;
solutionService.GetProjectOfGuid(project.Guid, out selectedHierarchy);
solutionService.GetProjrefOfProject(selectedHierarchy, out projRef);
Guid projectType;
IntPtr proj;
solutionService.GetProjectTypeGuid(0, project.UniqueName, out projectType);
projectType = Guid.Empty;
var iidProject = Guid.Empty; //project.Guid;
int res = VSConstants.S_OK;
if (ErrorHandler.Failed(res = solutionService.CreateProject(ref projectType, solPath + project.UniqueName, null, null, (uint)__VSCREATEPROJFLAGS.CPF_OPENFILE, ref iidProject, out proj)))
{
Debug.Fail(String.Format("IVsolution::CreateProject retuend 0x{0:X}.", res));
}
}
I played around with any combination of more creation-flags (__VSCREATEPROJFLAGS.CPF_OVERWRITE, __VSCREATEPROJFLAGS.CPF_SILENT), and without setting the references projectType and iidProject to Guid.Emtpy. Nothing works, I always get the result VS_E_PROJECTALREADYEXISTS.
Any idea how to achieve the functionality I have on the context menu to unload/reload a project programmatically? Maybe a completely different approach? Thanks a lot