6
votes

I have a solution that contains projects targeting .NET Framework 4.6.1 and a single project targeting .NET Core 2.0. This .Net Core project has references to projects targeting .NET Framework 4.6.1.

Locally, using Visual Studio 2017 Community, I can build this solution without any issue.

I am trying to configure a TeamCity build using the following steps :
1 - Clean packages folder
2 - Get packages : runner type = NuGet Installer and Restore mode = Restore
3 - Restore : dotnet restore MyDonetCoreProject.csproj
4 - Build solution : runner type = Visual Studio (sln) with VS 2017

I get a compilation error when compiling my .NET Core project :

C:\Program Files\dotnet\sdk\2.1.301\Sdks\Microsoft.NET.Sdk\targets\Microsoft.PackageDependencyResolution.targets(198, 5): Package Microsoft.AspNetCore, version 2.0.3 was not found. It might have been deleted since NuGet restore. Otherwise, NuGet restore might have only partially completed, which might have been due to maximum path length restrictions.

I checked the path C:\Users\MyUser\.nuget\packages\microsoft.aspnetcore on my TeamCity server and I have a folder 2.0.3.

I don't have any reference in my solution to this package. What is looking to this package and where is it looking ?

3
Did you try just one step - rebuild solution with runner type Visual Studio 2017? Restore should be automatic. You don't have to execute restore twice.Peska
Just tried it. I got the same error.PMerlet
Hi @PMerlet, did you manage to solve the problem?rotman
@rotman I added an answer to describe the config I am currently usingPMerlet
@PMerlet thanks but unfortunately it didn't help in my case - I run into another problem in dotnet build so I had to stick to MSBuild. I will post my solution here.rotman

3 Answers

0
votes

Why do not you use .NetCore CLI command to build your .NetCore app or library. but at the same time, you should have both .NetCore 2.0 and .NET Framework 4.6.1 on build Agent. I am not familiar with TeamCity CI, you could try this,

instead of step << 4 - Build solution : runner type = Visual Studio (sln) with VS 2017 >>

dotnet build [.csproj of .NetCore]

https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-build?tabs=netcore2x

You could consider using .net standard (as target) instead of having tagets to specific framework version if applicable.

0
votes

I managed to fixed this issue using the following build process :

1- Restore nugets : use restore mode "Restore (requires NuGet 2.7+) and specify all your packages sources in the field "Packages sources" (even if you have a NuGet.config file in your solution) and set "Update mode" to "Update via solution file"

2- Build solution : set "Runner type" to ".NET CLI (dotnet)" with "command" set to "build"

I cannot remember why I had to remove the cleaning step but this works for me.

0
votes

In my case the reason of the problem was the old version of NuGet set in TeamCity. I used version 3.4.3 which used MSBuild 14.0 which does not support new csproj files. Here is the log from my build agent:

[Step 6/14] restore: Restoring NuGet packages for xxx.sln (7s)
[restore] NuGet command: C:\BuildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\BuildAgent\tools\NuGet.CommandLine.3.4.3\tools\NuGet.exe restore C:\BuildAgent\work\ccbe07449ac24705\e2.sln -Source https://www.nuget.org/api/v2/ -Source http://xxx/guestAuth/app/nuget/v1/FeedService.svc/
[restore] Starting: C:\BuildAgent\temp\agentTmp\custom_script4470451835266630981.cmd
[restore] in directory: C:\BuildAgent\work\ccbe07449ac24705
[restore] JetBrains TeamCity NuGet Runner 2018.1.4015.0
[restore] Registered additional extensions from paths: C:\BuildAgent\plugins\nuget-agent\bin\plugins-3.3
[restore] Starting NuGet.exe 3.4.3.855 from C:\BuildAgent\tools\NuGet.CommandLine.3.4.3\tools\NuGet.exe
[restore] MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.

Changing NuGet version to 4.7.1 solved the problem. This topic helped me: https://github.com/dotnet/sdk/issues/2347