If you run
msbuild and get an error message that points out
Microsoft.PackageDependencyResolution.targets(198,5), then this article may help you and your build. The problem is so simple, but if you are new with building .NET code without Visual Studio, it would not look such simple. As I didn't easily get solutions for it by googling, I thought it may be worth to write it in an article.
Background
While building my solution on Visual Studio, builds were all fine, but once I built it on AppVeyor, I came across the build error shown blow.
Microsoft (R) Build Engine version 15.6.0.0 (xplat-master/ca830585 Sun Mar 25 19:24:09 EDT 2018) for Mono<br />Copyright (C) Microsoft Corporation. All rights reserved.<br /><br />/usr/local/share/dotnet/sdk/2.1.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file '/Users/yas/Projects/UriConvert/UriConvert/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/yas/Projects/UriConvert/UriConvert/UriConvert.csproj]<br />/usr/local/share/dotnet/sdk/2.1.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.PackageDependencyResolution.targets(198,5): error : Assets file '/Users/yas/Projects/UriConvert/UriConvert.Test/obj/project.assets.json' not found. Run a NuGet package restore to generate this file. [/Users/yas/Projects/UriConvert/UriConvert.Test/UriConvert.Test.csproj]<br />
The weird thing was that running
msbuild in command line in my local, the error didn't occur and the build was success. There were a lot of stuffs suspecious, which was also because I'm new in AppVeyor and msbuild.
After a while, I succeeded to reproduce this error. After deleting intermediate output directories, which default is
obj/, I got the same error in my local. It is thus a problem not only with AppVeyor but generally with builds without Visual Studio.
The error message points out a file named project.assets.json, which is in the intermediate output directories. This is a file generated by nuget. With using Visual Studio, it is generated when opening a solution that has dependency to NuGet packages, whih is because NuGet Visual Studio add-in automatically runs NuGet restore at that occasion. It is not removed when cleaning the solution or projects, by the way. This makes sense in a way that msbuild and nuget is separate tools, and msbuild only clean up things generated by msbuild.
Therefore, msbuild succeeded in my environment because I always had project.assets.json because of the use of Visual Studio, and it didn't in AppVeyor because the solution was not opened in Visual Studio and only msbuild was run. I guess that it would be an interesting fact for beginers in msbuild.
Solution
So, a solution for it is very simple. As this error message mentions, what is required is to run NuGet restore before running msbuild, which can be run with a line of command below.
nuget restore
Solution in AppVeyor
As I had this problem in AppVeyor, here is also a solution for build in AppVeyor.
Go to [SETTINGS] - [Build], and scroll down to
Before build scription section, add the line above and save it.
Please find me in
CodeProject.