Skip to content

Commit

Permalink
Use different Build Action codes for msvc >= 15 and < 15.
Browse files Browse the repository at this point in the history
  • Loading branch information
awulkiew committed Jun 12, 2020
1 parent 5750218 commit f57b570
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions Visual_Studio_2017/ExcludeFromBuild/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,23 @@ class Util
{
public enum Configuration { Active, All };

private enum BuildAction { None = 0, Compile = 1, ApplicationDefinition = 6, Page = 7 };
private class BuildAction
{
public BuildAction(DTE2 dte)
{
int i = dte.Version.IndexOf('.');
if (i < 0)
i = dte.Version.Length;
version = int.Parse(dte.Version.Substring(0, i));
}

private readonly int version;

public int None { get { return 0; } }
public int Compile { get { return 1; } }
public int ApplicationDefinition { get { return version >= 15 ? 6 : 4; } }
public int Page { get { return version >= 15 ? 7 : 5; } }
}

#pragma warning disable VSTHRD010
public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration configuration)
Expand All @@ -27,7 +43,8 @@ public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration conf
var items = dte.ToolWindows.SolutionExplorer.SelectedItems as Array;
if (items == null)
return;
SetExcludedFromBuildRecursive(items, value, configuration);
BuildAction buildAction = new BuildAction(dte);
SetExcludedFromBuildRecursive(items, value, configuration, buildAction);
}

// Casting COM objects to VCFile and VCFilter works but the problem is that
Expand All @@ -37,7 +54,8 @@ public static void SetExcludedFromBuild(DTE2 dte, bool value, Configuration conf

private static void SetExcludedFromBuildRecursive(IEnumerable items,
bool value,
Configuration configuration)
Configuration configuration,
BuildAction buildAction)
{
foreach (var item in items)
{
Expand All @@ -48,7 +66,7 @@ private static void SetExcludedFromBuildRecursive(IEnumerable items,
// Any container, e.g. filter or C# XAML, etc.
if (hitem.UIHierarchyItems.Count > 0)
{
SetExcludedFromBuildRecursive(hitem.UIHierarchyItems, value, configuration);
SetExcludedFromBuildRecursive(hitem.UIHierarchyItems, value, configuration, buildAction);
}

// For C++ this is Microsoft.VisualStudio.VCProjectEngine.VCProjectItem
Expand All @@ -69,9 +87,9 @@ private static void SetExcludedFromBuildRecursive(IEnumerable items,
if (buildActionProp == null)
continue;
if (extension == ".cs")
buildActionProp.Value = (int)(value ? BuildAction.None : BuildAction.Compile);
buildActionProp.Value = value ? buildAction.None : buildAction.Compile;
else //if (extension == ".xaml")
buildActionProp.Value = (int)(value ? BuildAction.None : BuildAction.Page);
buildActionProp.Value = value ? buildAction.None : buildAction.Page;
}
else if (extension == ".cpp" || extension == ".c" || extension == ".cc" || extension == ".cxx")
{
Expand Down

0 comments on commit f57b570

Please sign in to comment.