1
votes

I set up an ubuntu 16.04 machine with Jenkins, nodejs, and .net core 2.0, and then tried to have it build my .net core 2.0 web application. It failed with the following message(s):

16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Authorization". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Mvc.Abstractions". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.IdentityModel.Tokens". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.IdentityModel.Tokens.Jwt". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/ForbiddenResult.cs(5,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(3,28): error CS0234: The type or namespace name 'Mvc' does not exist in the namespace 'Microsoft.AspNetCore' (are you missing an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Services/Impl/TokenManagementService.cs(10,14): error CS0234: The type or namespace name 'IdentityModel' does not exist in the namespace 'System' (are you missing an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Services/Impl/TokenManagementService.cs(12,17): error CS0234: The type or namespace name 'IdentityModel' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/ForbiddenResult.cs(9,33): error CS0246: The type or namespace name 'IActionResult' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/ForbiddenResult.cs(18,40): error CS0246: The type or namespace name 'ActionContext' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(8,51): error CS0246: The type or namespace name 'IActionFilter' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(33,33): error CS0246: The type or namespace name 'ActionExecutingContext' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(53,32): error CS0246: The type or namespace name 'ActionExecutedContext' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj] 16:32:27 Security/Decorators/GroupMemberAttribute.cs(58,24): error CS0246: The type or namespace name 'ActionExecutingContext' could not be found (are you missing a using directive or an assembly reference?) [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj]

On my dev machine, I looked around and couldn't find those assemblies, but I'm definitely referencing them, so I'm guessing they're stashed in a common location somewhere.

What do I need to do to get all the referenced assemblies to be found by Jenkins and successfully build my project? All the documentation I've seen online seems to reference .net core 1.0 or 1.1 and it seems a lot of this stuff is different now.

My build steps are very simple (there's one). A script to do:

dotnet clean
dotnet restore
dotnet build
1
Could you share what you have in your Jenkins build step?Igors Sutovs

1 Answers

3
votes

SO IT TURNS OUT that this is a bug (perhaps of ReSharper) where if you reference a library in your solution in a project for the first time, and automagically update the reference, the reference isn't added completely correctly; IOW, the MySolution.Common project did not explicitly add the dependent assemblies to the project file, even though they were part of the solution and available.

On my development machine, that didn't matter so much; Visual Studio was able to find the dependencies just fine. On my build server, however, this was a critical piece of information that was missing.

HOW TO CORRECT

If we take a look at the first error:

16:32:26 /usr/share/dotnet/sdk/2.0.0/Microsoft.Common.CurrentVersion.targets(1987,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.AspNetCore.Authorization". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [/var/lib/jenkins/workspace/MySolution Main App/MySolution.Common/MySolution.Common.csproj]

...we can see that the problem occurred when building the MySolution.Common project, and the missing assembly was Microsoft.AspNetCore.Authorization.

There are two ways to make this work. One is to manually edit the .csproj file. If you add the line in the PackageReference ItemGroup like so:

<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="2.0.1" />

... the problem (for that missing reference) will go away. This is what I originally did, and it worked, but then I found out that I could do this without messing with that file by simply going to my Package Management Console and doing something like this:

cd MySolution.Common
dotnet add reference Microsoft.AspNetCore.Authorization

...this would add it to the project file properly, along with the proper version and everything, so I think this is a better method.

I hope this saves someone the hours it cost me.