dotnet build issue for ArcGIS Runtime LocalServer 100.15 Deployment

587
2
11-23-2022 06:27 PM
Joshua-JD
New Contributor

When we use dotnet cli to build a .NET Framework project we get the following error when including Esri.ArcGISRuntime library, error MSB4062: The "DeploymentTask" task could not be loaded from the assembly net461\Esri.ArcGISRuntime.LocalServices.BuildTasks.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

This error is due to the dotnet cli using .NET Core and not .NET Framework for it's build tasks. The dotnet cli can not load the .NET Framework 4.6.1 dependent libraries for the Esri.ArcGISRuntime.LocalServices to complete the Esri DeploymentTask. Looking at the NuGet package(Esri.ArcGISRuntime.LocalServices), there is both a .NET Standard 2.0 and a .NET Framework 4.6.1 version of Esri.ArcGISRuntime.LocalServices.BuildTasks. I believe you can remove the .NET Framework 4.6.1 version and just use the .NET Standard version because .NET Standard 2.0 is compatible with .NET Framework 4.6.1 https://dotnet.microsoft.com/en-us/platform/dotnet-standard.

I have tested this myself by manually replacing the .NET Framework 4.6.1 Esri.ArcGISRuntime.LocalServices.BuildTasks library with the .NET Standard version and it successfully ran without errors and produced the expected results. I tested it also with Visual Studio 2022 and it was error free in both cases and produced the same results before and after the experiment of replacing the library. I believe this is the solution for this issue.

Can you please update the packages to resolve this error?

Thanks

0 Kudos
2 Replies
Joshua-JD
New Contributor

To highlight the issue, it's with the fact that dotnet CLI uses .NET Core/5/6/7 and not .NET Framework to run tasks. The Esri build tasks are built in .NET Framework 4.6.1 and .NET Standard 2.0 which allows for msbuild to use the .NET Framework version of Esri build task and dotnet build to use .NET Standard 2.0 when building a .NET Core/5/6/7 project. The issue comes in when building a .NET Framework project with the dotnet CLI, as the CLI uses the .NET Framework version of the Esri build task since it matches the project .NET version but dotnet CLI can't load and run the build task since it's running .NET Core/5/6/7 instead. If you build a .NET Core/5/6/7 project using dotnet build and Esri it will work since it will use the .NET Standard 2.0 library for the project which allows the build task work properly.


The simple solution is to remove the .NET Framework 4.6.1 version of the build task and use only the .NET Standard 2.0 version. That works for both MSBuild and dotnet CLI with any combination of .NET project types(.NET Framework or .NET Core/5/6/7) and is fully compliant with what Esri currently supports. While my testing with our projects shows that this method will work, it would obviously be recommended that Esri test this to ensure that I have not overlooked anything. Here's a link to Microsoft showing that .NET Standard 2.0 is fully compatible with .NET Framework 4.6.1 (https://dotnet.microsoft.com/en-us/platform/dotnet-standard). If you look at the source code, you will notice they are the same besides calls to Log.LogError have an extra parameter at the end which is Array.Empty<object>(), and the references are slightly different because of what is included and not included in .NET Framework/Standard. Those differences shouldn't cause any issues for anyone.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Building .NET Framework applications with the dotnet cli is not currently supported. Either port your application to .NET 6, or use MSBuild to compile your application from commandline.

Is there a particular reason you want to use "dotnet build" instead of "msbuild /t:Build" ?

0 Kudos