MSBuild error finding the nuget.targets file

22,405

Solution 1

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:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\CableSense\</SolutionDir>

Which then caused the issue! Hope this helps someone else there, I feel bad for answering my own question now.

Solution 2

OK, so I got the same error now recently but the solution worked out to be different for me.

In the Build Definition, under Source Settings, I had the Source Control Folder set to the directory of the actual project instead of the root folder for the solution.

I know this is an old answered thread, but this might help someone who made the same mistake I did.

Share:
22,405
Matt Roberts
Author by

Matt Roberts

Updated on July 01, 2020

Comments

  • Matt Roberts
    Matt Roberts almost 4 years

    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?