Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dino committed May 18, 2015
2 parents b230519 + eeecbf6 commit 48f2e87
Show file tree
Hide file tree
Showing 95 changed files with 4,924 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,12 @@ public virtual bool Isolated {
}
}

public uint RefType {
get { throw new NotImplementedException(); }
public virtual uint RefType {
get {
// Default to native reference to help prevent callers from
// making incorrect assumptions
return (uint)__PROJECTREFERENCETYPE.PROJREFTYPE_NATIVE;
}
}

public virtual bool Resolved {
Expand Down
112 changes: 100 additions & 12 deletions Common/Product/SharedProject/CommonConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,46 +13,134 @@
* ***************************************************************************/

using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell.Interop;
using System.Collections.Generic;

namespace Microsoft.VisualStudioTools.Project {
/// <summary>
/// Enables the Any CPU Platform form name for Dynamic Projects.
/// Enables the Any CPU, x86, x64, and ARM Platform form names for Dynamic Projects.
/// Hooks language specific project config.
/// Projects that are platform aware should have a PlatformAware and AvailablePlatforms
/// property for configuration handling to function correctly.
/// PlatformAware value can be true or false. AvailablePlatforms is a comma separated string of supported platforms (e.g. "x86, X64")
/// If the PlatformAware property is ommited then this provider will only provide "Any CPU" platform.
/// </summary>
internal class CommonConfigProvider : ConfigProvider {
private CommonProjectNode _project;
private bool _isPlatformAware;

public CommonConfigProvider(CommonProjectNode project)
: base(project) {
bool appxPackage, windowsAppContainer;
_project = project;
bool.TryParse(this.ProjectMgr.BuildProject.GetPropertyValue(ProjectFileConstants.PlatformAware), out _isPlatformAware);

if (!_isPlatformAware) {
bool.TryParse(this.ProjectMgr.BuildProject.GetPropertyValue(ProjectFileConstants.AppxPackage), out appxPackage);
bool.TryParse(this.ProjectMgr.BuildProject.GetPropertyValue(ProjectFileConstants.WindowsAppContainer), out windowsAppContainer);
_isPlatformAware = appxPackage && windowsAppContainer;
}
}

#region overridden methods

protected override ProjectConfig CreateProjectConfiguration(string configName) {
protected override ProjectConfig CreateProjectConfiguration(string configName) {
if (_isPlatformAware) {
if (configName != null) {
var configParts = configName.Split('|');

if (configParts.Length == 2) {
var config = _project.MakeConfiguration(configName);
config.PlatformName = configParts[1];
return config;
}
}
}

return _project.MakeConfiguration(configName);
}

public override int GetPlatformNames(uint celt, string[] names, uint[] actual) {
if (names != null) {
names[0] = "Any CPU";
if (_isPlatformAware) {
var platforms = GetSupportedPlatformsFromProject();
return GetPlatforms(celt, names, actual, platforms);
}
else {
if (names != null) {
names[0] = AnyCPUPlatform;
}

if (actual != null) {
actual[0] = 1;
if (actual != null) {
actual[0] = 1;
}

return VSConstants.S_OK;
}
}

return VSConstants.S_OK;
public override int GetSupportedPlatformNames(uint celt, string[] names, uint[] actual) {
if (_isPlatformAware) {
var platforms = GetSupportedPlatformsFromProject();
return GetPlatforms(celt, names, actual, platforms);
}
else {
if (names != null) {
names[0] = AnyCPUPlatform;
}

if (actual != null) {
actual[0] = 1;
}

return VSConstants.S_OK;
}
}

public override int GetSupportedPlatformNames(uint celt, string[] names, uint[] actual) {
if (names != null) {
names[0] = "Any CPU";
public override int GetCfgs(uint celt, IVsCfg[] a, uint[] actual, uint[] flags) {
if (_isPlatformAware) {
if (flags != null) {
flags[0] = 0;
}

int i = 0;
string[] configList = GetPropertiesConditionedOn(ProjectFileConstants.Configuration);
string[] platformList = GetSupportedPlatformsFromProject();

if (a != null) {
foreach (string platformName in platformList) {
foreach (string configName in configList) {
a[i] = this.GetProjectConfiguration(configName + "|" + platformName);
i++;
if (i == celt) {
break;
}
}
if(i == celt) {
break;
}
}
}
else {
i = configList.Length * platformList.Length;
}

if (actual != null) {
actual[0] = (uint)i;
}

return VSConstants.S_OK;
}

if (actual != null) {
actual[0] = 1;
return base.GetCfgs(celt, a, actual, flags);
}

public override int GetCfgOfName(string name, string platName, out IVsCfg cfg) {
if (!string.IsNullOrEmpty(platName)) {
cfg = this.GetProjectConfiguration(name + "|" + platName);

return VSConstants.S_OK;
}
cfg = this.GetProjectConfiguration(name);

return VSConstants.S_OK;
}
Expand Down
165 changes: 159 additions & 6 deletions Common/Product/SharedProject/CommonPropertyPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Microsoft.Build.Construction;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.OLE.Interop;

Expand Down Expand Up @@ -49,6 +53,10 @@ internal virtual CommonProjectNode Project {
}
}

internal virtual IEnumerable<CommonProjectConfig> SelectedConfigs {
get; set;
}

protected void SetProjectProperty(string propertyName, string propertyValue) {
// SetProjectProperty's implementation will check whether the value
// has changed.
Expand All @@ -59,6 +67,150 @@ protected string GetProjectProperty(string propertyName) {
return Project.GetUnevaluatedProperty(propertyName);
}

protected void SetUserProjectProperty(string propertyName, string propertyValue) {
// SetUserProjectProperty's implementation will check whether the value
// has changed.
Project.SetUserProjectProperty(propertyName, propertyValue);
}

protected string GetUserProjectProperty(string propertyName) {
return Project.GetUserProjectProperty(propertyName);
}

protected string GetConfigUserProjectProperty(string propertyName) {
if (SelectedConfigs == null) {
string condition = string.Format(System.Globalization.CultureInfo.InvariantCulture,
ConfigProvider.configPlatformString,
Project.CurrentConfig.GetPropertyValue("Configuration"),
Project.CurrentConfig.GetPropertyValue("Platform"));

return GetUserPropertyUnderCondition(propertyName, condition);
} else {
StringCollection values = new StringCollection();

foreach (var config in SelectedConfigs) {
string condition = string.Format(System.Globalization.CultureInfo.InvariantCulture,
ConfigProvider.configPlatformString,
config.ConfigName,
config.PlatformName);

values.Add(GetUserPropertyUnderCondition(propertyName, condition));
}

switch (values.Count) {
case 0:
return null;
case 1:
return values[0];
default:
return "<different values>";
}
}
}

protected void SetConfigUserProjectProperty(string propertyName, string propertyValue) {
if (SelectedConfigs == null) {
string condition = string.Format(System.Globalization.CultureInfo.InvariantCulture,
ConfigProvider.configPlatformString,
Project.CurrentConfig.GetPropertyValue("Configuration"),
Project.CurrentConfig.GetPropertyValue("Platform"));

SetUserPropertyUnderCondition(propertyName, propertyValue, condition);
} else {
foreach (var config in SelectedConfigs) {
string condition = string.Format(System.Globalization.CultureInfo.InvariantCulture,
ConfigProvider.configPlatformString,
config.ConfigName,
config.GetConfigurationProperty("Platform", false));

SetUserPropertyUnderCondition(propertyName, propertyValue, condition);
}
}
}

private string GetUserPropertyUnderCondition(string propertyName, string condition) {
string conditionTrimmed = (condition == null) ? String.Empty : condition.Trim();

if (Project.UserBuildProject != null) {
if (conditionTrimmed.Length == 0) {
return Project.UserBuildProject.GetProperty(propertyName).UnevaluatedValue;
}

// New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
// So do it ourselves.
ProjectPropertyGroupElement matchingGroup = null;

foreach (ProjectPropertyGroupElement group in Project.UserBuildProject.Xml.PropertyGroups) {
if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase)) {
matchingGroup = group;
break;
}
}

if (matchingGroup != null) {
foreach (ProjectPropertyElement property in matchingGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
{
if (string.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase)
&& (property.Condition == null || property.Condition.Length == 0)) {
return property.Value;
}
}
}

}

return null;
}

/// <summary>
/// Emulates the behavior of SetProperty(name, value, condition) on the old MSBuild object model.
/// This finds a property group with the specified condition (or creates one if necessary) then sets the property in there.
/// </summary>
private void SetUserPropertyUnderCondition(string propertyName, string propertyValue, string condition) {
string conditionTrimmed = (condition == null) ? String.Empty : condition.Trim();
const string userProjectCreateProperty = "UserProject";

if (Project.UserBuildProject == null) {
Project.SetUserProjectProperty(userProjectCreateProperty, null);
}

if (conditionTrimmed.Length == 0) {
var userProp = Project.UserBuildProject.GetProperty(userProjectCreateProperty);
if (userProp != null) {
Project.UserBuildProject.RemoveProperty(userProp);
}
Project.UserBuildProject.SetProperty(propertyName, propertyValue);
return;
}

// New OM doesn't have a convenient equivalent for setting a property with a particular property group condition.
// So do it ourselves.
ProjectPropertyGroupElement newGroup = null;

foreach (ProjectPropertyGroupElement group in Project.UserBuildProject.Xml.PropertyGroups) {
if (String.Equals(group.Condition.Trim(), conditionTrimmed, StringComparison.OrdinalIgnoreCase)) {
newGroup = group;
break;
}
}

if (newGroup == null) {
newGroup = Project.UserBuildProject.Xml.AddPropertyGroup(); // Adds after last existing PG, else at start of project
newGroup.Condition = condition;
}

foreach (ProjectPropertyElement property in newGroup.PropertiesReversed) // If there's dupes, pick the last one so we win
{
if (string.Equals(property.Name, propertyName, StringComparison.OrdinalIgnoreCase)
&& (property.Condition == null || property.Condition.Length == 0)) {
property.Value = propertyValue;
return;
}
}

newGroup.AddProperty(propertyName, propertyValue);
}

public bool Loading {
get {
return _loading;
Expand Down Expand Up @@ -138,18 +290,19 @@ void IPropertyPage.SetObjects(uint count, object[] punk) {

if (count > 0) {
if (punk[0] is ProjectConfig) {
ArrayList configs = new ArrayList();
if (_project == null) {
_project = (CommonProjectNode)((CommonProjectConfig)punk.First()).ProjectMgr;
}

var configs = new List<CommonProjectConfig>();

for (int i = 0; i < count; i++) {
CommonProjectConfig config = (CommonProjectConfig)punk[i];

if (_project == null) {
Project = (CommonProjectNode)config.ProjectMgr;
break;
}

configs.Add(config);
}

SelectedConfigs = configs;
} else if (punk[0] is NodeProperties) {
if (_project == null) {
Project = (CommonProjectNode)(punk[0] as NodeProperties).HierarchyNode.ProjectMgr;
Expand Down
Loading

0 comments on commit 48f2e87

Please sign in to comment.