Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit d15e5c6

Browse files
committed
[Core] Ensure multi-run config updated after project reload
With a multi-run configuration defined for the solution, if a project is reloaded, the multi-run config would not have the latest project run configuration. This would result in changes to the project run configuration in project options, such as adding or removing startup arguments, not being used when the multi-run configuration was used to run the solution. On reloading the new project run configuration is resolved and updated in the multi-run configuration. Previously only the SolutionItem was updated. Fixes VSTS #653269 - Multi startup project run configuration - arguments not passed after reload
1 parent d02f67c commit d15e5c6

File tree

9 files changed

+234
-4
lines changed

9 files changed

+234
-4
lines changed

main/src/core/MonoDevelop.Core/MonoDevelop.Projects/MultiItemSolutionRunConfiguration.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ StartupItem [] ItemArray {
7575
internal void ReplaceItem (SolutionItem oldItem, SolutionItem newItem)
7676
{
7777
foreach (var si in Items)
78-
if (si.SolutionItem == oldItem)
78+
if (si.SolutionItem == oldItem) {
7979
si.SolutionItem = newItem;
80+
81+
// SolutionItem's RunConfiguration will have been reloaded. Ensure the new run config is used.
82+
si.ResolveRunConfiguration ();
83+
}
8084
}
8185

8286
internal void RemoveItem (SolutionItem item)
@@ -159,13 +163,18 @@ internal void ResolveObjects (Solution sol)
159163
SolutionItem = sol.GetSolutionItem (ItemId) as SolutionItem;
160164
if (SolutionItem == null)
161165
SolutionItem = sol.FindProjectByName (ItemName) as SolutionItem;
162-
if (SolutionItem != null && ConfigurationId != null)
163-
RunConfiguration = SolutionItem.GetRunConfigurations ().FirstOrDefault (c => c.Id == ConfigurationId);
166+
ResolveRunConfiguration ();
164167
ItemId = null;
165168
ConfigurationId = null;
166169
}
167170
}
168-
171+
172+
internal void ResolveRunConfiguration ()
173+
{
174+
if (SolutionItem != null && ConfigurationId != null)
175+
RunConfiguration = SolutionItem.GetRunConfigurations ().FirstOrDefault (c => c.Id == ConfigurationId);
176+
}
177+
169178
public SolutionItem SolutionItem { get; internal set; }
170179
public SolutionItemRunConfiguration RunConfiguration { get; internal set; }
171180
}

main/tests/MonoDevelop.Core.Tests/MonoDevelop.Projects/SolutionTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,40 @@ public async Task SolutionDisposed_ActiveProjectTasks_MSBuildEngineManagerNotDis
10551055
WorkspaceObject.UnregisterCustomExtension (en);
10561056
}
10571057
}
1058+
1059+
[Test]
1060+
public async Task MultiRunConfig_ReloadProject_ProjectRunConfigUpdatedInMultiRunConfig ()
1061+
{
1062+
string solFile = Util.GetSampleProject ("test-multi-run-config-reload", "test-multi-run-config-reload.sln");
1063+
1064+
using (var sol = (Solution)await Services.ProjectService.ReadWorkspaceItem (Util.GetMonitor (), solFile)) {
1065+
var projectA = (DotNetProject)sol.FindProjectByName ("ProjectA");
1066+
var projectB = (DotNetProject)sol.FindProjectByName ("ProjectB");
1067+
Assert.IsNotNull (projectA);
1068+
Assert.IsNotNull (projectB);
1069+
1070+
var multiRunConfig = new MultiItemSolutionRunConfiguration ("MultiTestId", "multi");
1071+
var startupItem1 = new StartupItem (projectA, projectA.RunConfigurations.Single ());
1072+
multiRunConfig.Items.Add (startupItem1);
1073+
1074+
var startupItem2 = new StartupItem (projectB, projectB.RunConfigurations.Single ());
1075+
multiRunConfig.Items.Add (startupItem2);
1076+
1077+
sol.MultiStartupRunConfigurations.Add (multiRunConfig);
1078+
1079+
await sol.RootFolder.ReloadItem (Util.GetMonitor (), projectA);
1080+
1081+
// Ensure latest project instance is used by getting them from the solution again.
1082+
projectA = (DotNetProject)sol.FindProjectByName ("ProjectA");
1083+
projectB = (DotNetProject)sol.FindProjectByName ("ProjectB");
1084+
1085+
var runConfigA = multiRunConfig.Items.Single (item => item.SolutionItem == projectA);
1086+
Assert.AreEqual (projectA.RunConfigurations.Single (), runConfigA.RunConfiguration, "Multi-run config does not match project's run config (ProjectA)");
1087+
1088+
var runConfigB = multiRunConfig.Items.Single (item => item.SolutionItem == projectB);
1089+
Assert.AreEqual (projectB.RunConfigurations.Single (), runConfigB.RunConfiguration, "Multi-run config does not match project's run config (ProjectB)");
1090+
}
1091+
}
10581092
}
10591093

10601094
class SomeItem: SolutionItem
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace ProjectA
4+
{
5+
class MainClass
6+
{
7+
public static void Main (string[] args)
8+
{
9+
Console.WriteLine ("Project A: args.Length={0}", args.Length);
10+
}
11+
}
12+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">anycpu</Platform>
6+
<ProjectGuid>{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}</ProjectGuid>
7+
<OutputType>Exe</OutputType>
8+
<RootNamespace>ProjectA</RootNamespace>
9+
<AssemblyName>ProjectA</AssemblyName>
10+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|anycpu' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
<ExternalConsole>true</ExternalConsole>
21+
<IntermediateOutputPath>obj\anycpu\Debug</IntermediateOutputPath>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|anycpu' ">
24+
<Optimize>true</Optimize>
25+
<OutputPath>bin\Release</OutputPath>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<ExternalConsole>true</ExternalConsole>
29+
<IntermediateOutputPath>obj\anycpu\Release</IntermediateOutputPath>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
32+
<StartAction>Project</StartAction>
33+
<StartArguments>A1</StartArguments>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
43+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
4+
// Information about this assembly is defined by the following attributes.
5+
// Change them to the values specific to your project.
6+
7+
[assembly: AssemblyTitle ("ProjectA")]
8+
[assembly: AssemblyDescription ("")]
9+
[assembly: AssemblyConfiguration ("")]
10+
[assembly: AssemblyCompany ("Microsoft")]
11+
[assembly: AssemblyProduct ("")]
12+
[assembly: AssemblyCopyright ("Microsoft Corporation")]
13+
[assembly: AssemblyTrademark ("")]
14+
[assembly: AssemblyCulture ("")]
15+
16+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
17+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
18+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
19+
20+
[assembly: AssemblyVersion ("1.0.*")]
21+
22+
// The following attributes are used to specify the signing key for the assembly,
23+
// if desired. See the Mono documentation for more information about signing.
24+
25+
//[assembly: AssemblyDelaySign(false)]
26+
//[assembly: AssemblyKeyFile("")]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+

2+
using System;
3+
4+
namespace ProjectB
5+
{
6+
class MainClass
7+
{
8+
public static void Main (string[] args)
9+
{
10+
Console.WriteLine ("Project A: args.Length={0}", args.Length);
11+
}
12+
}
13+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">anycpu</Platform>
6+
<ProjectGuid>{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}</ProjectGuid>
7+
<OutputType>Exe</OutputType>
8+
<RootNamespace>ProjectB</RootNamespace>
9+
<AssemblyName>ProjectB</AssemblyName>
10+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
11+
</PropertyGroup>
12+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|anycpu' ">
13+
<DebugSymbols>true</DebugSymbols>
14+
<DebugType>full</DebugType>
15+
<Optimize>false</Optimize>
16+
<OutputPath>bin\Debug</OutputPath>
17+
<DefineConstants>DEBUG;</DefineConstants>
18+
<ErrorReport>prompt</ErrorReport>
19+
<WarningLevel>4</WarningLevel>
20+
<ExternalConsole>true</ExternalConsole>
21+
<IntermediateOutputPath>obj\anycpu\Debug</IntermediateOutputPath>
22+
</PropertyGroup>
23+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|anycpu' ">
24+
<Optimize>true</Optimize>
25+
<OutputPath>bin\Release</OutputPath>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
<ExternalConsole>true</ExternalConsole>
29+
<IntermediateOutputPath>obj\anycpu\Release</IntermediateOutputPath>
30+
</PropertyGroup>
31+
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Default' ">
32+
<StartAction>Project</StartAction>
33+
<StartArguments>B1 B2</StartArguments>
34+
</PropertyGroup>
35+
<ItemGroup>
36+
<Reference Include="System" />
37+
</ItemGroup>
38+
<ItemGroup>
39+
<Compile Include="Program.cs" />
40+
<Compile Include="Properties\AssemblyInfo.cs" />
41+
</ItemGroup>
42+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
43+
</Project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+

2+
using System.Reflection;
3+
using System.Runtime.CompilerServices;
4+
5+
// Information about this assembly is defined by the following attributes.
6+
// Change them to the values specific to your project.
7+
8+
[assembly: AssemblyTitle ("ProjectB")]
9+
[assembly: AssemblyDescription ("")]
10+
[assembly: AssemblyConfiguration ("")]
11+
[assembly: AssemblyCompany ("Microsoft")]
12+
[assembly: AssemblyProduct ("")]
13+
[assembly: AssemblyCopyright ("Microsoft Corporation")]
14+
[assembly: AssemblyTrademark ("")]
15+
[assembly: AssemblyCulture ("")]
16+
17+
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
18+
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
19+
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
20+
21+
[assembly: AssemblyVersion ("1.0.*")]
22+
23+
// The following attributes are used to specify the signing key for the assembly,
24+
// if desired. See the Mono documentation for more information about signing.
25+
26+
//[assembly: AssemblyDelaySign(false)]
27+
//[assembly: AssemblyKeyFile("")]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectA", "ProjectA\ProjectA.csproj", "{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}"
5+
EndProject
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProjectB", "ProjectB\ProjectB.csproj", "{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|anycpu = Debug|anycpu
11+
Release|anycpu = Release|anycpu
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}.Debug|anycpu.ActiveCfg = Debug|anycpu
15+
{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}.Debug|anycpu.Build.0 = Debug|anycpu
16+
{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}.Release|anycpu.ActiveCfg = Release|anycpu
17+
{1217D2CD-2C77-4AEF-AC43-418FC5DD7CE9}.Release|anycpu.Build.0 = Release|anycpu
18+
{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}.Debug|anycpu.ActiveCfg = Debug|anycpu
19+
{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}.Debug|anycpu.Build.0 = Debug|anycpu
20+
{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}.Release|anycpu.ActiveCfg = Release|anycpu
21+
{2D669FEF-FBF4-4183-87E6-A3A4D6C8C97F}.Release|anycpu.Build.0 = Release|anycpu
22+
EndGlobalSection
23+
EndGlobal

0 commit comments

Comments
 (0)