MSBuild

Inline task

<UsingTask TaskName="MethodDemo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
	<Task>
		<Reference Include="System.Web.Extensions" />
		<Using Namespace="System" />
		<Code Type="Method" Language="C#">
			<![CDATA[
				public override bool Execute()
				{
					if(Random.NextDouble() > 0.5)
					{
						Log.LogError("Fail because random value said so");
						//return false;
					}

					//return true;
					return !Log.HasLoggedErrors;
				}
			]]>
		</Code>
	</Task>
</UsingTask>

<UsingTask TaskName="ClassDemo" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
	<ParameterGroup>
		<InputParam0 ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
		<OutputParam0 ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
	</ParameterGroup>
	<Task>
		<Using Namespace="System" />
		<Code Type="Class" Language="C#">
			<![CDATA[
				using System;
				using System.IO;
				using System.Security;
				using System.Collections;
				using Microsoft.Build.Framework;
				using Microsoft.Build.Utilities;

				namespace Microsoft.Build.Tasks
				{
					public class ClassDemo : Task
					{
						[Required]
						public ITaskItem[] InputParam0 { get; set; }

						[Output]
						public ITaskItem[] OutputParam0 { get; set; }

						public override bool Execute()
						{
							ArrayList items = new ArrayList();
							foreach (var item in InputParam0)
							{
								Log.LogMessage(MessageImportance.High, item.ItemSpec);
							}

							OutputParam0 = new TaskItem[]{new TaskItem("itemspec1")};

							return !Log.HasLoggedErrors;
						}
					}
				}
			]]>
		</Code>
	</Task>
</UsingTask>

Exec task

How to encode ; in variable given to EnvironmentVariables (which use ; as variables separator). TL;DR: use %3B:

Other:

Last updated