CreateNewProject() public méthode

public CreateNewProject ( ) : Microsoft.Build.BuildEngine.Project
Résultat Microsoft.Build.BuildEngine.Project
Exemple #1
0
		public void TestCondition1 ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<PropertyGroup>
						<A Condition='true'></A>
						<B Condition='false'></B>
						<C Condition='TRUE'></C>
						<D Condition='FALSE'></D>
						<E Condition=''>A</E>
					</PropertyGroup>
				</Project>
			";

			proj.LoadXml (documentString);

			Assert.IsNotNull (proj.EvaluatedProperties ["A"], "A1");
			Assert.IsNull (proj.EvaluatedProperties ["B"], "A2");
			Assert.IsNotNull (proj.EvaluatedProperties ["C"], "A3");
			Assert.IsNull (proj.EvaluatedProperties ["D"], "A4");
			Assert.IsNotNull (proj.EvaluatedProperties ["E"], "A5");
		}
		public void TestGetEnumerator ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='TrueTestTask'
					/>
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='FalseTestTask'
					/>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			
			IEnumerator en = project.UsingTasks.GetEnumerator ();
			en.MoveNext ();

			Assert.AreEqual ("Test/resources/TestTasks.dll", ((UsingTask) en.Current).AssemblyFile, "A1");
			Assert.AreEqual ("TrueTestTask", ((UsingTask) en.Current).TaskName, "A2");

			en.MoveNext ();

			Assert.AreEqual ("Test/resources/TestTasks.dll", ((UsingTask) en.Current).AssemblyFile, "A3");
			Assert.AreEqual ("FalseTestTask", ((UsingTask) en.Current).TaskName, "A4");

			Assert.IsFalse (en.MoveNext ());
		}
		public void TestExecution1 ()
		{
			Engine engine;
			Project project;

			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='1'>
						<GetFrameworkPath>
							<Output
								TaskParameter='Path'
								PropertyName='Path'
							/>
						</GetFrameworkPath>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			Assert.IsTrue (project.Build ("1"), "A1");

			Assert.IsNotNull (project.EvaluatedProperties ["Path"], "A2");
			Assert.IsTrue (String.Empty != project.EvaluatedProperties ["Path"].FinalValue, "A3");
		}
        public void TestFalseWhen () {
            Engine engine;
            Project project;
            BuildItemGroup[] groups = new BuildItemGroup[1];

            string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
                    <Choose>
                        <When Condition=""'$(Configuration)' == 'False'"">
					        <ItemGroup>
						        <A Include='a' />
					        </ItemGroup>
                        </When>
                    </Choose>
				</Project>
			";

            engine = new Engine (Consts.BinPath);
            project = engine.CreateNewProject ();
            project.LoadXml (documentString);

            //Assert.AreEqual (1, project.ItemGroups.Count, "A1");
            Assert.AreEqual (0, project.PropertyGroups.Count, "A2");
            Assert.AreEqual (0, project.EvaluatedItems.Count, "A3");
            Assert.AreEqual (0, project.EvaluatedItemsIgnoringCondition.Count, "A4");
        }
		public void TestAssemblyFile2 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='SimpleTask'
					/>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			
			IEnumerator en = project.UsingTasks.GetEnumerator ();
			en.MoveNext ();
			
			UsingTask ut = (UsingTask) en.Current;
			
			Assert.AreEqual ("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1");
			Assert.IsNull (ut.AssemblyName, "A2");
			Assert.AreEqual (null, ut.Condition, "A3");
			Assert.AreEqual (false, ut.IsImported, "A4");
			Assert.AreEqual ("SimpleTask", ut.TaskName, "A5");
		}
Exemple #6
0
		public void TestFromXml2 ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='Target' Condition='false' DependsOnTargets='X' >
					</Target>
                                </Project>
                        ";

			engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			Target[] t = new Target [1];
			project.Targets.CopyTo (t, 0);

			Assert.AreEqual ("false", t [0].Condition, "A1");
			Assert.AreEqual ("X", t [0].DependsOnTargets, "A2");

			t [0].Condition = "true";
			t [0].DependsOnTargets = "A;B";

			Assert.AreEqual ("true", t [0].Condition, "A3");
			Assert.AreEqual ("A;B", t [0].DependsOnTargets, "A4");
		}
		public void TestProperties2 ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
					<PropertyGroup>
						<A>A</A>
						<B>B</B>
					</PropertyGroup>

					<Target Name='Main' >
						<StringTestTask Array='$(A)$(B)'>
							<Output TaskParameter='Array' ItemName='Out' />
						</StringTestTask>
					</Target>
				</Project>
			";

			proj.LoadXml (documentString);
			proj.Build ("Main");
			Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("Out").Count, "A1");
			Assert.AreEqual ("AB", proj.GetEvaluatedItemsByName ("Out") [0].Include, "A2");
		}
		public void TestExecution1 ()
		{
			Engine engine;
			Project project;

			string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup>
						<Dir Include='b' />
						<Dir Include='c' />
						<Dir Include='d\e' />
					</ItemGroup>
					<Target Name='1'>
						<CombinePath BasePath='a' Paths='@(Dir)'>
							<Output
								TaskParameter='CombinedPaths'
								ItemName='Out'
							/>
						</CombinePath>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			Assert.IsTrue (project.Build ("1"), "A1");

			BuildItemGroup output = project.GetEvaluatedItemsByName ("Out");
			Assert.AreEqual (3, output.Count, "A2");
			Assert.AreEqual (Path.Combine ("a", "b"), output [0].FinalItemSpec, "A3");
			Assert.AreEqual (Path.Combine ("a", "c"), output [1].FinalItemSpec, "A4");
			Assert.AreEqual (Path.Combine ("a", Path.Combine ("d", "e")), output [2].FinalItemSpec, "A5");

		}
		public void TestItems1 ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup>
						<Item0 Include='A' />
						<Item1 Include='A;B;C' />
						<Item2 Include='@(Item1);A;D' />
						<Item3 Include='@(Item2)' Exclude='A' />
						<Item4 Include='@(Item1);Q' Exclude='@(Item2)' />
						<Item5 Include='@(Item1)' Exclude='@(Item2)' />
						<Item6 Include='@(Item2)' Exclude='@(Item1)' />
						<Item7 Include='@(item_that_doesnt_exist)' />
					</ItemGroup>
				</Project>
			";

			proj.LoadXml (documentString);
			CheckItems (proj, "Item0", "A1", "A");
			CheckItems (proj, "Item1", "A2", "A", "B", "C");
			CheckItems (proj, "Item2", "A3", "A", "B", "C", "A", "D");
			CheckItems (proj, "Item3", "A4", "B", "C", "D");
			CheckItems (proj, "Item4", "A5", "Q");
			CheckItems (proj, "Item5", "A6");
			CheckItems (proj, "Item6", "A7", "D");
			CheckItems (proj, "Item7", "A8");
		}
Exemple #10
0
        internal static void EnsureCorrectTempProject(MSBuild.Project baseProject,
                                                      string configuration, string platform,
                                                      ref MSBuild.Project tempProject)
        {
            if (configuration == null && platform == null)
            {
                // unload temp project
                if (tempProject != null && tempProject != baseProject)
                {
                    tempProject.ParentEngine.UnloadAllProjects();
                }
                tempProject = null;
                return;
            }
            if (configuration == null)
            {
                configuration = baseProject.GetEvaluatedProperty("Configuration");
            }
            if (platform == null)
            {
                platform = baseProject.GetEvaluatedProperty("Platform");
            }

            if (tempProject != null &&
                tempProject.GetEvaluatedProperty("Configuration") == configuration &&
                tempProject.GetEvaluatedProperty("Platform") == platform)
            {
                // already correct
                return;
            }
            if (baseProject.GetEvaluatedProperty("Configuration") == configuration &&
                baseProject.GetEvaluatedProperty("Platform") == platform)
            {
                tempProject = baseProject;
                return;
            }
            // create new project

            // unload old temp project
            if (tempProject != null && tempProject != baseProject)
            {
                tempProject.ParentEngine.UnloadAllProjects();
            }
            try {
                MSBuild.Engine engine = CreateEngine();
                tempProject = engine.CreateNewProject();
                // tell MSBuild the path so that projects containing <Import Project="relativePath" />
                // can be loaded
                tempProject.FullFileName = baseProject.FullFileName;
                MSBuildBasedProject.InitializeMSBuildProject(tempProject);
                tempProject.LoadXml(baseProject.Xml);
                tempProject.SetProperty("Configuration", configuration);
                tempProject.SetProperty("Platform", platform);
            } catch (Exception ex) {
                ICSharpCode.Core.MessageService.ShowWarning(ex.ToString());
                tempProject = baseProject;
            }
        }
		public void TestAddNewProperty2 ()
		{
			Engine engine;
			Project project;

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();

			project.EvaluatedProperties.AddNewProperty ("a", "b");
		}
		public void TestHintPath1 ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\test.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
Exemple #13
0
		public void TestAdd1 ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Import Project='project_that_doesnt_exist'/>
                                </Project>
                        ";

                        engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);
		}
Exemple #14
0
		public void TestRootElement ()
		{
			Engine engine;
			Project proj;
			string documentString = @"
			<something>
			</something>
			";

			engine = new Engine (Consts.BinPath);
			proj = engine.CreateNewProject ();
			proj.LoadXml (documentString);
		}
		public void ResolveBinary_FancyStuff ()
		{
			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly (null, @"Test\resources\binary\FancyStuff.dll"));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big[0].Include.EndsWith ("FancyStuff.dll"), "A3");
			
			big = project.GetEvaluatedItemsByName ("ResolvedDependencyFiles");
			Assert.AreEqual (1, big.Count, "A4");
			Assert.IsTrue (big.Cast<BuildItem> ().Any (item => item.Include.EndsWith ("SimpleWrite.dll")), "A5");
		}
		public void TestGac1 ()
		{
			var gacDir = GetGacDir ();

			if (gacDir == null || !System.IO.Directory.Exists (gacDir))
				Assert.Ignore ("GAC not found.");

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (ResolveAssembly ("System", null));
			
			Assert.IsTrue (project.Build ("A"), "A1");
			big = project.GetEvaluatedItemsByName ("ResolvedFiles");
			Assert.AreEqual (1, big.Count, "A2");
			Assert.IsTrue (big [0].Include.EndsWith (".dll"), "A3");
		}
Exemple #17
0
		public void TestDefaultTasks ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='Main'>
						<Message Text='Message' />
					</Target>
				</Project>
			";

			proj.LoadXml (documentString);
			proj.Build ("Main");
		}
		public void TestEmpty ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                </Project>
                        ";

			engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			Assert.AreEqual (0, project.Targets.Count, "A1");
			Assert.IsFalse (project.Targets.IsSynchronized, "A2");
			Assert.IsNotNull (project.Targets.SyncRoot, "A3");
		}
		public void TestMakeRelative ()
		{
			string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
					<PropertyGroup>
						<Path1>c:\users\</Path1>
						<Path2>c:\users\username\</Path2>
						<Path3>/home/user/</Path3>
						<Path4>/home/user/username/</Path4>
						<Path5>/home/user/</Path5>
						<Path6>/tmp/test/file</Path6>
						<Path7>/home/user/</Path7>
						<Path8>/home/user/username/path with spaces + special? chars (1)/</Path8>
						<Path9>c:\users</Path9>
						<Path10>c:\users\username\test\</Path10>
						<Path11>/home/user</Path11>
						<Path12>/home/user/username/test/</Path12>
						<MakeRelative1>$([MSBuild]::MakeRelative($(Path1), $(Path2)))</MakeRelative1>
						<MakeRelative2>$([MSBuild]::MakeRelative($(Path2), $(Path1)))</MakeRelative2>
						<MakeRelative3>$([MSBuild]::MakeRelative($(Path3), $(Path4)))</MakeRelative3>
						<MakeRelative4>$([MSBuild]::MakeRelative($(Path4), $(Path3)))</MakeRelative4>
						<MakeRelative5>$([MSBuild]::MakeRelative($(Path5), $(Path6)))</MakeRelative5>
						<MakeRelative6>$([MSBuild]::MakeRelative($(Path7), $(Path8)))</MakeRelative6>
						<MakeRelative7>$([MSBuild]::MakeRelative($(Path9), $(Path10)))</MakeRelative7>
						<MakeRelative8>$([MSBuild]::MakeRelative($(Path11), $(Path12)))</MakeRelative8>
					</PropertyGroup>
				</Project>
			";

			if (Path.DirectorySeparatorChar == '\\') {
				documentString = documentString.Replace ("/home", "c:/home");
				documentString = documentString.Replace ("/tmp", "c:/tmp");
			}

			var engine = new Engine (Consts.BinPath);
			var project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative1"].FinalValue, "#1");
			Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative2"].FinalValue, "#2");
			Assert.AreEqual (@"username\", project.EvaluatedProperties ["MakeRelative3"].FinalValue, "#3");
			Assert.AreEqual (@"..\", project.EvaluatedProperties ["MakeRelative4"].FinalValue, "#4");
			Assert.AreEqual (@"..\..\tmp\test\file", project.EvaluatedProperties ["MakeRelative5"].FinalValue, "#5");
			Assert.AreEqual (@"username\path with spaces + special? chars (1)\", project.EvaluatedProperties ["MakeRelative6"].FinalValue, "#6");
			Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative7"].FinalValue, "#7");
			Assert.AreEqual (@"username\test\", project.EvaluatedProperties ["MakeRelative8"].FinalValue, "#8");
		}
		public void TestAdd1 ()
		{
			string first = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Import Project='second.proj'/>
                                </Project>
";
			using (StreamWriter sw = new StreamWriter ("Test/resources/first.proj")) {
				sw.Write (first);
			}

			string second = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                </Project>
";
			using (StreamWriter sw = new StreamWriter ("Test/resources/second.proj")) {
				sw.Write (second);
			}

                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
						<Import Project='Test\resources\first.proj'/>
						<Import Project='Test\resources\Import.csproj' Condition='false'/>
                                </Project>
                        ";

                        engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			Import[] t = new Import [2];
			Assert.AreEqual (2, project.Imports.Count, "Number of imports");
			project.Imports.CopyTo (t, 0);

			string base_dir = Path.Combine (Environment.CurrentDirectory, Path.Combine ("Test", "resources"));

			Assert.IsNull (t [0].Condition, "A1");

			Assert.AreEqual (false, t[0].IsImported, "A5");
			Assert.AreEqual ("Test\\resources\\first.proj", t[0].ProjectPath, "A6");
			Assert.AreEqual (Path.Combine (base_dir, "first.proj"), t[0].EvaluatedProjectPath, "A7");

			Assert.AreEqual (true, t[1].IsImported, "A2");
			Assert.AreEqual ("second.proj", t[1].ProjectPath, "A3");
			Assert.AreEqual (Path.Combine (base_dir, "second.proj"), t[1].EvaluatedProjectPath, "A4");
		}
		public void TestCopyTo2 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<ItemGroup>
						<Name Include='Value' />
					</ItemGroup>
				</Project>
			";

			engine = new Engine (Consts.BinPath);

			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			
			project.ItemGroups.CopyTo (new BuildItemGroup [1], -1);
		}
Exemple #22
0
		public void TestAdd2 ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Import Project='Test/resources/Import.csproj'/>
					<Import Project='Test/resources/Import.csproj'/>
                                </Project>
                        ";

                        engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			Assert.AreEqual (1, project.Imports.Count, "A1");
			Assert.AreEqual (false, project.Imports.IsSynchronized, "A2");
		}
		public void TestCopyTo1 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<PropertyGroup>
						<Name>Value</Name>
					</PropertyGroup>
				</Project>
			";

			engine = new Engine (Consts.BinPath);

			project = engine.CreateNewProject ();
			project.LoadXml (documentString);
			
			project.PropertyGroups.CopyTo (null, 0);
		}
		public void Test1 ()
		{
			string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
				<ItemGroup>
					<ResXFile Include=""Item1"">
						<Culture>fr</Culture>
					</ResXFile>
					<ResXFile Include=""Item2"">
						<Culture>fr</Culture>
					</ResXFile>
					<ResXFile Include=""Item3"">
						<Culture>en</Culture>
					</ResXFile>
					<ResXFile Include=""Item4"">
						<Culture>gb</Culture>
					</ResXFile>
					<ResXFile Include=""Item5"">
						<Culture>fr</Culture>
					</ResXFile>
					<ResXFile Include=""Item6"">
						<Culture>it</Culture>
					</ResXFile>
				</ItemGroup>

				<Target Name=""ShowMessage"">
					<Message
						Text = ""Culture: %(ResXFile.Culture) -- ResXFile: @(ResXFile)"" />
				</Target>
			  </Project>";

			Engine engine = new Engine (Consts.BinPath);
			Project project = engine.CreateNewProject ();

			TestMessageLogger testLogger = new TestMessageLogger ();
			engine.RegisterLogger (testLogger);

			project.LoadXml (projectString);
			Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");

			CheckMessage (testLogger, "fr", "Item1;Item2;Item5", "A2");
			CheckMessage (testLogger, "en", "Item3", "A3");
			CheckMessage (testLogger, "gb", "Item4", "A4");
			CheckMessage (testLogger, "it", "Item6", "A5");

			CheckEngineEventCounts (testLogger, 1, 1, 4, 4);
		}
Exemple #25
0
		public void TestBuild2 ()
		{
			Engine engine;
			Project project;

			string documentString = @"
				<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
					<Target Name='1' DependsOnTargets='2'>
					</Target>
				</Project>
			";

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
			project.LoadXml (documentString);

			Assert.IsFalse (project.Build ("1"));
		}
		public void TestProperties1 ()
		{
			Engine engine = new Engine (Consts.BinPath);
			Project proj = engine.CreateNewProject ();

			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<PropertyGroup>
						<Config>debug</Config>
						<ExpProp>$(Config)-$(Config)</ExpProp>
					</PropertyGroup>
				</Project>
			";

			proj.LoadXml (documentString);
			Assert.AreEqual (1, proj.PropertyGroups.Count, "A1");
			Assert.AreEqual ("debug", proj.GetEvaluatedProperty ("Config"), "A2");
			Assert.AreEqual ("debug-debug", proj.GetEvaluatedProperty ("ExpProp"), "A3");
		}
		public void TestAssemblyFile1 ()
		{
			string documentString = @"
				<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<UsingTask
						AssemblyFile='Test/resources/TestTasks.dll'
						TaskName='TrueTestTask'
					/>
				</Project>
			";

                        engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);
                        
                        Assert.AreEqual (1, project.UsingTasks.Count, "A1");
                        Assert.AreEqual (false, project.UsingTasks.IsSynchronized, "A2");
                        Assert.AreEqual (typeof (object), project.UsingTasks.SyncRoot.GetType (), "A3");
		}
		public void TestAddNewTarget1 ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
                                </Project>
                        ";

			engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			project.Targets.AddNewTarget ("name");

			Assert.AreEqual (1, project.Targets.Count, "A1");
			Assert.AreEqual ("name", project.Targets ["name"].Name, "A2");
			Assert.IsFalse (project.Targets ["name"].IsImported, "A3");
			Assert.AreEqual (String.Empty, project.Targets ["name"].Condition, "A4");
			Assert.AreEqual (String.Empty, project.Targets ["name"].DependsOnTargets, "A5");	
		}
Exemple #29
0
		public void TestDefaultTargetsAttribute ()
		{
			Engine engine;
			Project proj;
			Project cproj;
			string documentString = @"
			<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" DefaultTargets=""Build;Compile"">
			</Project>
			";
			
			engine = new Engine (Consts.BinPath);
			proj = engine.CreateNewProject ();
			Assert.AreEqual (String.Empty, proj.FullFileName, "A1");

			proj.LoadXml (documentString);
			Assert.AreEqual (String.Empty, proj.FullFileName, "A2");
			proj.DefaultTargets = "Build";
			Assert.AreEqual ("Build", proj.DefaultTargets, "A3");
			cproj = CloneProject (proj);
			Assert.AreEqual (proj.DefaultTargets, cproj.DefaultTargets, "A4");
		}
Exemple #30
0
		public void SetUp ()
		{
			if ('/' == DSC) {
				OS = OsType.Unix;
			} else if ('\\' == DSC) {
				OS = OsType.Windows;
			} else {
				OS = OsType.Mac;
				//FIXME: For Mac. figure this out when we need it
			}

			files = new string [] {
				//resx files
				".\\foo.resx", @"bar\foo.resx", 
				"foo.fr.resx", @"dir\abc.en.resx", "foo.bar.resx",
				//non-resx
				"sample.txt", @"bar\sample.txt",
				"sample.it.png", @"dir\sample.en.png", "sample.inv.txt"};

			engine = new Engine (Consts.BinPath);
			project = engine.CreateNewProject ();
		}
Exemple #31
0
		public void TestFromXml1 ()
		{
                        string documentString = @"
                                <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
					<Target Name='Target'>
					</Target>
                                </Project>
                        ";

			engine = new Engine (Consts.BinPath);

                        project = engine.CreateNewProject ();
                        project.LoadXml (documentString);

			Target[] t = new Target [1];
			project.Targets.CopyTo (t, 0);

			Assert.AreEqual (String.Empty, t [0].Condition, "A1");
			Assert.AreEqual (String.Empty, t [0].DependsOnTargets, "A2");
			Assert.IsFalse (t [0].IsImported, "A3");
			Assert.AreEqual ("Target", t [0].Name, "A4");
		}
Exemple #32
0
        /// <summary>
        /// Initializes the in memory project. Sets BuildEnabled on the project to true.
        /// </summary>
        /// <param name="engine">The build engine to use to create a build project.</param>
        /// <param name="fullProjectPath">The full path of the project.</param>
        /// <returns>A loaded msbuild project.</returns>
        internal static MSBuild.Project InitializeMsBuildProject(MSBuild.Engine buildEngine, string fullProjectPath)
        {
            if (buildEngine == null)
            {
                throw new ArgumentNullException("engine");
            }

            if (String.IsNullOrEmpty(fullProjectPath))
            {
                throw new ArgumentException(SR.GetString(SR.InvalidParameter), "fullProjectPath");
            }

            // Check if the project already has been loaded with the fullProjectPath. If yes return the build project associated to it.
            MSBuild.Project buildProject = buildEngine.GetLoadedProject(fullProjectPath);

            if (buildProject == null)
            {
                buildProject = buildEngine.CreateNewProject();
                buildProject.BuildEnabled = true;
                buildProject.Load(fullProjectPath);
            }

            return(buildProject);
        }