# MSBuild reference for .NET SDK projects

This page is a reference for the MSBuild properties and items that you can use to configure .NET projects.

Note

This page is a work in progress and does not list all of the useful MSBuild properties for the .NET SDK. For a list of common MSBuild properties, see Common MSBuild properties.

## Framework properties

The following MSBuild properties are documented in this section:

### TargetFramework

The TargetFramework property specifies the target framework version for the app. For a list of valid target framework monikers, see Target frameworks in SDK-style projects.

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

### TargetFrameworks

Use the TargetFrameworks property when you want your app to target multiple platforms. For a list of valid target framework monikers, see Target frameworks in SDK-style projects.

Note

This property is ignored if TargetFramework (singular) is specified.

<PropertyGroup>
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks>
</PropertyGroup>

### NetStandardImplicitPackageVersion

Note

This property only applies to projects using netstandard1.x. It doesn't apply to projects that use netstandard2.x.

Use the NetStandardImplicitPackageVersion property when you want to specify a framework version that's lower than the metapackage version. The project file in the following example targets netstandard1.3 but uses the 1.6.0 version of NETStandard.Library.

<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
</PropertyGroup>

## Assembly attribute properties

### GenerateAssemblyInfo

The GenerateAssemblyInfo property controls AssemblyInfo attribute generation for the project. The default value is true. Use false to disable generation of the file:

<PropertyGroup>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
</PropertyGroup>

The GeneratedAssemblyInfoFile setting controls the name of the generated file.

When the GenerateAssemblyInfo value is true, package-related project properties are transformed into assembly attributes. The following table lists the project properties that generate the attributes. It also lists the properties that you can use to disable that generation on a per-attribute basis, for example:

<PropertyGroup>
<GenerateNeutralResourcesLanguageAttribute>false</GenerateNeutralResourcesLanguageAttribute>
</PropertyGroup>
MSBuild property Assembly attribute Property to disable attribute generation
Company AssemblyCompanyAttribute GenerateAssemblyCompanyAttribute
Configuration AssemblyConfigurationAttribute GenerateAssemblyConfigurationAttribute
Description AssemblyDescriptionAttribute GenerateAssemblyDescriptionAttribute
FileVersion AssemblyFileVersionAttribute GenerateAssemblyFileVersionAttribute
InformationalVersion AssemblyInformationalVersionAttribute GenerateAssemblyInformationalVersionAttribute
Product AssemblyProductAttribute GenerateAssemblyProductAttribute
AssemblyTitle AssemblyTitleAttribute GenerateAssemblyTitleAttribute
AssemblyVersion AssemblyVersionAttribute GenerateAssemblyVersionAttribute
NeutralLanguage NeutralResourcesLanguageAttribute GenerateNeutralResourcesLanguageAttribute

• AssemblyVersion and FileVersion default to the value of $(Version) without the suffix. For example, if$(Version) is 1.2.3-beta.4, then the value would be 1.2.3.
• InformationalVersion defaults to the value of $(Version). • If the$(SourceRevisionId) property is present, it's appended to InformationalVersion. You can disable this behavior using IncludeSourceRevisionInInformationalVersion.
• Configuration, which defaults to Debug, is shared with all MSBuild targets. You can set it via the --configuration option of dotnet commands, for example, dotnet pack.
• Some of the properties are used when creating a NuGet package. For more information, see Package properties.

#### Migrating from .NET Framework

.NET Framework project templates create a code file with these assembly info attributes set. The file is typically located at .\Properties\AssemblyInfo.cs or .\Properties\AssemblyInfo.vb. SDK-style projects generate this file for you based on the project settings. You can't have both. When porting your code to .NET 5 (or .NET Core 3.1) or later, do one of the following:

• Disable the generation of the temporary code file that contains the assembly info attributes by setting GenerateAssemblyInfo to false in your project file. This enables you to keep your AssemblyInfo file.
• Migrate the settings in the AssemblyInfo file to the project file, and then delete the AssemblyInfo file.

</PropertyGroup>

### DefaultItemExcludesInProjectFolder

Use the DefaultItemExcludesInProjectFolder property to define glob patterns for files and folders in the project folder that should be excluded from the include, exclude, and remove globs. By default, folders that start with a period (.), such as .git and .vs, are excluded from the glob patterns.

This property is very similar to the DefaultItemExcludes property, except that it only considers files and folders in the project folder. When a glob pattern would unintentionally match items outside the project folder with a relative path, use the DefaultItemExcludesInProjectFolder property instead of the DefaultItemExcludes property.

<PropertyGroup>

### PackageReference

The PackageReference item defines a reference to a NuGet package.

The Include attribute specifies the package ID. The Version attribute specifies the version or version range. For information about how to specify a minimum version, maximum version, range, or exact match, see Version ranges.

The project file snippet in the following example references the System.Runtime package.

<ItemGroup>
<PackageReference Include="System.Runtime" Version="4.3.0" />
</ItemGroup>

You can also control dependency assets using metadata such as PrivateAssets.

<ItemGroup>
<PackageReference Include="Contoso.Utility.UsefulStuff" Version="3.6.0">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

### TrimmerRootAssembly

The TrimmerRootAssembly item lets you exclude an assembly from trimming. Trimming is the process of removing unused parts of the runtime from a packaged application. In some cases, trimming might incorrectly remove required references.

The following XML excludes the System.Security assembly from trimming.

<ItemGroup>
<TrimmerRootAssembly Include="System.Security" />
</ItemGroup>

### Using

The Using item lets you globally include a namespace across your C# project, such that you don't have to add a using directive for the namespace at the top of your source files. This item is similar to the Import item that can be used for the same purpose in Visual Basic projects. This property is available starting in .NET 6.

<ItemGroup>
<Using Include="My.Awesome.Namespace" />
</ItemGroup>

You can also use the Using item to define global using <alias> and using static <type> directives.

<ItemGroup>
<Using Include="My.Awesome.Namespace" Alias="Awesome" />
</ItemGroup>

For example:

• <Using Include="Microsoft.AspNetCore.Http.Results" Alias="Results" /> emits global using Results = global::Microsoft.AspNetCore.Http.Results;
• <Using Include="Microsoft.AspNetCore.Http.Results" Static="True" /> emits global using static global::Microsoft.AspNetCore.Http.Results;

For more information, see aliased using directives and using static <type> directives.

In addition to the standard MSBuild item attributes, the following item metadata tags are made available by the .NET SDK:

### CopyToPublishDirectory

The CopyToPublishDirectory metadata on an MSBuild item controls when the item is copied to the publish directory. Allowable values are PreserveNewest, which only copies the item if it has changed, Always, which always copies the item, and Never, which never copies the item. From a performance standpoint, PreserveNewest is preferable because it enables an incremental build.

<ItemGroup>
</ItemGroup>