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?
A target element can have both Inputs and Outputs attributes, indicating what items the target expects as input, and what items it produces as output. If all output items are up-to-date, MSBuild skips the target, which significantly improves the build speed. This is called an incremental build of the target.
PackagePath : Path where the file should be output in the package. NuGet issues a warning if more than one file is added to the same package path. BuildAction : The build action to assign to the file, required only if the package path is in the contentFiles folder. Defaults to "None".
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. Here are some actions you can take to resolve this error: Add the /restore option to your MSBuild.exe command.
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.
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.
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