Skip to content

Commit 94d6e54

Browse files
committed
Changes the way the robot project is detected
As explained in #17, The old method of forcing the startup project to be the robot project was flawed. Instead we now have a flag in the csproj that the extension can use to be certain it is the robot project.
1 parent c8a1d0b commit 94d6e54

File tree

8 files changed

+60
-31
lines changed

8 files changed

+60
-31
lines changed

FRC-Extension/Buttons/DeployDebugButton.cs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ public class DeployDebugButton : ButtonBase
1414
protected static bool s_deploying = false;
1515
protected static readonly List<OleMenuCommand> s_deployCommands = new List<OleMenuCommand>();
1616

17+
private Project m_robotProject = null;
18+
1719
public DeployDebugButton(Frc_ExtensionPackage package, int pkgCmdIdOfButton, bool debug) : base(package, true, GuidList.guidFRC_ExtensionCmdSet, pkgCmdIdOfButton)
1820
{
1921
m_debugButton = debug;
@@ -59,7 +61,7 @@ public override async void ButtonCallback(object sender, EventArgs e)
5961
//Disable the deploy buttons
6062
DisableAllButtons();
6163
DeployManager m = new DeployManager(m_package.PublicGetService(typeof(DTE)) as DTE);
62-
await m.DeployCode(teamNumber, page, m_debugButton);
64+
await m.DeployCode(teamNumber, page, m_debugButton, m_robotProject);
6365
EnableAllButtons();
6466
m_output.ProgressBarLabel = "Robot Code Deploy Successful";
6567
}
@@ -79,32 +81,36 @@ public override void QueryCallback(object sender, EventArgs e)
7981
if (menuCommand != null)
8082
{
8183
var dte = m_package.PublicGetService(typeof(DTE)) as DTE;
82-
var sb = (SolutionBuild2)dte.Solution.SolutionBuild;
8384

8485
bool visable = false;
85-
if (sb.StartupProjects != null)
86+
m_robotProject = null;
87+
88+
foreach (Project project in dte.Solution.Projects)
8689
{
87-
string project = ((Array)sb.StartupProjects).Cast<string>().First();
88-
Project startupProject = dte.Solution.Item(project);
89-
var vsproject = startupProject.Object as VSLangProj.VSProject;
90-
if (vsproject != null)
90+
if (project.Globals.VariableExists["RobotProject"])
9191
{
92-
//If we are an assembly, and its named WPILib, enable the deploy
93-
if ((from Reference reference in vsproject.References where reference.SourceProject == null select reference.Name).Any(name => name.Contains("WPILib")))
92+
var vsproject = project.Object as VSLangProj.VSProject;
93+
94+
if (vsproject != null)
9495
{
95-
visable = true;
96+
//If we are an assembly, and its named WPILib, enable the deploy
97+
if ((from Reference reference in vsproject.References where reference.SourceProject == null select reference.Name).Any(name => name.Contains("WPILib")))
98+
{
99+
visable = true;
100+
m_robotProject = project;
101+
break;
102+
}
96103
}
97104
}
98105
}
106+
99107
if (s_deploying)
100108
visable = false;
101109

102110
menuCommand.Visible = visable;
103111
if (menuCommand.Visible)
104112
{
105-
bool enabled = ((Array)sb.StartupProjects).Cast<string>().Count() == 1;
106-
107-
menuCommand.Enabled = enabled;
113+
menuCommand.Enabled = true;
108114
}
109115
}
110116
}

FRC-Extension/RoboRIOCode/DeployManager.cs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,23 @@ public DeployManager(DTE dte)
3030

3131

3232
//Uploads code to the robot and then runs it.
33-
public async Task DeployCode(string teamNumber, SettingsPageGrid page, bool debug)
33+
public async Task DeployCode(string teamNumber, SettingsPageGrid page, bool debug, Project robotProject)
3434
{
3535

3636
var writer = OutputWriter.Instance;
3737

38+
if (robotProject == null)
39+
{
40+
writer.WriteLine("Robot Project not valid. Contact RobotDotNet for support.");
41+
return;
42+
}
43+
3844
//Connect to Robot Async
3945
OutputWriter.Instance.WriteLine("Attempting to Connect to RoboRIO");
4046
Task<bool> rioConnectionTask = StartConnectionTask(teamNumber);
4147
Task delayTask = Task.Delay(10000);
4248

43-
CodeReturnStruct codeReturn = await BuildAndPrepareCode(debug);
49+
CodeReturnStruct codeReturn = await BuildAndPrepareCode(debug, robotProject);
4450

4551
if (codeReturn == null) return;
4652

@@ -127,7 +133,7 @@ public CodeReturnStruct(string exe, List<string> files)
127133
}
128134

129135

130-
public async Task<CodeReturnStruct> BuildAndPrepareCode(bool debug)
136+
public async Task<CodeReturnStruct> BuildAndPrepareCode(bool debug, Project robotProject)
131137
{
132138

133139
var writer = OutputWriter.Instance;
@@ -151,7 +157,8 @@ public async Task<CodeReturnStruct> BuildAndPrepareCode(bool debug)
151157
if (sb.LastBuildInfo == 0)
152158
{
153159
writer.WriteLine("Successfully Built Robot Code");
154-
string path = GetStartupAssemblyPath();
160+
//string path = GetStartupAssemblyPath();
161+
string path = GetAssemblyPath(robotProject);
155162
string robotExe = Path.GetFileName(path);
156163
string buildDir = Path.GetDirectoryName(path);
157164

@@ -249,20 +256,6 @@ public async Task<bool> CheckRoboRioImage()
249256
}
250257
}
251258

252-
internal string GetStartupAssemblyPath()
253-
{
254-
Project startupProject = GetStartupProject();
255-
return GetAssemblyPath(startupProject);
256-
}
257-
258-
private Project GetStartupProject()
259-
{
260-
var sb = (SolutionBuild2)m_dte.Solution.SolutionBuild;
261-
string project = ((Array)sb.StartupProjects).Cast<string>().First();
262-
Project startupProject = m_dte.Solution.Item(project);
263-
return startupProject;
264-
}
265-
266259
internal string GetAssemblyPath(Project vsProject)
267260
{
268261
string fullPath = vsProject.Properties.Item("FullPath").Value.ToString();

Templates/CSharp/Project-Templates/AttributedCommandRobot/ProjectTemplate.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Templates/CSharp/Project-Templates/CommandRobot/ProjectTemplate.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Templates/CSharp/Project-Templates/IterativeRobot/ProjectTemplate.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Templates/CSharp/Project-Templates/LabVIEWRobot/ProjectTemplate.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Templates/CSharp/Project-Templates/SampleRobot/ProjectTemplate.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

Templates/VisualBasic/Project-Templates/IterativeRobotVB/ProjectTemplate.vbproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ProjectExtensions>
4+
<VisualStudio>
5+
<UserProperties RobotProject="yes" />
6+
</VisualStudio>
7+
</ProjectExtensions>
38
<PropertyGroup>
49
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
510
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>

0 commit comments

Comments
 (0)