private void SetupProjectGlobalPropertiesThatAllProjectSystemsMustSet()
{
string solutionDirectory = null;
string solutionFile = null;
string userOptionsFile = null;
IVsSolution solution = this.Site.GetService(typeof(SVsSolution)) as IVsSolution;
if (solution != null)
{
// We do not want to throw. If we cannot set the solution related constants we set them to empty string.
solution.GetSolutionInfo(out solutionDirectory, out solutionFile, out userOptionsFile);
}
if (solutionDirectory == null)
{
solutionDirectory = String.Empty;
}
if (solutionFile == null)
{
solutionFile = String.Empty;
}
string solutionFileName = (solutionFile.Length == 0) ? String.Empty : Path.GetFileName(solutionFile);
string solutionName = (solutionFile.Length == 0) ? String.Empty : Path.GetFileNameWithoutExtension(solutionFile);
string solutionExtension = String.Empty;
if (solutionFile.Length > 0 && Path.HasExtension(solutionFile))
{
solutionExtension = Path.GetExtension(solutionFile);
}
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionDir.ToString(), solutionDirectory);
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionPath.ToString(), solutionFile);
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionFileName.ToString(), solutionFileName);
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionName.ToString(), solutionName);
this.buildProject.SetGlobalProperty(GlobalProperty.SolutionExt.ToString(), solutionExtension);
// Other misc properties
this.buildProject.SetGlobalProperty(GlobalProperty.BuildingInsideVisualStudio.ToString(), "true");
this.buildProject.SetGlobalProperty(GlobalProperty.Configuration.ToString(), ProjectConfig.Debug);
this.buildProject.SetGlobalProperty(GlobalProperty.Platform.ToString(), ProjectConfig.AnyCPU);
// DevEnvDir property
object installDirAsObject = null;
IVsShell shell = this.Site.GetService(typeof(SVsShell)) as IVsShell;
if (shell != null)
{
// We do not want to throw. If we cannot set the solution related constants we set them to empty string.
shell.GetProperty((int)__VSSPROPID.VSSPROPID_InstallDirectory, out installDirAsObject);
}
string installDir = ((string)installDirAsObject);
if (String.IsNullOrEmpty(installDir))
{
installDir = String.Empty;
}
else
{
// Ensure that we have traimnling backslash as this is done for the langproj macros too.
if (installDir[installDir.Length - 1] != Path.DirectorySeparatorChar)
{
installDir += Path.DirectorySeparatorChar;
}
}
this.buildProject.SetGlobalProperty(GlobalProperty.DevEnvDir.ToString(), installDir);
}