"You must add a reference to assembly netstandard" when Jenkins builds iOS project

Hello,

I'm trying to build a CI pipeline with Jenkins for a solution containing a Xamarin iOS project and a .NET Standard, but I'm running into errors with MSBuild not finding a reference to the .NET Standard library:

IDebugSettingService.cs(8,22): error CS0012: The type 'IDisposable' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

ViewModels/IPresentationTabViewModel.cs(17,15): error CS0012: The type 'MulticastDelegate' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

ViewModels/ICredentials.cs(17,10): error CS0012: The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.

I can build the project successfully on my account on the Mac build machine, but the Jenkins service account always fails here. I've tried clearing and restoring all the NuGet packages, and the MSBuild logs aren't much help. However, I do notice that MSBuild seems to load significantly less assemblies when run by Jenkins than when run by my account.

Is this a problem with how my project is set up, or is it a problem with Jenkins?

Best Answer

Answers

  • mattwardmattward GBMember Xamurai

    If those files in the error messages are from the iOS project and not the .NET Standard project then I would check the same Mono and Xamarin.iOS versions are installed on the build server compared with the machine that is working.

    When a Xamarin.iOS project references a .NET Standard project then msbuild should, with the help of the Xamarin.iOS MSBuild targets, add a reference to the netstandard.dll that ships with Xamarin.iOS when it builds the project.

    Another workaround here would be to add an explicit reference to netstandard in your Xamarin.iOS project, but it should work without doing that.

     <ItemGroup>
        <Reference Include="netstandard" />
      </ItemGroup>
    

    However the file names in the error messages suggest that these maybe from the .NET Standard project, since you have view models and interfaces. In this case it might be that the .NET Standard project is not being restored first, using dotnet restore, or msbuild /t:restore. Also be worth checking what .NET Core SDK is installed on the build server.

  • arodriguezarodriguez Member ✭✭

    @mattward,

    First of all, thanks for responding to my question!

    I forgot to mention that this error happens when MSBuild tries to compile the .NET Standard project, not the iOS project; in fact, I can't get the latter to compile without the former compiling.

    In Jenkins, I have a build script that restores the NuGet packages, first with msbuild BlipBlop.sln /t:Restore followed by nuget BlipBlop.sln restore. I can see in the console output as well as in the service account's global .nuget cache that the packages are restored, but I still keep getting this error. The same Mono and Xamarin.iOS versions are installed on the build machine, and the .NET Core SDK is installed as well -- I can verify this by successfully building the same project on my personal account on the machine. It's Jenkins giving me the error when it tries to build the solution using its own account.

  • mattwardmattward GBMember Xamurai

    Since it works on the build machine with your personal account then the Mono and Xamarin.iOS versions must be OK. So it must be something else.

    I would compare the following on the build machine when using your personal account and the Jenkins account, to see what the differences are.

    • .NET Standard project's obj/project.assets.json file
    • msbuild BlipBlop.sln /v:diag > msbuild.log

    The last step runs a diagnostic MSBuild build and generates the output in msbuild.log. I would be looking at the csc command being used to see what references are being passed.

  • arodriguezarodriguez Member ✭✭

    I compared the two files you mentioned above and found this in the msbuild.log file:

    Dependency "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". (TaskId:47)
    Could not resolve this reference. Could not locate the assembly "netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. (TaskId:47)
    For SearchPath "/Users/ana_build/.nuget/packages/newtonsoft.json/11.0.2/lib/netstandard2.0". (TaskId:47)
    Considered "/Users/ana_build/.nuget/packages/newtonsoft.json/11.0.2/lib/netstandard2.0/netstandard.winmd", but it didn't exist. (TaskId:47)
    Considered "/Users/ana_build/.nuget/packages/newtonsoft.json/11.0.2/lib/netstandard2.0/netstandard.dll", but it didn't exist. (TaskId:47)
    Considered "/Users/ana_build/.nuget/packages/newtonsoft.json/11.0.2/lib/netstandard2.0/netstandard.exe", but it didn't exist. (TaskId:47)
    For SearchPath "/Jenkins/workspace/Jenkins_Admin/test_Pipeline/runtime". (TaskId:47)
    Considered "/Jenkins/workspace/Jenkins_Admin/test_Pipeline/runtime/netstandard.winmd", but it didn't exist. (TaskId:47)
    Considered "/Jenkins/workspace/Jenkins_Admin/test_Pipeline/runtime/netstandard.dll", but it didn't exist. (TaskId:47)
    Considered "/Jenkins/workspace/Jenkins_Admin/test_Pipeline/runtime/netstandard.exe", but it didn't exist. (TaskId:47)
    Required by "/Users/ana_build/.nuget/packages/newtonsoft.json/11.0.2/lib/netstandard2.0/Newtonsoft.Json.dll". (TaskId:47)
    Required by "BlipBlop.Platform.Abstractions". (TaskId:47)

    I checked the /Users/ana_build/.nuget/packages/ folder for netstandard.library, and netstandard.dll exists inside of it, so why is MSBuild looking for it in the newtonsoft.json folder and giving up there?

    With regards to the project.assets.json files, the Jenkins version is a whopping 4,500 lines compared to the 350 lines in the one created using my personal account. However, netstandard is nowhere to be found in the Jenkins version whereas it shows up in my version.

  • arodriguezarodriguez Member ✭✭

    It was the PATH environment variable! I went back and compared the variables between accounts and it turns out the Jenkins account didn't have the /usr/local/share/dotnet path. I added it, and the .NET Standard reference was resolved.

    Thank you for your help!

Sign In or Register to comment.