using Microsoft.Build.Tasks;
using Microsoft.Build.Utilities;
using NUnit.Framework;
+using System.IO;
using System.Text;
namespace MonoTests.Microsoft.Build.Tasks
"{DAE34193-B5C7-4488-A911-29EE15C84CBE}"
};
- CreateAndCheckProject (guids, project_ref_guids, new string[] {
- "AssignedProjects : foo0.csproj;foo1.csproj;foo2.csproj;foo3.csproj: SetConfig: Configuration=Release",
+ CreateAndCheckProject (guids, new bool[] {true, true, true, true, true, true},
+ project_ref_guids, new string[] {
+ "AssignedProjects : foo0.csproj;foo1.csproj;foo2.csproj;foo3.csproj;foo4.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1",
"AssignedProjects : foo2.csproj: SetPlatform: Platform=AnyCPU2",
"AssignedProjects : foo3.csproj: SetPlatform: Platform=AnyCPU3",
- "UnassignedProjects : foo4.csproj"},
+ "AssignedProjects : foo4.csproj: SetPlatform: Platform=AnyCPU4",
+ "UnassignedProjects : "},
true,
"A1#");
}
[Test]
- public void TestInvalidProjectGuid ()
+ public void TestNoGuidAndNoAbsolutePathFound()
{
string[] guids = new string[] {
+ "asd"
+ };
+
+ string[] project_ref_guids = new string[] {
+ "{DAE34193-B5C7-4488-A911-29EE15C84CB8}",
+ "invalid guid",
+ ""
+ };
+
+ CreateAndCheckProject (guids, new bool[]{false},
+ project_ref_guids,
+ new string[] {
+ "AssignedProjects : : SetConfig: ",
+ "AssignedProjects : : SetPlatform: ",
+ "UnassignedProjects : foo0.csproj;foo1.csproj;foo2.csproj"
+ },
+ true, "A1#");
+ }
+
+ [Test]
+ public void TestInvalidProjectGuidWithAbsolutePath ()
+ {
+ string[] guids = new string[] {
+ null, // no AbsPath
+ "another invalid guid", // has AbsPath
+ };
+
+ string[] project_ref_guids = new string[] {
+ "1234zxc", // this won't match because no AbsPath
+ "xzxoiu", // match with the second project, foo1.csproj
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}",
+ "badref" // no corresponding project at all
+ };
+
+ CreateAndCheckProject (guids, new bool[]{false, true},
+ project_ref_guids,
+ new string[] {
+ "AssignedProjects : foo1.csproj: SetConfig: Configuration=Release",
+ "AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU1",
+ "UnassignedProjects : foo0.csproj;foo2.csproj;foo3.csproj"
+ },
+ true, "A1#");
+ }
+
+ [Test]
+ public void TestNoGuidWithAbsolutePath ()
+ {
+ string[] guids = new string[] {
+ "",
+ null
};
string[] project_ref_guids = new string[] {
"invalid guid"
};
- CreateAndCheckProject (guids, project_ref_guids, null, false, "A1#");
+ CreateAndCheckProject (guids, new bool[]{true, false},
+ project_ref_guids,
+ new string[] {
+ "AssignedProjects : foo0.csproj: SetConfig: Configuration=Release",
+ "AssignedProjects : foo0.csproj: SetPlatform: Platform=AnyCPU0",
+ "UnassignedProjects : foo1.csproj;foo2.csproj"
+ },
+ true, "A1#");
}
[Test]
"{23F291D9-78DF-4133-8CF2-78CE104DDE63}"
};
- CreateAndCheckProject (guids, project_ref_guids,
+ CreateAndCheckProject (guids, new bool[]{false, true},
+ project_ref_guids,
new string [] {
"AssignedProjects : foo1.csproj: SetConfig: Configuration=Release",
"AssignedProjects : foo1.csproj: SetPlatform: Platform=AnyCPU0",
}
- void CreateAndCheckProject (string[] guids, string[] project_ref_guids, string[] messages, bool build_result, string prefix)
+ void CreateAndCheckProject (string[] guids, bool[] set_project_paths, string[] project_ref_guids, string[] messages, bool build_result, string prefix)
{
Engine engine = new Engine (Consts.BinPath);
Project project = engine.CreateNewProject ();
TestMessageLogger testLogger = new TestMessageLogger ();
engine.RegisterLogger (testLogger);
- string projectString = CreateProject (guids, project_ref_guids);
+ string projectString = CreateProject (guids, set_project_paths, project_ref_guids);
project.LoadXml (projectString);
try {
}
}
- string CreateProject (string[] guids, string[] project_ref_guids)
+ string CreateProject (string[] guids, bool[] set_project_paths, string[] project_ref_guids)
{
StringBuilder sb = new StringBuilder ();
sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
sb.Append ("\n" + GetUsingTask ("AssignProjectConfiguration"));
- sb.AppendFormat (@"<PropertyGroup>{0}</PropertyGroup>", CreateSolutionConfigurationProperty (guids, "Release|AnyCPU"));
+ sb.AppendFormat (@"<PropertyGroup>{0}</PropertyGroup>", CreateSolutionConfigurationProperty (guids, set_project_paths, "Release|AnyCPU"));
sb.Append (CreateProjectReferencesItemGroup (project_ref_guids));
sb.Append ("\n\t<Target Name=\"1\">\n");
return sb.ToString ();
}
- string CreateSolutionConfigurationProperty (string[] guids, string config_str)
+ string CreateSolutionConfigurationProperty (string[] guids, bool[] set_project_paths, string config_str)
{
+ string abs_proj_path_prefix = Path.GetFullPath ("foo");
StringBuilder sb = new StringBuilder ();
sb.Append ("\n<CurrentSolutionConfigurationContents>\n");
sb.Append ("\t<foo xmlns=\"\">\n");
for (int i = 0; i < guids.Length; i++) {
- sb.AppendFormat ("\t\t<bar Project=\"{0}\">{1}{2}</bar>\n",
+ sb.Append ("\t\t<bar");
+ if (guids[i] != null)
+ sb.AppendFormat (" Project=\"{0}\"", guids[i]);
+ if (set_project_paths[i])
+ sb.AppendFormat (" AbsolutePath=\"{0}{1}.csproj\" ", abs_proj_path_prefix, i);
+ sb.AppendFormat (">{1}{2}</bar>\n",
guids[i], config_str, i);
}
sb.Append ("\t</foo>\n");
{
StringBuilder sb = new StringBuilder ();
sb.Append ("\n<ItemGroup>\n");
- for (int i = 0; i < guids.Length; i ++)
- sb.AppendFormat ("\t<ProjectReference Include=\"foo{1}.csproj\"><Project>{0}</Project></ProjectReference>\n", guids [i], i);
+ for (int i = 0; i < guids.Length; i ++) {
+ sb.AppendFormat ("\t<ProjectReference Include=\"foo{0}.csproj\">", i);
+ if (guids[i] != null)
+ sb.AppendFormat ("<Project>{0}</Project>", guids[i]);
+ sb.Append ("</ProjectReference>\n");
+ }
sb.Append ("</ItemGroup>\n");
return sb.ToString ();
}