public void ConditionalCyclicDependence() { string project_xml = @"<Project DefaultTargets='Build' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <PropertyGroup> <C>False</C> </PropertyGroup> <Target Name='Build' DependsOnTargets='ResolveReferences' /> <Target Name='Build2' DependsOnTargets='Bar' /> <Target Name='ResolveReferences' DependsOnTargets='Foo;Bar' /> <Target Name='Foo'> <CreateProperty Value='True'> <Output TaskParameter='Value' PropertyName='C' /> </CreateProperty> </Target> <Target Name='Bar' Condition='!($(C))' DependsOnTargets='ResolveReferences'> </Target> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectInstanceTest.ConditionalCyclicDependence.proj"; var proj = new ProjectInstance(root, null, "4.0", ProjectCollection.GlobalProjectCollection); Assert.IsTrue(proj.Build(), "#1"); Assert.IsFalse(proj.Build("Build2", new ILogger [0]), "#2"); }
public ProjectInstance Compile() { if (_compiledProject != null) { return(_compiledProject); } Project project = Load(); if (project == null) { return(null); } // Compile the project using (_buildEnvironment.SetEnvironmentVariables()) { ProjectInstance projectInstance = project.CreateProjectInstance(); if (Manager.CleanBeforeCompile && !projectInstance.Build("Clean", GetLoggers())) { return(null); } if (!projectInstance.Build("Compile", GetLoggers())) { return(null); } _compiledProject = projectInstance; return(_compiledProject); } }
public ProjectInstance Compile() { if (_compiledProject != null) { return(_compiledProject); } Project project = Load(); if (project == null) { return(null); } // Compile the project using (new BuildEnvironment(GlobalProperties)) { ProjectInstance projectInstance = project.CreateProjectInstance(); if (!projectInstance.Build("Clean", _logger == null ? null : new ILogger[] { _logger })) { return(null); } if (!projectInstance.Build("Compile", _logger == null ? null : new ILogger[] { _logger })) { return(null); } _compiledProject = projectInstance; return(_compiledProject); } }
public ProjectInstance Compile() { if (_compiledProject != null) { return(_compiledProject); } Project project = Load(); if (project == null) { return(null); } // Compile the project _buildEnvironment.SetEnvironmentVars(GlobalProperties); try { ProjectInstance projectInstance = project.CreateProjectInstance(); if (!projectInstance.Build("Clean", _logger == null ? null : new ILogger[] { _logger })) { return(null); } if (!projectInstance.Build("Compile", _logger == null ? null : new ILogger[] { _logger })) { return(null); } _compiledProject = projectInstance; return(_compiledProject); } finally { _buildEnvironment.UnsetEnvironmentVars(); } }
public void InputsAndOutputs() { string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <Target Name='Foo' Inputs='inputsandoutputstest.txt' Outputs='inputsandoutputstest.txt'> <Error Text='error' /> </Target> </Project>"; try { if (!File.Exists("inputsandoutputstest.txt")) { File.CreateText("inputsandoutputstest.txt").Close(); } var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectTargetInstanceTest.InputsAndOutputs.proj"; var proj = new ProjectInstance(root); Assert.IsTrue(proj.Build(), "#1"); // if it does not skip Foo, it results in an error. } finally { if (File.Exists("inputsandoutputstest.txt")) { File.Delete("inputsandoutputstest.txt"); } } }
// To NOT reuse this IBuildEngine instance for different build, we create another BuildManager and BuildSubmisson and then run it. public bool BuildProjectFile(string projectFileName, string[] targetNames, IDictionary globalProperties, IDictionary targetOutputs, string toolsVersion) { toolsVersion = string.IsNullOrEmpty(toolsVersion) ? project.ToolsVersion : toolsVersion; var globalPropertiesThatMakeSense = new Dictionary <string, string> (); foreach (DictionaryEntry p in globalProperties) { globalPropertiesThatMakeSense [(string)p.Key] = (string)p.Value; } var projectToBuild = new ProjectInstance(ProjectRootElement.Create(XmlReader.Create(projectFileName)), globalPropertiesThatMakeSense, toolsVersion, Projects); // Not very sure if ALL of these properties should be added, but some are certainly needed. foreach (var p in this.project.Properties.Where(p => !globalProperties.Contains(p.Name))) { projectToBuild.SetProperty(p.Name, p.EvaluatedValue); } IDictionary <string, TargetResult> outs; var ret = projectToBuild.Build(targetNames ?? new string [] { "Build" }, Projects.Loggers, out outs); foreach (var p in outs) { targetOutputs [p.Key] = p.Value.Items ?? new ITaskItem [0]; } return(ret); }
public ProjectInstance Execute(Project project) { _logger.LogVerbose($"Beginning design-time build of project {project.FullPath}."); _logger.LogVerbose("Setting the following global properties:"); foreach (KeyValuePair <string, string> kvp in _globalProperties) { project.SetGlobalProperty(kvp.Key, kvp.Value); _logger.LogVerbose($" {kvp.Key}={kvp.Value}"); } ProjectInstance projectInstance = project.CreateProjectInstance(); var designTimeBuildTargets = new string[] { "CollectResolvedSDKReferencesDesignTime", "CollectPackageReferences", "ResolveComReferencesDesignTime", "ResolveProjectReferencesDesignTime", "BuiltProjectOutputGroup", "ResolveAssemblyReferencesDesignTime", "CollectSDKReferencesDesignTime", "ResolvePackageDependenciesDesignTime", "CompileDesignTime", "CollectFrameworkReferences", "CollectUpToDateCheckBuiltDesignTime", "CollectPackageDownloads", "CollectAnalyzersDesignTime", "CollectUpToDateCheckInputDesignTime", "CollectUpToDateCheckOutputDesignTime", "CollectResolvedCompilationReferencesDesignTime" }; SimpleMsBuildLogger buildLogger; bool result = false; int retries = 0; // Retrying here as there are some odd cases where a file will be in use by another process // long enough for this to fail, but will work on a subsequent attempt. do { buildLogger = new SimpleMsBuildLogger(); _logger.LogVerbose($"Attempting design-time build # {retries + 1}..."); result = projectInstance.Build(designTimeBuildTargets, new Microsoft.Build.Framework.ILogger[] { buildLogger }); }while (!result && (++retries < _numRetries)); if (!result || _alwaysLogBuildLog) { _logger.LogVerbose("Design time build log:"); _logger.LogVerbose(buildLogger.LogText); _logger.LogVerbose(string.Empty); } if (!result) { throw new Exception("Failed to build project.\r\n" + buildLogger.ErrorText); } return(projectInstance); }
public void MultipleBinaryCondition() { string cond = @"$(AndroidIncludeDebugSymbols) == '' And Exists ('$(_IntermediatePdbFile)') And '$(OS)' == 'Windows_NT'"; string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <PropertyGroup> <X>a/b/c.txt</X> </PropertyGroup> <Target Name='Foo'> <CreateItem Include='$(X)'> <Output TaskParameter='Include' ItemName='I' /> </CreateItem> <CreateProperty Value=""@(I->'%(Filename)%(Extension)')""> <Output TaskParameter='Value' PropertyName='P' /> </CreateProperty> <Error Text=""Expected 'c.txt' but got '$(P)'"" Condition=""" + cond + @""" /> </Target> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); var p = new ProjectInstance(root); var sw = new StringWriter(); var result = p.Build(new ILogger [] { new ConsoleLogger(LoggerVerbosity.Minimal, sw.WriteLine, null, null) }); Assert.IsTrue(result, "#1: " + sw); }
public void Build() { // Setting the current directory to the MSBuild running location. It *should* be this // already, but if it's not some other test changed it and didn't change it back. If // the directory does not include the reference dlls the compilation will fail. Directory.SetCurrentDirectory(BuildEnvironmentHelper.Instance.CurrentMSBuildToolsDirectory); string projectFileContent = @" <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <UsingTask TaskName='Microsoft.Build.Tasks.Message' AssemblyFile='Microsoft.Build.Tasks.Core.dll'/> <ItemGroup> <i Include='i0'/> </ItemGroup> <Target Name='Build'> <Message Text='Building...'/> <Message Text='Completed!'/> </Target> </Project>"; ProjectInstance projectInstance = GetProjectInstance(projectFileContent); List <ILogger> loggers = new List <ILogger>(); MockLogger mockLogger = new MockLogger(_output); loggers.Add(mockLogger); bool success = projectInstance.Build("Build", loggers); Assert.True(success); mockLogger.AssertLogContains(new string[] { "Building...", "Completed!" }); }
public void TaskNodesDieAfterBuild() { using (TestEnvironment env = TestEnvironment.Create()) { string pidTaskProject = $@" <Project> <UsingTask TaskName=""ProcessIdTask"" AssemblyName=""net.r_eg.IeXod.Engine.UnitTests"" TaskFactory=""TaskHostFactory"" /> <Target Name='AccessPID'> <ProcessIdTask> <Output PropertyName=""PID"" TaskParameter=""Pid"" /> </ProcessIdTask> </Target> </Project>"; TransientTestFile project = env.CreateFile("testProject.csproj", pidTaskProject); ProjectInstance projectInstance = new ProjectInstance(project.Path); projectInstance.Build().ShouldBeTrue(); string processId = projectInstance.GetPropertyValue("PID"); string.IsNullOrEmpty(processId).ShouldBeFalse(); Int32.TryParse(processId, out int pid).ShouldBeTrue(); Process.GetCurrentProcess().Id.ShouldNotBe <int>(pid); try { Process taskHostNode = Process.GetProcessById(pid); taskHostNode.WaitForExit(2000).ShouldBeTrue(); } // We expect the TaskHostNode to exit quickly. If it exits before Process.GetProcessById, it will throw an ArgumentException. catch (ArgumentException e) { e.Message.ShouldBe($"Process with an Id of {pid} is not running."); } } }
public void FirstUsingTaskTakesPrecedenceCommon(bool importFirst, bool buildShouldSucceed) { string thisAssembly = new Uri(GetType().Assembly.CodeBase).LocalPath; string filename = "Test/ProjectTargetInstanceTest.FirstUsingTaskTakesPrecedence.Import.proj"; string imported_xml = string.Format(@"<Project DefaultTargets='Foo' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <UsingTask TaskName='MonoTests.Microsoft.Build.Execution.MyTask' AssemblyFile='{0}' /> </Project>", thisAssembly); string usingTask = string.Format("<UsingTask TaskName='MonoTests.Microsoft.Build.Execution.SubNamespace.MyTask' AssemblyFile='{0}' />", thisAssembly); string import = string.Format("<Import Project='{0}' />", filename); string project_xml = string.Format(@"<Project DefaultTargets='Foo' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> {0} {1} <Target Name='Foo'> <MyTask /> </Target> </Project>", importFirst ? import : usingTask, importFirst ? usingTask : import); try { File.WriteAllText(filename, imported_xml); var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); Assert.IsTrue(root.UsingTasks.All(u => !string.IsNullOrEmpty(u.AssemblyFile)), "#1"); Assert.IsTrue(root.UsingTasks.All(u => string.IsNullOrEmpty(u.AssemblyName)), "#2"); root.FullPath = "ProjectTargetInstanceTest.FirstUsingTaskTakesPrecedence.proj"; var proj = new ProjectInstance(root); Assert.AreEqual(buildShouldSucceed, proj.Build(), "#3"); } finally { File.Delete(filename); } }
public void EvaluatePropertyWithQuotation() { string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <ItemGroup> <Foo Include='abc/xxx.txt' /> </ItemGroup> <PropertyGroup> <B>foobar</B> </PropertyGroup> <Target Name='default'> <CreateProperty Value=""@(Foo->'%(Filename)%(Extension)')""> <Output TaskParameter='Value' PropertyName='P' /> </CreateProperty> <CreateProperty Value='$(B)|$(P)'> <Output TaskParameter='Value' PropertyName='Q' /> </CreateProperty> </Target> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectInstanceTest.EvaluatePropertyWithQuotation.proj"; var proj = new ProjectInstance(root); proj.Build(); var p = proj.GetProperty("P"); Assert.AreEqual("xxx.txt", p.EvaluatedValue, "#1"); var q = proj.GetProperty("Q"); Assert.AreEqual("foobar|xxx.txt", q.EvaluatedValue, "#2"); }
public void ItemsAndPostEvaluationCondition() { // target-assigned property X is not considered when evaluating condition for C. string project_xml = @"<Project DefaultTargets='X;Y' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <ItemGroup> <A Include='foo.txt' /> <B Condition='False' Include='bar.txt' /> <C Condition=""'$(X)'=='True'"" Include='baz.txt' /> </ItemGroup> <Target Name='X'> <CreateProperty Value='True'> <Output TaskParameter='Value' PropertyName='X' /> </CreateProperty> </Target> <Target Name='Y'> <Error Condition=""'@(C)'==''"" Text='missing C. X is $(X)' /> </Target> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectInstanceTest.ItemsAndPostEvaluationCondition.proj"; var proj = new ProjectInstance(root); Assert.AreEqual(1, proj.Items.Count, "Count1"); Assert.IsFalse(proj.Build(), "Build"); Assert.AreEqual(1, proj.Items.Count, "Count2"); }
[Category("NotWorking")] // until we figure out why it fails on wrench. public void ItemsInTargets() { string project_xml = @"<Project DefaultTargets='Default' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <Target Name='Default'> <PropertyGroup> <_ExplicitMSCorlibPath>$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll</_ExplicitMSCorlibPath> </PropertyGroup> <ItemGroup> <_ExplicitReference Include='$(_ExplicitMSCorlibPath)' Condition='Exists($(_ExplicitMSCorlibPath))'> <Private>false</Private> </_ExplicitReference> </ItemGroup> </Target> <Import Project='$(MSBuildBinPath)\\Microsoft.CSharp.targets' /> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectInstanceTest.ConditionalExpression.proj"; var proj = new ProjectInstance(root, null, "4.0", ProjectCollection.GlobalProjectCollection); proj.Build(); // make sure the property value expansion is done successfully. Assert.IsTrue(!string.IsNullOrEmpty(proj.GetPropertyValue("_ExplicitMSCorlibPath")), "premise: propertyValue by ToolLocationHelper func call"); var items = proj.GetItems("_ExplicitReference"); // make sure items are stored after build. Assert.IsTrue(items.Any(), "items.Any"); Assert.IsTrue(!string.IsNullOrEmpty(items.First().EvaluatedInclude), "item.EvaluatedInclude"); }
public void BuildNullLoggerInArray() { Assert.Throws <ArgumentNullException>(() => { ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create()); instance.Build("t", new ILogger[] { null }); } ); }
public string GetProjectPropertyByName(IProject project, string name) { Dictionary <string, string> cachedProperties; if (this.myData.TryGetValue(project, out cachedProperties)) { string value; if (cachedProperties.TryGetValue(name, out value)) { return(value); } } else { cachedProperties = new Dictionary <string, string>(); this.myData.Add(project, cachedProperties); } try { const string resolveassemblyreference = "ResolveAssemblyReferences"; IProjectFile projectFile = project.ProjectFile; if (projectFile == null) { return(null); } List <Project> loadedProjects = ProjectCollection.GlobalProjectCollection.GetLoadedProjects( projectFile.Location.FullPath).ToList(); if (loadedProjects.Count != 1) { return(null); } Project loadedProject = loadedProjects[0]; ProjectInstance projectInstance = BuildManager.DefaultBuildManager.GetProjectInstanceForBuild(loadedProject); if (projectInstance.Build(resolveassemblyreference, JetBrains.Util.EmptyList <ILogger> .InstanceList)) { ICollection <ProjectPropertyInstance> allProperties = projectInstance.Properties; foreach (ProjectPropertyInstance property in allProperties) { cachedProperties.Add(property.Name, property.EvaluatedValue); } ProjectPropertyInstance projectPropertyInstance = projectInstance.GetProperty(name); if (projectPropertyInstance != null) { return(projectPropertyInstance.EvaluatedValue); } } } catch (Exception e) { Logger.LogExceptionSilently(e); } return(""); }
public void BuildNullRemoteLoggerInArray() { Assert.Throws <ArgumentNullException>(() => { ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create()); instance.Build("t", null, new ForwardingLoggerRecord[] { null }); } ); }
public void BuildNullTargetInArray() { Assert.Throws <ArgumentNullException>(() => { ProjectInstance instance = new ProjectInstance(ProjectRootElement.Create()); instance.Build(new string[] { null }, null); } ); }
public void TestResolveEnvironment() { var proj1 = new ProjectInstance(TestData.GetPath(@"TestData\Targets\Environments1.pyproj")); Assert.IsTrue(proj1.Build("TestResolveEnvironment", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) })); var proj2 = new ProjectInstance(TestData.GetPath(@"TestData\Targets\Environments2.pyproj")); Assert.IsTrue(proj2.Build("TestResolveEnvironment", new ILogger[] { new ConsoleLogger(LoggerVerbosity.Detailed) })); }
private Microsoft.Expression.Project.Build.BuildResult Build(ProjectInstance projectInstance, IEnumerable <ILogger> loggers, params string[] targetNames) { IDictionary <string, TargetResult> strs = new Dictionary <string, TargetResult>(); if (projectInstance.Build(targetNames, loggers, null, out strs)) { return(Microsoft.Expression.Project.Build.BuildResult.Succeeded); } return(Microsoft.Expression.Project.Build.BuildResult.Failed); }
public BuildEngineResult BuildProjectFilesInParallel ( string[] projectFileNames, string[] targetNames, IDictionary[] globalProperties, IList <string>[] undefineProperties, string[] toolsVersion, bool returnTargetOutputs ) { List <IDictionary <string, ITaskItem[]> > targetOutputsPerProject = null; ILogger[] loggers = new ILogger[2] { _mockLogger, new ConsoleLogger() }; bool allSucceeded = true; if (returnTargetOutputs) { targetOutputsPerProject = new List <IDictionary <string, ITaskItem[]> >(); } for (int i = 0; i < projectFileNames.Length; i++) { Dictionary <string, string> finalGlobalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); if (globalProperties[i] != null) { foreach (DictionaryEntry newGlobalProperty in globalProperties[i]) { finalGlobalProperties[(string)newGlobalProperty.Key] = (string)newGlobalProperty.Value; } } ProjectInstance instance = _projectCollection.LoadProject((string)projectFileNames[i], finalGlobalProperties, null).CreateProjectInstance(); IDictionary <string, TargetResult> targetOutputs; bool success = instance.Build(targetNames, loggers, out targetOutputs); if (targetOutputsPerProject != null) { targetOutputsPerProject.Add(new Dictionary <string, ITaskItem[]>(StringComparer.OrdinalIgnoreCase)); foreach (KeyValuePair <string, TargetResult> resultEntry in targetOutputs) { targetOutputsPerProject[i][resultEntry.Key] = resultEntry.Value.Items; } } allSucceeded = allSucceeded && success; } return(new BuildEngineResult(allSucceeded, targetOutputsPerProject)); }
public void BuildNullTargetNameIsDefaultTarget() { ProjectRootElement xml = ProjectRootElement.Create(); xml.AddTarget("t").AddTask("Message").SetParameter("Text", "[OK]"); ProjectInstance instance = new ProjectInstance(xml); MockLogger logger = new MockLogger(); string target = null; instance.Build(target, new ILogger[] { logger }); logger.AssertLogContains("[OK]"); }
public void BuildDoesNotIncreaseCollectionContent() { string empty_project_xml = "<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003' />"; var xml = XmlReader.Create(new StringReader(empty_project_xml)); var root = ProjectRootElement.Create(xml); var coll = new ProjectCollection(); var inst = new ProjectInstance(root, null, null, coll); root.FullPath = "ProjectCollectionTest.BuildDoesNotIncreaseCollectionContent.proj"; Assert.AreEqual(0, coll.Count, "#1"); inst.Build(); Assert.AreEqual(0, coll.Count, "#2"); }
private IEnumerable <string> ResolveAssemblyReferences(Project project) { // Use MSBuild to figure out the full path of the referenced assemblies ProjectInstance projectInstance = project.CreateProjectInstance(); projectInstance.SetProperty("BuildingProject", "false"); project.SetProperty("DesignTimeBuild", "true"); projectInstance.Build("ResolveAssemblyReferences", null); ICollection <ProjectItemInstance> items = projectInstance.GetItems("_ResolveAssemblyReferenceResolvedFiles"); string baseDirectory = Path.GetDirectoryName(FileName); return(items.Select(i => Path.Combine(baseDirectory, i.GetMetadataValue("Identity")))); }
public void CaptureTargetOutputs() { Project project = ObjectModelHelpers.CreateInMemoryProject(@" <Project DefaultTargets=`build` ToolsVersion=`msbuilddefaulttoolsversion` xmlns=`msbuildnamespace`> <Target Name=`build` > <CallTarget Targets=` a; b; c ` > <Output ItemName=`myfancytargetoutputs` TaskParameter=`TargetOutputs`/> </CallTarget> </Target> <!-- include some nice characters that need escaping --> <Target Name=`a` Outputs=`a.t!@#$%^xt`> <Message Text=`Inside A` /> </Target> <Target Name=`b` Outputs=`b.txt`> <Message Text=`Inside B` /> </Target> <Target Name=`c` Outputs=`c.txt`> <Message Text=`Inside C` /> </Target> </Project> "); ProjectInstance instance = project.CreateProjectInstance(); bool success = instance.Build(); Assert.True(success); // "Build failed. See test output (Attachments in Azure Pipelines) for details" IEnumerable <ProjectItemInstance> targetOutputs = instance.GetItems("myfancytargetoutputs"); // Convert to a list of TaskItems for easier verification. List <ITaskItem> targetOutputsTaskItems = new List <ITaskItem>(); foreach (ProjectItemInstance item in targetOutputs) { targetOutputsTaskItems.Add(new TaskItem(item.EvaluatedInclude)); } // Order independent verification of the right set of items. ObjectModelHelpers.AssertItemsMatch(@" c.txt b.txt a.t!@#$%^xt ", targetOutputsTaskItems.ToArray(), false /* ignore the order */); }
private IEnumerable <string> ResolveAssemblyReferences(Project project) { // Use MSBuild to figure out the full path of the referenced assemblies ProjectInstance projectInstance = project.CreateProjectInstance(); projectInstance.SetProperty("BuildingProject", "false"); project.SetProperty("DesignTimeBuild", "true"); projectInstance.Build("ResolveAssemblyReferences", new[] { new ConsoleLogger(LoggerVerbosity.Minimal) }); ICollection <ProjectItemInstance> items = projectInstance.GetItems("_ResolveAssemblyReferenceResolvedFiles"); string baseDirectory = Path.GetDirectoryName(_projectLocation); // ReSharper disable once AssignNullToNotNullAttribute return(items.Select(i => Path.Combine(baseDirectory, i.GetMetadataValue("Identity")))); }
public void FunctionCall() { string project_xml = @"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <Target Name='Foo'> <Warning Text=""$([Microsoft.Build.Utilities.ToolLocationHelper]::GetPathToStandardLibraries ('$(TargetFrameworkIdentifier)', '$(TargetFrameworkVersion)', '$(TargetFrameworkProfile)'))\mscorlib.dll'"" /> </Target> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); var p = new ProjectInstance(root, null, "4.0", ProjectCollection.GlobalProjectCollection); var sw = new StringWriter(); var result = p.Build(new ILogger [] { new ConsoleLogger(LoggerVerbosity.Minimal, sw.WriteLine, null, null) }); Assert.IsTrue(result, "#1: " + sw); }
public bool BuildProject(ProjectInstance instance, string [] targetNames, IDictionary globalProperties) { if (globalProperties != null) { foreach (DictionaryEntry de in globalProperties) { //Note: trying to set this on the project causes the project to be added to the PC // again, which of course, fails instance.SetProperty((string)de.Key, (string)de.Value); } } //FIXME: assumption that we are still using the same PC! return(instance.Build(targetNames, ProjectCollection.Loggers)); }
public void MissingTypeForUsingTaskStillWorks2() { string thisAssembly = new Uri(GetType().Assembly.CodeBase).LocalPath; string project_xml = @"<Project DefaultTargets='X' xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <UsingTask AssemblyFile='nonexistent.dll' TaskName='NonExistent' /> <Target Name='X' /> </Project>"; var xml = XmlReader.Create(new StringReader(project_xml)); var root = ProjectRootElement.Create(xml); root.FullPath = "ProjectInstanceTest.MissingTypeForUsingTaskStillWorks2.proj"; var proj = new ProjectInstance(root); Assert.IsTrue(proj.Build(), "#1"); }
/// <summary> /// Returns all package references after invoking the target CollectPackageReferences. /// </summary> /// <param name="projectPath"> Path to the project for which the package references have to be obtained.</param> /// <param name="framework">Framework to get reference(s) for</param> /// <returns>List of Items containing the package reference for the package. /// If the libraryDependency is null then it returns all package references</returns> private static IEnumerable <InstalledPackageReference> GetPackageReferencesFromTargets(string projectPath, string framework) { var globalProperties = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase) { { "TargetFramework", framework } }; var newProject = new ProjectInstance(projectPath, globalProperties, null); newProject.Build(new[] { CollectPackageReferences }, new List <Microsoft.Build.Framework.ILogger> { }, out var targetOutputs); return(targetOutputs.First(e => e.Key.Equals(CollectPackageReferences)).Value.Items.Select(p => new InstalledPackageReference(p.ItemSpec) { OriginalRequestedVersion = p.GetMetadata("version"), })); }