public string GetProjectFileName(IVsSccProject2 pscp2Project)
{
// Note: Solution folders return currently a name like "NewFolder1{1DBFFC2F-6E27-465A-A16A-1AECEA0B2F7E}.storage"
// Your provider may consider returning the solution file as the project name for the solution, if it has to persist some properties in the "project file"
// UNDONE: What to return for web projects? They return a folder name, not a filename! Consider returning a pseudo-project filename instead of folder.
IVsHierarchy hierProject = (IVsHierarchy)pscp2Project;
IVsProject project = (IVsProject)pscp2Project;
// Attempt to get first the filename controlled by the root node
IList<string> sccFiles = GetNodeFiles(pscp2Project, VSConstants.VSITEMID_ROOT);
if (sccFiles.Count > 0 && sccFiles[0] != null && sccFiles[0].Length > 0)
{
return sccFiles[0];
}
// If that failed, attempt to get a name from the IVsProject interface
string bstrMKDocument;
if (project.GetMkDocument(VSConstants.VSITEMID_ROOT, out bstrMKDocument) == VSConstants.S_OK &&
bstrMKDocument != null && bstrMKDocument.Length > 0)
{
return bstrMKDocument;
}
// If that failes, attempt to get the filename from the solution
IVsSolution sol = (IVsSolution)GetService(typeof(SVsSolution));
string uniqueName;
if (sol.GetUniqueNameOfProject(hierProject, out uniqueName) == VSConstants.S_OK &&
uniqueName != null && uniqueName.Length > 0)
{
// uniqueName may be a full-path or may be relative to the solution's folder
if (uniqueName.Length > 2 && uniqueName[1] == ':')
{
return uniqueName;
}
// try to get the solution's folder and relativize the project name to it
string solutionDirectory, solutionFile, solutionUserOptions;
if (sol.GetSolutionInfo(out solutionDirectory, out solutionFile, out solutionUserOptions) == VSConstants.S_OK)
{
uniqueName = solutionDirectory + "\\" + uniqueName;
// UNDONE: eliminate possible "..\\.." from path
return uniqueName;
}
}
// If that failed, attempt to get the project name from
string bstrName;
if (hierProject.GetCanonicalName(VSConstants.VSITEMID_ROOT, out bstrName) == VSConstants.S_OK)
{
return bstrName;
}
// if everything we tried fail, return null string
return null;
}