How to install msbuild




















For more information about items, see Items. Tasks are units of executable code that MSBuild projects use to perform build operations. For example, a task might compile input files or run an external tool.

Tasks can be reused, and they can be shared by different developers in different projects. The execution logic of a task is written in managed code and mapped to MSBuild by using the UsingTask element. You can write your own task by authoring a managed type that implements the ITask interface.

For more information about how to write tasks, see Task writing. MSBuild includes common tasks that you can modify to suit your requirements. Examples are Copy , which copies files, MakeDir , which creates directories, and Csc , which compiles Visual C source code files. For a list of available tasks together with usage information, see Task reference. A task is executed in an MSBuild project file by creating an element that has the name of the task as a child of a Target element.

Tasks typically accept parameters, which are passed as attributes of the element. Both MSBuild properties and items can be used as parameters. For example, the following code calls the MakeDir task and passes it the value of the BuildDir property that was declared in the earlier example. For more information about tasks, see Tasks. Targets group tasks together in a particular order and expose sections of the project file as entry points into the build process.

Targets are often grouped into logical sections to increase readability and to allow for expansion. Breaking the build steps into targets lets you call one piece of the build process from other targets without copying that section of code into every target. For example, if several entry points into the build process require references to be built, you can create a target that builds references and then run that target from every entry point where it's required.

Targets are declared in the project file by using the Target element. For example, the following code creates a target named Compile , which then calls the Csc task that has the item list that was declared in the earlier example.

In more advanced scenarios, targets can be used to describe relationships among one another and perform dependency analysis so that whole sections of the build process can be skipped if that target is up-to-date. For more information about targets, see Targets.

You can log build errors, warnings, and messages to the console or another output device. Visual Studio uses the MSBuild project file format to store build information about managed projects. Project settings that are added or changed by using the Visual Studio interface are reflected in the. Visual Studio uses a hosted instance of MSBuild to build managed projects. This means that a managed project can be built in Visual Studio or at a command prompt even if Visual Studio isn't installed , and the results will be identical.

By using Visual Studio, you can compile an application to run on any one of several versions of. NET Framework. For example, you can compile an application to run on. NET Framework 2. NET Framework 4. The ability to compile to more than one framework is named multitargeting. You can develop applications that target earlier versions of. NET Framework, for example, versions 3.

Multitargeting guarantees that an application uses only the functionality that's available in the target framework and platform. For more information, see Multitargeting.

MSBuild reference Links to topics that contain reference information. Glossary Defines common MSBuild terms. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info.

Contents Exit focus mode. Is this page helpful? Please rate your experience Yes No. Any additional feedback? Note You can use Azure Pipelines to automatically compile, test, and deploy your application. Important Before you download a project, determine the trustworthiness of the code.

Submit and view feedback for This product This page. View all page feedback. In this article. Walkthrough: Creating an MSBuild project file from scratch. Walkthrough: Using MSBuild. Introduces properties and property collections. Explains how to group tasks together in a particular order and enable sections of the build process to be called on the command line. A target is a named sequence of tasks.

For more information, see the Targets topic. The default target is not defined in the project file. Instead, it is specified in imported projects. The Import element specifies imported projects. For example, in a C project, the default target is imported from the file Microsoft. In SDK-style projects, you don't see this import element, since the SDK attribute causes this file to be imported implicitly.

MSBuild keeps track of the targets of a build, and guarantees that each target is built no more than once. Add these lines to the project file, just after the Import statement or the opening Project element. This creates a target named HelloWorld.

Notice that you have IntelliSense support while editing the project file. The Message task is one of the many tasks that ships with MSBuild.

For a complete list of available tasks and usage information, see Task reference. The Message task takes the string value of the Text attribute as input and displays it on the output device or writes it to one or more logs, if applicable. The HelloWorld target executes the Message task twice: first to display "Hello", and then to display "World".

If you try to build this project from Visual Studio, it won't build the target you defined. That's because Visual Studio chooses the default target, which is still the one in the imported. Use the -target or -t command-line switch to select the target. Windows 10 In the search box on the taskbar, start typing the name of the tool, such as dev or developer command prompt. This brings up a list of installed apps that match your search pattern.

If you need to find it manually, the file is LaunchDevCmd. Run msbuild with the command switch -t:HelloWorld. This selects and builds the HelloWorld target:.

Examine the output in the Command window. You should see the two lines "Hello" and "World":. If instead you see The target "HelloWorld" does not exist in the project then you probably forgot to save the project file in the code editor. Save the file and try again. By alternating between the code editor and the command window, you can change the project file and quickly see the results. Build properties are name-value pairs that guide the build.

Several build properties are already defined at the top of the project file:. All properties are child elements of PropertyGroup elements. The name of the property is the name of the child element, and the value of the property is the text element of the child element. For example,. To get the value of a property, use the following syntax, where PropertyName is the name of the property:. Many properties like Configuration are defined conditionally, that is, the Condition attribute appears in the property element.

Conditional properties are defined or redefined only if the condition evaluates to "true". Note that undefined properties are given the default value of an empty string. Almost all MSBuild elements can have a Condition attribute. For more discussion about using the Condition attribute, see Conditions. MSBuild reserves some property names to store information about the project file and the MSBuild binaries.

MSBuildToolsPath is an example of a reserved property. For more information, see How to: Reference the name or location of the project file and MSBuild reserved and well-known properties. You can reference environment variables in project files the same way as build properties. If the project contains a property definition that has the same name as an environment variable, the property in the project overrides the value of the environment variable.

For more information, see How to: Use environment variables in a build. Properties may be defined on the command line using the -property or -p command line switch. Property values received from the command line override property values set in the project file and environment variables. Certain characters have special meaning in MSBuild project files. Change the Message task to show the value of the Configuration property with special characters to make it more readable.

For more information, see MSBuild special characters. An item is a piece of information, typically a file name, that is used as an input to the build system. For example, a collection of items representing source files might be passed to a task named Compile to compile them into an assembly.

All items are child elements of ItemGroup elements. The item name is the name of the child element, and the item value is the value of the Include attribute of the child element. The values of items with the same name are collected into item types of that name. The item type Compile has two values: Program. The following code creates the same item type by declaring both files in one Include attribute, separated by a semicolon.

For more information, see Items. File paths are relative to the folder containing the MSBuild project file, even if the project file is an imported project file. There are a few exceptions to this, such as when using Import and UsingTask elements. To get the values of an item type, use the following syntax, where ItemType is the name of the item type:. To change the separator of an item type, use the following syntax, where ItemType is the item type and Separator is a string of one or more separating characters:.

For more examples, see How to: Select the files to build. This is equivalent to the following line:. For more examples, see How to: Exclude files from the build. The Exclude attribute only affects the items added by the Include attribute in the item element that contains them both. Items may contain metadata in addition to the information gathered from the Include and Exclude attributes.



0コメント

  • 1000 / 1000