error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly

Xen 1 Reputation point
2021-03-31T07:59:38.39+00:00

[9:54 AM] Xen Cloete - BCX

Hi Gentle-men and ladies.

We are struggling with an issue the last few days and would like some assistance if possible. We have recently created a build server and loaded TeamCity to do our build.
Our app is a .NET Core 2.1 Web application. We are running the application on Visual Studio 2017. Not sure if you need information regarding the IDE. VisualStudioVersion = 15.0.27703.2035

We have the following error on three projects. I will list only one here.

==========================================================================================================
C:\TeamCity\buildAgent\temp\buildTmp.nuget\packages\microsoft.net.compilers\2.8.2\tools\Microsoft.CSharp.Core.targets(52,5):
error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly
C:\TeamCity\buildAgent\temp\buildTmp.nuget\packages\microsoft.net.compilers\2.8.2\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Assembly with same name is already loaded 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.

       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Solutions\WareHouse1.CloudRegion1.sln" ( target) (1) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\DataAccess\Context\EFCore\SqlServer\WareHouse1.CloudRegion1.DataAccess.Context.EFCore.SqlServer.csproj" ( target) (8:18) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\DataAccess\Context\EFCore\SqlServer\WareHouse1.CloudRegion1.DataAccess.Context.EFCore.SqlServer.csproj" (default target) (8:20) ->
       (ResolveKeySource target) ->
         C:\Program Files\dotnet\sdk\2.1.522\Microsoft.Common.CurrentVersion.targets(3214,5): error : PFX signing not supported on .NET Core


       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Solutions\WareHouse1.CloudRegion1.sln" ( target) (1) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\DataAccess\Context\EFCore\SqlServer\WareHouse1.CloudRegion1.DataAccess.Context.EFCore.SqlServer.csproj" ( target) (8:18) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\DataAccess\Context\EFCore\SqlServer\WareHouse1.CloudRegion1.DataAccess.Context.EFCore.SqlServer.csproj" (default target) (8:19) ->
         C:\Program Files\dotnet\sdk\2.1.522\Microsoft.Common.CurrentVersion.targets(3214,5): error : PFX signing not supported on .NET Core


       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Solutions\WareHouse1.CloudRegion1.sln" ( target) (1) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\UI\IdentityServer\WareHouse1Identity.csproj" ( target) (40:5) ->
         C:\Program Files\dotnet\sdk\2.1.522\Microsoft.Common.CurrentVersion.targets(3214,5): error : PFX signing not supported on .NET Core


       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Solutions\WareHouse1.CloudRegion1.sln" ( target) (1) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\UI\Host\WareHouse1.CloudRegion1.UI.Web.Host.csproj" ( target) (30:5) ->
       "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\WareHouse1CloudRegion1\UI\Host\Modules\WareHouse1.CloudRegion1.Modules.Core\WareHouse1.CloudRegion1.Modules.Core.csproj" ( target) (47:7) ->
         C:\Program Files\dotnet\sdk\2.1.522\Microsoft.Common.CurrentVersion.targets(3214,5): error : PFX signing not supported on .NET Core

==========================================================================================================

The problem is this section:
error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly
C:\TeamCity\buildAgent\temp\buildTmp.nuget\packages\microsoft.net.compilers\2.8.2\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll.
Assembly with same name is already loaded 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.

==========================================================================================================

When looking for resolution to this problem all I could find was to strongName sign the projects. So I did and the problem now is that .NET Core does not support PFX Signing.

Question asked before.

  1. Does the solution build on Visual Studio 2017? yes and works
  2. Have you StrongName signed the assemblies? yes and does not work on TeamCity Build See error above re: .NET Core

So the question is how do we resolve this problem?

Let me if anyone needs more information.

Thank you

X.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,947 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-04-01T04:12:19.883+00:00

    Hi Xen,

    error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly

    You can try to rename the package folder in your project directory, then clean and rebuild your project. The reference link: https://stackoverflow.com/a/32155774/11557747

    Best Regards,
    Dylan


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our **documentation to enable e-mail notifications if you want to receive the related email notification for this thread.**

    0 comments No comments

  2. Xen 1 Reputation point
    2021-04-01T07:17:35.763+00:00

    Morning Dylan,

    Thank you for your reply.

    We went ahead and did what you suggested. We renamed the folder and rebuilt the application. The package's folder was recreated on build. We committed the changes to the DevAzure Repo. The Build was run again on TeamCity. Unfortunately the same errors pops up. See below.

    "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Solutions\Warehouse1.CloudRegion1.sln" ( target) (1) ->
    "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Warehouse1CloudRegion1\UI\Host\Warehouse1.CloudRegion1.UI.Web.Host.csproj" ( target) (30:5) ->
    "C:\TeamCity\buildAgent\work\5d44c9bda67a0c54\src\Warehouse1CloudRegion1\UI\Host\Modules\Warehouse1.CloudRegion1.Modules.Core\Warehouse1.CloudRegion1.Modules.Core.csproj" ( target) (47:7) ->
    C:\TeamCity\buildAgent\temp\buildTmp.nuget\packages\microsoft.net.compilers\2.8.2\tools\Microsoft.CSharp.Core.targets(52,5): error MSB4062: The "Microsoft.CodeAnalysis.BuildTasks.Csc" task could not be loaded from the assembly C:\TeamCity\buildAgent\temp\buildTmp.nuget\packages\microsoft.net.compilers\2.8.2\build..\tools\Microsoft.Build.Tasks.CodeAnalysis.dll. Assembly with same name is already loaded 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.

    Any ideas?

    Regards

    X.


  3. Xen 1 Reputation point
    2021-04-05T16:42:32.363+00:00

    Hi Dylan,

    I will give it a try and see what happens.

    Thanks

    Xen

    0 comments No comments