Targeting different .NET Core versions in the .csproj files of your projects

For every project that Visual Studio 2019 generates, it creates a corresponding .csproj file, which includes several project-wide settings such as the referenced assemblies, the .NET Framework target versions, the included files, and folders, as well as multiple others.

For example, when opening the ASP.NET Core 3 project you created previously, you can see the following structure:


<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

</Project>

You can see the TargetFramework setting, which allows you to define what .NET Framework versions should be included and used for building and executing the source code.

In our example, it has been set to netcoreapp3.0, the specific value for using the .NET Core 3 Framework:

    <TargetFramework>netcoreapp3.0</TargetFramework>
Note that you can refer to multiple .NET Framework versions within your library projects. In this case, you have to replace the TargetFramework element with the TargetFrameworks element.

For instance, if you want to cross-target .NET Core 3 and .NET Core 2, you have to use the following settings:<TargetFrameworks>netcoreapp3.0;netcoreapp2.0</TargetFrameworks>

When executing your application in Debug mode by hitting the F5 key, you can see that multiple folders and files have been created in the application's Debug folder (/bin/Debug):

If you change the .csproj file and add other target frameworks, you will see that additional folders will be generated. The DLLs for each specific .NET Framework version are then put into the corresponding folders: 

The preceding example uses the TargetFrameworks settings for .NET Core 2 and .NET Core 3.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.190.156.212