{
	"id": "8b1ac3e3-1629-42d9-9fdf-db4346e2b615",
	"created_at": "2026-04-06T00:09:33.761173Z",
	"updated_at": "2026-04-10T03:20:04.27091Z",
	"deleted_at": null,
	"sha1_hash": "931afbe919c2f850cc660d040abb41dbf7a6ad8a",
	"title": "Create MSBuild inline tasks - MSBuild",
	"llm_title": "",
	"authors": "",
	"file_creation_date": "0001-01-01T00:00:00Z",
	"file_modification_date": "0001-01-01T00:00:00Z",
	"file_size": 106025,
	"plain_text": "Create MSBuild inline tasks - MSBuild\nBy ghogen\nArchived: 2026-04-05 20:25:28 UTC\nMSBuild tasks are typically created by compiling a class that implements the ITask interface. For more\ninformation, see Tasks.\nWhen you want to avoid the overhead of creating a compiled task, you can create a task inline in the project file or\nin an imported file. You don't have to create a separate assembly to host the task. Using an inline task makes it\neasier to keep track of source code and easier to deploy the task. The source code is integrated into the MSBuild\nproject file or imported file, typically a .targets file.\nYou create an inline task by using a code task factory. For current development, be sure to use\nRoslynCodeTaskFactory, not CodeTaskFactory . CodeTaskFactory only supports C# versions up to 4.0.\nInline tasks are intended as a convenience for small tasks that don't require complicated dependencies. Debugging\nsupport for inline tasks is limited. It's recommended to create a compiled task instead of inline task when you want\nto write more complex code, reference a NuGet package, run external tools, or perform operations that could\nproduce error conditions. Also, inline tasks are compiled every time you build, so there can be a noticeable impact\non build performance.\nThe structure of an inline task\nAn inline task is contained by a UsingTask element. The inline task and the UsingTask element that contains it\nare typically included in a .targets file and imported into other project files as required. Here's a basic inline\ntask that does nothing, but illustrates the syntax: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nPage 1 of 6\n\nThe UsingTask element in the example has three attributes that describe the task and the inline task factory that\r\ncompiles it.\r\nThe TaskName attribute names the task, in this case, DoNothing .\r\nThe TaskFactory attribute names the class that implements the inline task factory.\r\nThe AssemblyFile attribute gives the location of the inline task factory. Alternatively, you can use the\r\nAssemblyName attribute to specify the fully qualified name of the inline task factory class, which is\r\ntypically located in $(MSBuildToolsPath)\\Microsoft.Build.Tasks.Core.dll .\r\nThe remaining elements of the DoNothing task are empty and are provided to illustrate the order and structure of\r\nan inline task. A complete example is presented later in this article.\r\nThe ParameterGroup element is optional. When specified, it declares the parameters for the task. For\r\nmore information about input and output parameters, see Input and output parameters later in this article.\r\nThe Task element describes and contains the task source code.\r\nThe Reference element specifies references to the .NET assemblies that you are using in your code.\r\nUsing this element is equivalent to adding a reference to a project in Visual Studio. The Include attribute\r\nspecifies the path of the referenced assembly. Assemblies in mscorlib, .NET Standard,\r\nMicrosoft.Build.Framework, and Microsoft.Build.Utilities.Core, as well as some assemblies that are\r\ntransitively referenced as dependencies, are available without a Reference .\r\nThe Using element lists the namespaces that you want to access. This element is equivalent to the using\r\ndirective in C#. The Namespace attribute specifies the namespace to include. It doesn't work to put a\r\nusing directive in the inline code, because that code is put into a method body, where using directives\r\naren't allowed.\r\nReference and Using elements are language-agnostic. Inline tasks can be written in Visual Basic or C#.\r\nNote\r\nElements contained by the Task element are specific to the task factory, in this case, the code task factory.\r\nCode element\r\nThe last child element to appear within the Task element is the Code element. The Code element contains or\r\nlocates the code that you want to be compiled into a task. What you put in the Code element depends on how you\r\nwant to write the task.\r\nThe Language attribute specifies the language in which your code is written. Acceptable values are cs for C#,\r\nvb for Visual Basic.\r\nThe Type attribute specifies the type of code that is found in the Code element.\r\nhttps://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\r\nPage 2 of 6\n\nIf the value of Type is Class , then the Code element contains code for a class that derives from the\nITask interface.\nIf the value of Type is Method , then the code defines an override of the Execute method of the ITask\ninterface.\nIf the value of Type is Fragment , then the code defines the contents of the Execute method, but not the\nsignature or the return statement.\nThe code itself typically appears between a \u003c![CDATA[ marker and a ]]\u003e marker. Because the code is in a\nCDATA section, you don't have to worry about escaping reserved characters, for example, \"\u003c\" or \"\u003e\".\nAlternatively, you can use the Source attribute of the Code element to specify the location of a file that\ncontains the code for your task. The code in the source file must be of the type that is specified by the Type\nattribute. If the Source attribute is present, the default value of Type is Class . If Source isn't present, the\ndefault value is Fragment .\nNote\nWhen defining the task class in the source file, the class name must agree with the TaskName attribute of the\ncorresponding UsingTask element.\nHelloWorld\nHere's an example of a simple inline task. The HelloWorld task displays \"Hello, world!\" on the default error\nlogging device, which is typically the system console or the Visual Studio Output window.\n`\n\u003c![CDATA[\n// Display \"Hello, world!\"\nLog.LogError(\"Hello, world!\");\n]]\u003e\n ` https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nPage 3 of 6\n\nYou could save the HelloWorld task in a file that is named HelloWorld.targets, and then invoke it from a project as\nfollows.\nInput and output parameters\nInline task parameters are child elements of a ParameterGroup element. Every parameter takes the name of the\nelement that defines it. The following code defines the parameter Text .\nParameters may have one or more of these attributes:\nRequired is an optional attribute that is false by default. If true , then the parameter is required and\nmust be given a value before calling the task.\nParameterType is an optional attribute that is System.String by default. It may be set to any fully\nqualified type that is either an item or a value that can be converted to and from a string by using\nChangeType. (In other words, any type that can be passed to and from an external task.)\nOutput is an optional attribute that is false by default. If true , then the parameter must be given a\nvalue before returning from the Execute method.\nFor example,\ndefines these three parameters:\nExpression is a required input parameter of type System.String.\nFiles is a required item list input parameter.\nTally is an output parameter of type System.Int32.\nhttps://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nPage 4 of 6\n\nIf the Code element has the Type attribute of Fragment or Method , then properties are automatically created\nfor every parameter. Otherwise, properties must be explicitly declared in the task source code, and must exactly\nmatch their parameter definitions.\nDebug an inline task\nMSBuild generates a source file the inline task and writes the output to text file with a GUID filename in the\ntemporary files folder, AppData\\Local\\Temp\\MSBuildTemp. The output is normally deleted, but to preserve this\noutput file, you can set the environment variable MSBUILDLOGCODETASKFACTORYOUTPUT to 1.\nExample 1\nThe following inline task replaces every occurrence of a token in the given file with the given value.\n`\u003c![CDATA[\nstring content = File.ReadAllText(Path);\ncontent = content.Replace(Token, Replacement);\nFile.WriteAllText(Path, content);\n]]\u003e` Example 2\nThe following inline task generates serialized output. This example shows the use of an output parameter and a\nreference.\nhttps://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nPage 5 of 6\n\n$(MSBuildToolsPath)\\Micros   `\n \u003c![CDATA[\n Output = JsonSerializer.Serialize(new { Message = Input });\n ]]\u003e\n ` Related content\nTasks\nWalkthrough: Create an inline task\nSource: https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nhttps://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element\nPage 6 of 6",
	"extraction_quality": 1,
	"language": "EN",
	"sources": [
		"MITRE"
	],
	"references": [
		"https://docs.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019#code-element"
	],
	"report_names": [
		"msbuild-inline-tasks?view=vs-2019#code-element"
	],
	"threat_actors": [],
	"ts_created_at": 1775434173,
	"ts_updated_at": 1775791204,
	"ts_creation_date": 0,
	"ts_modification_date": 0,
	"files": {
		"pdf": "https://archive.orkl.eu/931afbe919c2f850cc660d040abb41dbf7a6ad8a.pdf",
		"text": "https://archive.orkl.eu/931afbe919c2f850cc660d040abb41dbf7a6ad8a.txt",
		"img": "https://archive.orkl.eu/931afbe919c2f850cc660d040abb41dbf7a6ad8a.jpg"
	}
}