Skip to content

Commit

Permalink
feat: UWP buildable and deployable under Any CPU
Browse files Browse the repository at this point in the history
- Setting ShouldBuild and ShouldDeploy on the UWP project under AnyCPU configuration for easier switching between projects
  • Loading branch information
MartinZikmund committed Jan 13, 2021
1 parent e4e76b6 commit 3a9a3b7
Showing 1 changed file with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Threading.Tasks;
using EnvDTE;
using EnvDTE80;
using Microsoft.VisualStudio.TemplateWizard;
Expand Down Expand Up @@ -44,6 +41,7 @@ public void RunFinished()

OpenWelcomePage();
SetStartupProject();
SetUWPAnyCPUBuildableAndDeployable();
SetDefaultConfiguration();
}

Expand Down Expand Up @@ -79,6 +77,38 @@ private void SetStartupProject()
}
}

private void SetUWPAnyCPUBuildableAndDeployable()
{
if (_dte?.Solution.SolutionBuild is SolutionBuild2 val)
{
try
{
var anyCpuConfig = val.SolutionConfigurations
.Cast<SolutionConfiguration2>()
.FirstOrDefault(c => c.Name == "Debug" && c.PlatformName == "Any CPU");

foreach (SolutionConfiguration2 solutionConfiguration2 in val.SolutionConfigurations)
{
foreach (SolutionContext solutionContext in anyCpuConfig.SolutionContexts)
{
if (solutionContext.ProjectName.EndsWith(".UWP.csproj"))
{
solutionContext.ShouldBuild = true;
solutionContext.ShouldDeploy = true;
}
}
}
}
catch (Exception)
{
}
}
else
{
throw new InvalidOperationException();
}
}


private void SetDefaultConfiguration()
{
Expand Down

2 comments on commit 3a9a3b7

@wokhan
Copy link

@wokhan wokhan commented on 3a9a3b7 Feb 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for this (I saw it in the changelog posted yesterday for release 3.5). So... I guess naming the UWP project xxx.UWP.csproj is mandatory (I thought it was optional), since at least this code relies on it ^^

@MartinZikmund
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wokhan It is necessary only when the solution is first created, it can be changed afterwards. And as there is exception handling, it should not be problem even then.

Please sign in to comment.