Skip to content

Commit

Permalink
An complete MvsSln integration with IEnvironment
Browse files Browse the repository at this point in the history
Updated `IsolatedEnv` together with latest MvsSln's changes: ValidProjects etc.

This also fixes `Environment.StartupProjectString`, see details in #53
  • Loading branch information
3F committed Jul 29, 2019
1 parent d8ef75c commit 26fd0ec
Show file tree
Hide file tree
Showing 13 changed files with 425 additions and 398 deletions.
11 changes: 7 additions & 4 deletions vsSolutionBuildEvent/API/EventLevel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using System;
using System.Collections.Generic;
using EnvDTE80;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using net.r_eg.vsSBE.API.Commands;
using net.r_eg.vsSBE.Bridge;
Expand All @@ -29,6 +28,10 @@
using net.r_eg.vsSBE.SBEScripts;
using net.r_eg.vsSBE.Scripts;

#if VSSDK_15_AND_NEW
using Microsoft.VisualStudio.Shell;
#endif

namespace net.r_eg.vsSBE.API
{
using AppSettings = vsSBE.Settings;
Expand Down Expand Up @@ -134,7 +137,7 @@ public void load(object dte2, ISettings cfg)
{
configure(cfg);

this.Environment = new Environment((DTE2)dte2);
this.Environment = new Environment((DTE2)dte2, this);
init();

clientLib.tryLoad(this, dte2);
Expand Down Expand Up @@ -424,7 +427,7 @@ public int solutionOpened(object pUnkReserved, int fNewSolution)
UI.Plain.State.Print(config.Data);

Action.Cmd.MSBuild.initPropByDefault(); //LC: #815, #814
OpenedSolution(this, new EventArgs());
OpenedSolution(this, EventArgs.Empty);

if(slnEvents == null) {
updateBuildType(BuildType.Common);
Expand Down Expand Up @@ -462,7 +465,7 @@ public int solutionClosed(object pUnkReserved)
ret = Codes.Failed;
}

ClosedSolution(this, new EventArgs());
ClosedSolution(this, EventArgs.Empty);

ConfigManager.Config.unload();
ConfigManager.UserConfig.unload();
Expand Down
58 changes: 46 additions & 12 deletions vsSolutionBuildEvent/EnvAbstract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,37 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Linq;
using net.r_eg.MvsSln;
using net.r_eg.MvsSln.Core;
using net.r_eg.vsSBE.API.Commands;
using net.r_eg.vsSBE.Exceptions;
using BuildType = net.r_eg.vsSBE.Bridge.BuildType;
using EProject = Microsoft.Build.Evaluation.Project;
using ProjectItem = net.r_eg.MvsSln.Core.ProjectItem;

namespace net.r_eg.vsSBE
{
public abstract class EnvAbstract
{
protected IRuleOfConfig cfgRule = new RuleOfConfig();
/// <summary>
/// Parsed solution data.
/// </summary>
protected ISlnResult sln;

/// <summary>
/// Activated environment for projects processing.
/// </summary>
protected IXProjectEnv slnEnv;

//[Obsolete("integrate via IXProjectEnv use")]
//protected IRuleOfConfig cfgRule = new RuleOfConfig();

/// <summary>
/// Project by default or "StartUp Project".
/// </summary>
public abstract string StartupProjectString { get; protected set; }

/// <summary>
/// Current context for actions.
Expand All @@ -46,25 +66,39 @@ public IFireCoreCommand CoreCmdSender
}

/// <summary>
/// Returns formatted configuration from the SolutionConfiguration2
/// Get instance of the Build.Evaluation.Project for accessing to properties etc.
/// </summary>
public string SolutionCfgFormat(EnvDTE80.SolutionConfiguration2 cfg)
/// <param name="name">Specified project name. null value will use the name from startup-project.</param>
/// <returns>Found relevant Microsoft.Build.Evaluation.Project.</returns>
public virtual EProject getProject(string name = null)
{
if(cfg == null) {
return formatCfg(PropertyNames.UNDEFINED);
// NOTE: Do not use ProjectCollection.GlobalProjectCollection from EnvDTE Environment because it can be empty.
// https://github.com/3F/vsSolutionBuildEvent/issues/8
// Either use DTE projects collection to refer to MBE projects, or use MvsSln's GetOrLoadProject

Log.Trace($"getProject: started with '{name}' /{StartupProjectString}");

if(String.IsNullOrEmpty(name)) {
name = StartupProjectString;
}
return formatCfg(cfg.Name, cfg.PlatformName);

ProjectItem project = sln.ProjectItems.FirstOrDefault(p => p.name == name);
if(project.fullPath == null) {
throw new NotFoundException($"Project '{name}' was not found. ['{project.name}', '{project.pGuid}']");
}

return slnEnv.GetOrLoadProject(project);
}

/// <summary>
/// Gets project name from Microsoft.Build.Evaluation.Project
/// Returns formatted configuration from the SolutionConfiguration2
/// </summary>
/// <param name="eProject"></param>
/// <returns></returns>
protected virtual string getProjectNameFrom(EProject eProject)
public string SolutionCfgFormat(EnvDTE80.SolutionConfiguration2 cfg)
{
//NOTE: this property can also define an unified project name between various .sln files (_2010.sln, _2017.sln)
return eProject.GetPropertyValue(PropertyNames.PRJ_NAME);
if(cfg == null) {
return formatCfg(PropertyNames.UNDEFINED);
}
return formatCfg(cfg.Name, cfg.PlatformName);
}

protected string formatCfg(string name, string platform = null)
Expand Down
Loading

0 comments on commit 26fd0ec

Please sign in to comment.