I’m trying to build a csproj project with msbuild, but having all sorts of weird issues with it complaining about not finding nuget.targets.
I run the simplest of command line builds with MSbuild:
Msbuild Project.csproj
And that works in my normal dev folder, but in another folder location, it fails with these errors:
error MSB4019: The imported project "C:\BuildAgent\work\CableSense\.nuget\nuget.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
That path (C:\BuildAgent\work\CableSense\.nuget\nuget.targets) is actually wrong and is missing a folder after work (work\somefolder\cablesense), but I’m at a loss why. More weirdly, if I build another project that is part of the solution, then that works, it’s just this project.
The csproj specifies the location of the nuget.targets file like this:
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
And the SolutionDir is defined like so:
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
Which is the same as the other project that does work. Any ideas?
Argh! After posting this I found the issue.. Basically, the project had dependencies on other projects. The csproj files for those related projects were slightly wrong – and had this as the SolutionDir:
Which then caused the issue! Hope this helps someone else there, I feel bad for answering my own question now.