0

We have LogicApp application with function DLL to include C# code. It is working without problems.

We have unit tests created with MsTest. Everything was ok in Visual Code and Visual Studio.

But after we have added project reference to function DLL, we got a strange build error in Visual Studio:

The "Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.FindFunctionJsonFolders" task could not be loaded from the assembly C:\Users<user>.nuget\packages\microsoft.azure.workflows.webjobs.sdk\1.2.0\build\tools\net8.0\Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.dll. Could not find a part of the path 'C:\Users<user>.nuget\packages\microsoft.azure.workflows.webjobs.sdk\1.2.0\build\tools\net8.0'. Confirm that the 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.

Everything is ok in Visual Studio Code.

Of course we have all files in

C:\Users\<user>\.nuget\packages\microsoft.azure.workflows.webjobs.sdk\1.2.0\build\tools\net8.0

Our Function DLL project:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <IsPackable>false</IsPackable>
        <TargetFramework>net8</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <OutputType>Library</OutputType>
        <PlatformTarget>AnyCPU</PlatformTarget>
        <LogicAppFolderToPublish>$(MSBuildProjectDirectory)\..\cus-02</LogicAppFolderToPublish>
        <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        <SelfContained>false</SelfContained>
    </PropertyGroup>
     
    <ItemGroup>
      <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="2.0.0"     PrivateAssets="all" />
      <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="2.0.0" />
      <PackageReference Include="Microsoft.Azure.Workflows.Webjobs.Sdk" Version="1.2.0" />
    </ItemGroup>
    
    <Target Name="TriggerPublishOnBuild" AfterTargets="Build">
          <CallTarget Targets="Publish" />
    </Target>
</Project>

We have created an empty .NET 8.0 console application and just add this nuget package:

Microsoft.Azure.Workflows.Webjobs.Sdk

and got the same error. Ildasm and other tool cannot show IL or C# of this library.

Do you have any ideas why we have these issues in Visual Studio 2022?

We need develop and debug unit tests in Visual Studio.

We are using this library for LogicApp unit tests:

https://github.com/LogicAppUnit/TestingFramework

Update. Thank for your help. But

There is no "AzureFunctionsProject" and "LogicAppSkipBuildTargets" switchers in .targets file (C:\Users<user>.nuget\packages\microsoft.azure.workflows.webjobs.sdk\1.2.0\build\Microsoft.Azure.Workflows.WebJobs.Sdk.targets ) or in Reflected source code from C:\Users<user>.nuget\packages\microsoft.azure.workflows.webjobs.sdk\1.2.0\build\tools\net8\Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.dll

If you need the package, add it with PrivateAssets="all" to avoid importing its build tasks I have tried several ways but it still run everything from .targets file.

I have created dummy library to cover build tasks logic and override these 2 tasks.

Program.cs

 namespace ConsoleApp1
 {
     internal class Program
     {
         static void Main(string[] args)
         {
             Console.WriteLine("Hello, World!");
         }
     }
 }

ConsoleApp1.csproj

  <Project Sdk="Microsoft.NET.Sdk">
   
    <PropertyGroup>
      <OutputType>Exe</OutputType>
      <TargetFramework>net8</TargetFramework>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
    </PropertyGroup>
   
    <Import Project="override.targets" />
   
    <ItemGroup>
      <PackageReference Include="microsoft.azure.workflows.webjobs.sdk" Version="1.1.0" />
    </ItemGroup>
   
    <ItemGroup>
      <ProjectReference Include="..\DummyTasks\DummyTasks.csproj" />
    </ItemGroup>
   
  </Project>

ConsoleApp1.sln

  Microsoft Visual Studio Solution File, Format Version 12.00
  # Visual Studio Version 17
  VisualStudioVersion = 17.13.35931.197
  MinimumVisualStudioVersion = 10.0.40219.1
  Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp1", "ConsoleApp1.csproj", "{662A46AC-D2E0-490B-A208-C06610C51BE6}"
  EndProject
  Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DummyTasks", "..\DummyTasks\DummyTasks.csproj", "{F84A6058-FDC7-4555-9845-3D9F86E70869}"
  EndProject
  Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution 
        Debug|Any CPU = Debug|Any CPU                        
        Debug|x64 = Debug|x64
        Debug|x86 = Debug|x86
        Release|Any CPU = Release|Any CPU
        Release|x64 = Release|x64
        Release|x86 = Release|x86
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|x64.ActiveCfg = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|x64.Build.0 = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|x86.ActiveCfg = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Debug|x86.Build.0 = Debug|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|Any CPU.Build.0 = Release|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|x64.ActiveCfg = Release|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|x64.Build.0 = Release|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|x86.ActiveCfg = Release|Any CPU
        {662A46AC-D2E0-490B-A208-C06610C51BE6}.Release|x86.Build.0 = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|x64.ActiveCfg = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|x64.Build.0 = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|x86.ActiveCfg = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Debug|x86.Build.0 = Debug|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|Any CPU.Build.0 = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|x64.ActiveCfg = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|x64.Build.0 = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|x86.ActiveCfg = Release|Any CPU
        {F84A6058-FDC7-4555-9845-3D9F86E70869}.Release|x86.Build.0 = Release|Any CPU
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
    GlobalSection(ExtensibilityGlobals) = postSolution
        SolutionGuid = {9E357AA5-DDBC-447B-BB66-BAA54AA23B99}
    EndGlobalSection
  EndGlobal

override.targets

  <?xml version="1.0" encoding="utf-8"?>
  <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  
  
  
      <UsingTask TaskName="Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.ParameterizedFunctionJsonGenerator" Override="true" 
                  AssemblyFile="$(MSBuildProjectDirectory)\..\Lib\$(Configuration)\net8\DummyTasks.dll" 
                  TaskFactory="$(TaskFactory)"/>
      <Target Name="ParameterizedFunctionJsonGeneratorNetCore" AfterTargets="Build" Condition="'$(TargetFramework)' != 'net472'" >
          <ParameterizedFunctionJsonGenerator AssemblyOutPath="$(AssemblyOutPath)" ProjectName="$(MSBuildProjectName).dll" Language="$(TargetFramework)" />
      </Target>
      <Target Name="ParameterizedFunctionJsonGenerator" AfterTargets="_GenerateFunctionsPostBuild" Condition="'$(TargetFramework)' == 'net472'" >
          <ParameterizedFunctionJsonGenerator AssemblyOutPath="$(AssemblyOutPath)" ProjectName="$(ProjectName)" Language="$(TargetFramework)" />
      </Target>
  
  
  
      <UsingTask TaskName="Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.FindFunctionJsonFolders" Override="true" 
                  TaskFactory="$(TaskFactory)"
                  AssemblyFile="$(MSBuildProjectDirectory)\..\Lib\$(Configuration)\net8\DummyTasks.dll" >
      </UsingTask>
      <Target Name="DeleteFunctionJsonFoldersTarget" BeforeTargets="Compile"  Condition="'$(TargetFramework)' != 'net472'"> 
          <FindFunctionJsonFolders RootDirectory="$(MSBuildProjectDirectory)\bin\$(Configuration)\net8" >
              <Output TaskParameter="FunctionFolders" PropertyName="BuiltFolders" />
          </FindFunctionJsonFolders>
          <RemoveDir Directories="$(BuiltFolders)" />
      </Target>
  
  
  </Project>

DummyTasks\FindFunctionJsonFolders.cs

  using Microsoft.Build.Framework;
  using Microsoft.Build.Utilities;
  
  
  namespace Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks
  {
      public class FindFunctionJsonFolders : Microsoft.Build.Utilities.Task
      {
          public override bool Execute()
          {
              List<ITaskItem> list = new List<ITaskItem>();
              foreach (string str in Directory.GetDirectories(this.RootDirectory, "*", SearchOption.AllDirectories))
              {
                  if (File.Exists(Path.Combine(str, "function.json")))
                  {
                      list.Add(new TaskItem(str));
                  }
              }
              this.FunctionFolders = list.ToArray();
              return true;
          }
   
   
          [Required]
          public string RootDirectory { get; set; }
   
          [Output]
          public ITaskItem[] FunctionFolders { get; set; }
   
      }
  }

DummyTasks\ParameterizedFunctionJsonGenerator.cs

 using Microsoft.Build.Framework;
  
 namespace Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks
 {
     public class ParameterizedFunctionJsonGenerator : Microsoft.Build.Utilities.Task
     {
         public override bool Execute()
         {
             return true;
         }
 
         [Required]
         public string AssemblyOutPath { get; set; }
 
 
 
         [Required]
         public string ProjectName { get; set; }
 
 
         [Required]
         public string Language { get; set; }
 
     }
 }

DummyTasks\DummyTasks.csproj

  <Project Sdk="Microsoft.NET.Sdk">
  
    <PropertyGroup>
      <TargetFramework>net8</TargetFramework>
      <ImplicitUsings>enable</ImplicitUsings>
      <Nullable>enable</Nullable>
      <BaseOutputPath>..\Lib</BaseOutputPath>
    </PropertyGroup>
  
    <ItemGroup>
      <PackageReference Include="Microsoft.Build.Utilities.Core" Version="17.14.8" />
    </ItemGroup>
  
  </Project>

And again I can build it with "dotnet build" but in Visual Studio it complains: The "Microsoft.Azure.Functions.Extensions.Workflows.Sdk.BuildTasks.FindFunctionJsonFolders" task could not be loaded from the assembly \ConsoleApp1..\Lib\Debug\net8\DummyTasks.dll. Could not find type 'System.Runtime.CompilerServices.NullableContextAttribute' in assembly 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Runtime.dll'. Confirm that the 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.

Why do it go to 'C:\Windows\Microsoft.NET' and not to 'C:\Program Files\dotnet\packs\Microsoft.NETCore.App.Ref\8.0.15\ref\net8.0' ?

And I have tried check version of compiled dll (.net 8.0) with "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\x64\ildasm.exe" ConsoleApp1.dll /metadata[=MDHEADER] /text /noil

and it shows: // Metadata section: 0x424a5342, version: 1.1, extra: 0, version len: 12, version: v4.0.30319

So it looks all .net 8.0 dlls use .net framework 4.0

What is wrong?

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.