This element allows you to specify a set of target frameworks that will be used as fallback when restoring packages. In project.json it was represented as an imports
statement inside the frameworks
or tools
node. The semantics of <PackageTargetFallback>
are the same as imports
in project.json.
This element is an MSBuild property. That means that it needs to be placed inside <PropertyGroup>
element, either a new one or an existing one in your project file:
<PropertyGroup>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
The below bigger sample is a sample console application that uses the fallback element. The project in question is a default template that dotnet new
creates in Preview 3 version of the CLI. You can see how it is placed within the csproj file. Observe that I've placed the element as part of an existing <PropertyGroup>
that already exists in the template.
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App">
<Version>1.0.1</Version>
</PackageReference>
<PackageReference Include="Microsoft.NET.Sdk">
<Version>1.0.0-alpha-20161104-2</Version>
<PrivateAssets>All</PrivateAssets>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
If the syntax or notions of "property groups" and "item groups" are unfamiliar to you, here are some links with great explanations: