I try to build a solution with TeamCity. To reduce our repository-size, wie do NOT include DLLs into the repository, but use NuGet to receive the current actual version of any package when building the solution. We can build the solution on our local machines but receive an error on the TeamCity-Buildserver:
The type or namespace name 'Formatting' does not exist in the namespace 'System.Net.Http' (are you missing an assembly reference?)
I think there is a problem with the nuget-packages. System.Net.Http.Formatting should be in the NuGet-Package Microsoft.AspNet.WebApi.Client 5.0.0 which IS downloaded by Teamcity. But it seems that the build command (Microsoft Visual Studio solution runner) looks into the Microsoft.Net.Http 2.2.xx instead where is no "formatting"-namespace
This is just my guess, what is going wrong. Any clue how to fix this issue?
My Packages-Configuration:
<packages>
<package id="log4net" version="2.0.3" targetFramework="net45" />
<package id="Microsoft.Bcl.Build" version="1.0.10" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Client" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.Core" version="5.0.0" targetFramework="net45" />
<package id="Microsoft.AspNet.WebApi.WebHost" version="5.0.0" targetFramework="net45" />
<package id="System.Net.Http.Formatting" version="4.0.20505.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="4.5.11" targetFramework="net45" />
</packages>
There are 2 ways to do package restore. The older way involved having a .nuget folder alongside your solution with nuget.exe and nuget.targets there and a nuget.config file alongside your .sln file. This is typically enabled by right clicking on your solution file and hitting 'Enable Package Restore'.
The newer approach does not involve modifying the build process, but instead Visual Studio takes care of package restore. You don't need to enable it. I think it's on by default unless you've used the older approach. This new approach is great when you're building in VS, but when using TeamCity, you'll need to modify your build process.
Check which approach your using (the newer one wouldn't add a nuget.exe in {solution root}/.nuget). If you're using the newer one, you'd want to add a separate command-line step to your build process to call this. It will populate the packages folder with everything the build will need to succeed. Provided you didn't manually change references, the hint path on those references should point to the appropriate places (If you did, you can run Update-Package PackageName -Reinstall -ProjectName WhicheverProjectYouModified from the package manager console).
c:\somewhere\nuget.exe restore c:\somewhere\yoursolution.sln
This will require you to put a recent version of nuget.exe somewhere on your build server. If you already have nuget there somewhere, run this to bring it to the latest version:
nuget update -self
If you are using the old approach and still having problems with TC, I would recommend you update to the new approach (see the second link below).
See here for more info:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With