Subscribe

UiPath Developer

The UiPath Developer Guide

Migrating Activities to .NET 6

This page offers an overview of how to migrate your custom .NET Framework activities to .NET 6 for use in projects with the Windows and cross-platform compatibilities available starting with Studio 2021.10.6.

Step 1: Migrate the project to the new SDK-style format

If your project is using the .NET Framework project format, you must migrate it to the new SDK-style format.

Use the <Project Sdk="Microsoft.NET.Sdk" attribute for most projects. For projects that require WPF,
use <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop" with <UseWpf>true</UseWpf>.

Package references must be declared in the .csproj file as opposed to packages.config. You must declare the following WWF dependencies for .NET.
<PackageReference Include="UiPath.Workflow.Runtime" />
<PackageReference Include="UiPath.Workflow" />
<PackageReference Include="System.Activities.Core.Presentation" />
<PackageReference Include="System.Activities.Metadata" />

Considerations

To centralize package versions, you can create a global Directory.build.targets file with dependencies used by most projects. For example:

<Project>
  <ItemGroup Condition="'$(TargetFramework)' != 'net461' ">
    <PackageReference Update="UiPath.Workflow.Runtime" Version="6.0.0-20220401-03" PrivateAssets="All"/>
    <PackageReference Update="UiPath.Workflow" Version="6.0.0-20220401-03" PrivateAssets="All"/>
    <PackageReference Update="System.Activities.Core.Presentation" Version="6.0.0-20220318.2" PrivateAssets="All"/>
    <PackageReference Update="System.Activities.Metadata" Version="6.0.0-20220318.2" PrivateAssets="All"/>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Update="UiPath.Activities.Api" Version="22.4.1" PrivateAssets="All" />
  </ItemGroup>
</Project>

🚧

Important:

Do not include the referenced packages in the NuGet package or add them as dependencies in the package metadata. Including the referenced packages results in a failure to install the package in Studio.

Then, in your project file you only need to specify the package name. For example:

<PackageReference Include="CsvHelper"/>

You can create a dedicated .build.targets file for your specific solution to centralize other dependencies and include it in your .csproj files as follows:

<Import Project="..\System.build.targets" />

You can create a dedicated .build.props file for your specific solution to centralize other properties like version, company, etc. Include it in your .csproj files as follows:

<Import Project="..\System.build.props" />

See the Microsoft documentation for a migration example.

Step 2. Add the .NET target framework in all project files

In addition to net461, you must add either the net6.0-windows or net6.0 target framework.

  • For a project you want to be compatible with Windows, add net6.0-windows.
  • For a cross-platform project, add net6.0.

References to DLLs related to the package must be replaced with packages where needed, as in the following sample project file:

<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
    <PropertyGroup>
        <TargetFrameworks>net461;net6.0-windows</TargetFrameworks>
        <UseWPF>true</UseWPF>
    </PropertyGroup>
    <PropertyGroup>
        <PackageId>UiPath.Api.Sample</PackageId>
        <PackageIconUrl>https://download.uipath.com/UI_icon.png</PackageIconUrl>
        <PackageLicenseUrl>https://www.uipath.com/hubfs/legalspot/UiPath_MSSA.pdf</PackageLicenseUrl>
        <PackageProjectUrl>https://docs.uipath.com/studio/docs/about-the-activities-sdk</PackageProjectUrl>
        <Description>API for developing UiPath Activities</Description>
        <Authors>UiPath</Authors>
        <Version>21.10.0</Version>
        <RootNamespace>MyCustomActivityPack</RootNamespace>
        <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    </PropertyGroup>
    <ItemGroup Condition="'$(TargetFramework)' == 'net461' ">
        <Reference Include="System.Activities" />
        <Reference Include="System.Activities.Core.Presentation" />
        <Reference Include="System.Activities.Presentation" />
    </ItemGroup>
    <ItemGroup Condition="'$(TargetFramework)' != 'net461' ">
        <PackageReference Include="System.Activities" />
        <PackageReference Include="UiPath.Workflow" />
        <PackageReference Include="System.Activities.Core.Presentation" />
        <PackageReference Include="System.Activities.Metadata" />
    </ItemGroup>
    <ItemGroup>
        <PackageReference Include="UiPath.Activities.Api"/>
    </ItemGroup>
</Project>

Make sure all your dependencies support .NET Core. You might need to find newer package versions or replacement packages.

If parts of your code do not compile and it is feasible to exclude them, consider moving the affected classes under a NetFramework folder and adjust your Directory.build.targets as follows:

<Choose>
    <When Condition="$(TargetFramework.StartsWith('net4'))">
      <ItemGroup>
        <Compile Remove="NetCore\**\*.cs" />
      </ItemGroup>
      <ItemGroup>
        <Page Remove="NetCore\**\*.xaml" />
      </ItemGroup>
    </When>
    <Otherwise>
      <ItemGroup>
        <Compile Remove="NetFramework\**\*.cs" />
      </ItemGroup>
      <ItemGroup>
        <Page Remove="NetFramework\**\*.xaml" />
      </ItemGroup>
    </Otherwise>
  </Choose>

For smaller lines of code and methods, you can use #if NET461 and related code directives. If this approach is not feasible, consider splitting your activity class names and public properties in a separate .shared project with partial classes and include them in a dedicated .Standard.csproj while they are still included in your main activities project.

Step 3: Create a NuGet package

You can create packages using dotnet pack directly with the .csproj files. For more information, see the Microsoft documentation

  • Consider creating a separate project just for bundling your package.

  • To exclude the .Package DLL, use:

<Target Name="RemoveMetaDll" AfterTargets="BuiltProjectOutputGroup">
    <ItemGroup>
      <BuiltProjectOutputGroupOutput Remove="@(BuiltProjectOutputGroupOutput)" />
    </ItemGroup>
</Target>
  • Include all required files explicitly. For example:
<Target Name="AddDlls">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutputPath)CustomInputForm.exe" />
      <BuildOutputInPackage Include="$(OutputPath)UiPath.OrchestratorClient.dll" />
      <BuildOutputInPackage Include="$(OutputPath)UiPath.System.Activities.dll" />
      <BuildOutputInPackage Include="$(OutputPath)UiPath.System.Activities.Design.dll" />
      <BuildOutputInPackage Include="$(OutputPath)de\UiPath.System.Activities.resources.dll" TargetPath="de\UiPath.System.Activities.resources.dll" />
      <BuildOutputInPackage Include="$(OutputPath)de7\UiPath.System.Activities.Design.resources.dll" TargetPath="de\UiPath.System.Activities.Design.resources.dll" />
    </ItemGroup>
</Target>
  • Use the target as follows:
<TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);AddDlls</TargetsForTfmSpecificBuildOutput>
  • Resource DLLs must be listed individually, unless you find an alternative solution.

  • Make sure to add package references with the appropriate TargetFramework conditions.

  • Adjust your CI pipeline to be able to pack the new package format with the [email protected] task. For example:

- task: [email protected]
  displayName: "Create NET .SDK Packages"
  continueOnError: true
  inputs:
    command: "pack"
    packagesToPack: "$(SdkPackagesToPack)"
    configurationToPack: "$(BuildConfiguration)"
    outputDir: "$(ArtifactsOutputPath)"
    nobuild: true
  condition: eq(variables['HasSdkPackages'], 'true')
  • Consider leaving an empty <VersionSuffix></VersionSuffix> tag in your .Package.csproj and adjust your CI scripts to replace it with the -alpha, beta suffixes. Other approaches might be feasible and it depends on your CI pipeline.

  • For local development builds, consider adding a post-build debug step that calls the dotnet pack command.

Updated about a month ago

Migrating Activities to .NET 6


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.