.net 查找 nuget.targets 文件时出现 MSBuild 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13975682/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:47:55  来源:igfitidea点击:

MSBuild error finding the nuget.targets file

.netmsbuildnuget

提问by Matt Roberts

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.

我正在尝试使用 msbuild 构建一个 csproj 项目,但是遇到了各种奇怪的问题,抱怨找不到 nuget.targets。

I run the simplest of command line builds with MSbuild:

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

Msbuild Project.csproj

And that works in my normal dev folder, but in another folder location, it fails with these errors:

这适用于我的普通 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.

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.

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

The csproj specifies the location of the nuget.targets file like this:

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

<Import Project="$(SolutionDir)\.nuget\nuget.targets" />

And the SolutionDir is defined like so:

并且 SolutionDir 定义如下:

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

Which is the same as the other project that does work. Any ideas?

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

回答by Matt Roberts

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:

啊!发布后我发现了问题..基本上,该项目依赖于其他项目。这些相关项目的 csproj 文件略有错误 - 并将其作为 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.

然后导致了这个问题!希望这可以帮助那里的其他人,我现在回答我自己的问题感到很难过。

回答by Talon

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.

在 Build Definition 中的 Source Settings 下,我将 Source Control Folder 设置为实际项目的目录,而不是解决方案的根文件夹。

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

我知道这是一个旧的回答线程,但这可能会帮助那些犯了同样错误的人。

回答by MNF

for me I just changed the solution location, in order to have a short location.

对我来说,我只是改变了解决方案的位置,以便有一个短的位置。