# MSBuild
> The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software. Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio.
> ([.NET Documentation](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild?view=vs-2019))
This page contains information about MSBuild. It concerns *dev-time*, not *run-time*. See [[Dotnet Runtime|.NET Runtime]] for *run-time* related stuff.
## Properties
See [MSBuild Properties Reference for .NET SDK projects](https://docs.microsoft.com/en-us/dotnet/core/project-sdk/msbuild-props) for more.
To set properties (and targets) to multiple projects in a solution see [[Directory.Build.props and Directory.Build.targets files]].
- `AppendTargetFrameworkToOutputPath` set to false will prevent MSBuild from appending target framework to output path
- `OutputType`, which if set to `WinExe` prevents the display of the console window. See [[Starting ASP.NET Core Application Without the Console Window]]
- `Nullable`, if set to `enable` will enable [[Nullable Reference Types in CSharp|Nullable Reference Types in C#]]
- `SelfContained`, if set to `true`, will direct the compiler to make a self-contained assembly (as opposed to shared-framework). For more details see [[Shared vs. Self-Contained Dotnet Deployments|Shared vs. Self-Contained .NET Deployments]]
- `RuntimeIdentifier` sets the target runtime and makes the deployment runtime specific. Note that this sets `SelfContained` to true, unless it is explicitly set to false. For a list of possible identifiers see [[Dotnet Runtime Identifiers]].
- For single file executable properties see [[Dotnet Single File Executable#MSBuild Properties|Single File Executable MSBuild Properties]]
- For properties that control trimming see [[Trimming Compiler Output in Dotnet|Trimming Compiler Output in .NET]].
- `LangVersion` can be used to restrict the language version used in the current project. See [[Restricting CSharp Version in a Dotnet Project|Restricting C# Version in a .NET Project]].
- `PublishReadyToRun` enables the ready-to-run mode. See [[ReadyToRun Dotnet Deployment|ReadyToRun .NET Deployment]].
- `AutoGenerateBindingRedirects` controls automatic generation of [[Binding Redirects]] for .NET Framework projects (not applicable to .NET 5 / Core).
- For assembly info attributes see [[AssemblyInfo in csproj and fsproj]]. [[GitInfo]] can be used to append additional metadata.
## Targets
Targets documentation can be found [here](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-targets?view=vs-2019).
To set targets (and properties) to multiple projects in a solution see [[Directory.Build.props and Directory.Build.targets files]].
## Running Tasks from MSBuild
- To run tasks from MSBuild see [this](https://learn.microsoft.com/en-us/visualstudio/msbuild/task-writing?view=vs-2019), [this](https://learn.microsoft.com/en-us/visualstudio/msbuild/usingtask-element-msbuild?view=vs-2019), [this](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-inline-tasks?view=vs-2019), and [this](https://learn.microsoft.com/en-us/dotnet/api/microsoft.build.utilities.task?view=msbuild-16-netcore)
## Including All Items in a Folder and Copying Them to Output
```xml
<ItemGroup>
<None Update="TestData\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="ReferenceImplementation\AML\**">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Link>AML\%(RecursiveDir)%(Filename)%(Extension)</Link>
</None></ItemGroup>
</ItemGroup/>
```
Second example will output files to a specific directory in the output. For more see [Allow CopyToOutputDirectory to have a custom destination path](https://github.com/dotnet/msbuild/issues/2795).
## Troubleshooting
- [[Multiple Entries With the Same BundleRelativePath]]