我问过 question about build errors并继续由我绝望的自己进一步调查这个问题。
我猜测问题在于获取但未正确放置的包。翻阅枯燥乏味的日志给了我这个。
2016-01-15T21:50:40.8680146Z
The target "BeforeGenerateProjectPriFile" listed in a BeforeTargets attribute at "C:\Program Files (x86)\MSBuild\Microsoft\NuGet\Microsoft.NuGet.targets (186,61)" does not exist in the project, and will be ignored.
此后不久,我可以看到某些东西横向移动的第一个迹象。
2016-01-15T21:50:43.9631666Z ##[warning]
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
2016-01-15T21:50:43.9631666Z 2>
C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors. [C:\a\1\s\MyStuff\MyStuff.csproj]
然后它继续大量考虑不存在的东西。
2016-01-15T21:50:43.9661661Z
Considered "..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\lib\net45\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.dll", but it didn't exist.
2016-01-15T21:50:43.9671655Z
For SearchPath "{TargetFrameworkDirectory}". 2016-01-15T21:50:43.9681655Z
Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.2\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.winmd", but it didn't exist.
...
我不熟悉 TFS 上的 CI 或 VS Online,所以它几乎没有告诉我在哪里解决问题。我在谷歌上搜索了半死,并在整个门户网站上测试了无数不同的设置。没运气。我可能会导致其他错误(当我知道我输入了错误的内容时等),但无论如何,我都会转向这个错误。
任何提示将不胜感激。
最佳答案
从 VS2015 版本开始,不需要 NuGet 文件夹,这与我看到的指南相反。事实上,唯一需要的文件是包的配置文件。有一种常见但非常具有欺骗性的解决方法来检查包及其可执行文件,但这可能会在 future 产生很多问题。我不建议这样做,因为它隐藏了问题,而不是解决问题。
首先,验证您的构建是否确实恢复了包。我注意到在错误日志中,看起来好像是这样,但这是一个陷阱。这是一种恢复的尝试,而不是真正的成功。如果您遇到这样的警告(对于 nUnit、WebGrease、NewtonSoft 或 NuGet 控制下的任何其他包也是如此):
Warning MSB3245: Could not resolve this reference. Could not locate the assembly "EntityFramework". Check to make sure the assembly exists on disk.
首先验证日志是否包含以下段落:
PrepareForBuild:
Creating directory "obj\Debug\".
...
RestorePackages:
"C:\a\src\src.nuget\nuget.exe" install "C:\a\src\src\xxxx.Entities\packages.config"
-source -RequireConsent -o "C:\a\src\src\packages"
...
Successfully installed "EntityFramework 6.3.1". ResolveAssemblyReferences:
Primary reference "EntityFramework".
请记住,当您查看日志文件时,请搜索部分字符串,因为目录、版本、包名称等可能略有不同。如果您找不到它,则很有可能在构建服务器上没有恢复这些包。本地编译证明环境之间存在差异,很可能是packages.config文件不可用。这是一个棘手的错误,因为失败的日志不会告诉您它丢失了。事实上,我的日志中根本没有提到它。
出现此问题的原因是初始 checkin 选择了许多要忽略的文件。主要是 bin、obj 等,但也包括 packages.config。它需要特别选择为不被忽略。如果有人 checkin 所有文件(在我看来不是很明智),他也会获得所需的文件,因此看起来他们做得对。请注意,您应该先将文件添加到版本控制中。这样,它在每次更改时都会被检入。否则,如果您在本地添加新软件包或更新现有软件包,问题将再次出现。
如果您收到警告但软件包已恢复(日志中列出了这些行),请尝试在本地更新软件包或重新安装它。最后,您可以通过运行
Update-Package -Reinstall
从包管理器控制台刷新安装。 .关于tfs - 在 TFS (VS Online VS2015) 下在 CI 队列上构建时未恢复包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34820770/