All docs
V21.1
21.2 (EAP/Beta)
21.1
20.2
The page you are viewing does not exist in version 20.2. This link will take you to the root page.
20.1
The page you are viewing does not exist in version 20.1. This link will take you to the root page.
19.2
The page you are viewing does not exist in version 19.2. This link will take you to the root page.
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

Port an XAF shared module from .NET Framework to .NET Standard 2.0+

  • 3 minutes to read

Imagine that you have an XAF .NET Framework solution for WinForms and ASP.NET WebForms with the following structure:

  • YourSolutionName.Module
  • YourSolutionName.Module.Win
  • YourSolutionName.Module.Web
  • YourSolutionName.Win
  • YourSolutionName.Web

You need to convert the existing .NET Framework WinForms projects to .NET 5, and add an ASP.NET Core Blazor Server project to this solution. Also, you wish to keep .NET Framework ASP.NET WebForms projects working.

If you have shared XAF modules that should be reused in both .NET Framework and .NET 5 apps, you can target .NET Standard 2.0 in these shared projects. This article describes how to convert XAF shared modules from .NET Framework to .NET Standard 2.0. These techniques are applicable to DevExpress components v20.1 and higher. After you convert a module to .NET Standard 2.0, you can reuse it in .NET Framework 4.6.1+, .NET 5+ WinForms, and Blazor Server projects.

Important

.NET Framework does not support .NET Standard 2.1. Use .NET Standard 2.0 instead. See the following topic for more information: When to target net5.0 vs. netstandard.

Convert a .NET Framework XAF Module to .NET Standard

  1. Copy your shared module to another folder to avoid breaking your existing project. If your module has platform-specific code, move this code to the corresponding platform-specific modules of your XAF project (YourSolutionName.Module.Win and YourSolutionName.Module.Web).

  2. Replace the existing code in the YourSolutionName.Module.csproj file with the following code:

    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Library</OutputType>
        <TargetFramework>netstandard2.0</TargetFramework>
        <RootNamespace>YourSolutionName.Module</RootNamespace>
        <AssemblyName>YourSolutionName.Module</AssemblyName>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <Deterministic>false</Deterministic>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DefineConstants>TRACE;DEBUG</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DefineConstants>TRACE</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'EasyTest|AnyCPU' ">
        <DefineConstants>TRACE;DEBUG;EASYTEST</DefineConstants>
    </PropertyGroup>
    <ItemGroup>
        <EmbeddedResource Include="**\*.svg" />
        <EmbeddedResource Include="**\*.xafml" />
        <EmbeddedResource Remove="bin\**" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="DevExpress.ExpressApp.Core.All" Version="currentVersion" />
        <PackageReference Include="DevExpress.ExpressApp.Security.Xpo" Version="currentVersion" />
        <PackageReference Include="DevExpress.Persistent.BaseImpl.Xpo" Version="currentVersion" />
    </ItemGroup>
    </Project> 
    
    <Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Library</OutputType>
        <TargetFramework>netstandard2.0</TargetFramework>
        <RootNamespace>YourSolutionName.Module</RootNamespace>
        <AssemblyName>YourSolutionName.Module</AssemblyName>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <Deterministic>false</Deterministic>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
        <DefineConstants>TRACE;DEBUG</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
        <DefineConstants>TRACE</DefineConstants>
    </PropertyGroup>
    <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'EasyTest|AnyCPU' ">
        <DefineConstants>TRACE;DEBUG;EASYTEST</DefineConstants>
    </PropertyGroup>
    <ItemGroup>
        <EmbeddedResource Include="**\*.svg" />
        <EmbeddedResource Include="**\*.xafml" />
        <EmbeddedResource Remove="bin\**" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="DevExpress.ExpressApp.Core.All" Version="currentVersion" />
        <PackageReference Include="DevExpress.ExpressApp.Security.EFCore" Version="currentVersion" />
        <PackageReference Include="DevExpress.Persistent.BaseImpl.EFCore" Version="currentVersion" />
    </ItemGroup>
    </Project> 
    
  3. Replace the YourSolutionName placeholder with your project’s root namespace. Replace the currentVersion placeholder with the current version of DevExpress NuGet packages. You can find the version number in the NuGet Package Manager.

  4. If you reference other NuGet packages, add additional <PackageReference> elements for them. The following section lists DevExpress XAF NuGet Packages: XAF NuGet Packages.
  5. Select the Add -> Existing project… item in the solution context menu to add your shared module to the solution.
  6. Run your application.

The following example uses a .NET Standard 2.0 platform-agnostic module with XAF WinForms, ASP.NET WebForms, and ASP.NET Core Blazor Server applications:

View Example: XAF - How to show the number of nested List View items in tab captions

Note

The following section describes how to add only required Data Model classes from an existing .NET Standard Module: Import Classes from a Business Class Library or Module.

See Also