MSBuild错误找到nuget.targets文件

Mat*_*rts 33 .net msbuild nuget

我正在尝试用msbuild构建一个csproj项目,但是它有各种奇怪的问题抱怨没有找到nuget.targets.

我使用MSbuild运行最简单的命令行构建:

Msbuild Project.csproj
Run Code Online (Sandbox Code Playgroud)

这可以在我的普通dev文件夹中工作,但在另一个文件夹位置,它会因以下错误而失败:

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.

该路径(C:\BuildAgent\work\CableSense\.nuget\nuget.targets)实际上是错误的并且在工作之后丢失了一个文件夹(work\somefolder\cablesense),但我不知道为什么.更奇怪的是,如果我构建另一个项目,这是解决方案的一部分,那么这是有效的,它只是这个项目.

csproj指定nuget.targets文件的位置,如下所示:

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
Run Code Online (Sandbox Code Playgroud)

SolutionDir的定义如下:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
Run Code Online (Sandbox Code Playgroud)

这与其他有效的项目相同.有任何想法吗?

Mat*_*rts 56

哎呀!发布后我发现了问题..基本上,该项目依赖于其他项目.这些相关项目的csproj文件略有错误 - 并将其作为SolutionDir:

<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\CableSense\</SolutionDir>
Run Code Online (Sandbox Code Playgroud)

然后引起了这个问题!希望这有助于那里的其他人,我现在对回答我自己的问题感到很难过.

  • 好吧,马特,你说这导致了问题,但你没有说你是如何修复它的.我遇到了同样的问题,看着你的答案,我仍然不知道如何解决这个问题. (13认同)
  • 基本上,检查那些相关的项目,看看当SolutionDir不存在时使用的路径是否正确(在该帖子中它的../../CableSense是错误的) (5认同)