【问题标题】:VS Build fails for .NET project because of NuGet package restore errors由于 NuGet 包还原错误,.NET 项目的 VS 构建失败
【发布时间】:2018-10-02 13:23:01
【问题描述】:

我正在使用 Visual Studio 17 中的 .NET 4.5.2 开发一个 MVC.NET 项目,该项目由于错误而无法构建:

构建恢复了 NuGet 包。再次构建项目以在构建中包含这些包。如需更多信息,请参阅http://www.postsharp.net/links/nuget-restore

我的 PostSharp 版本是 4.1.30。

每次构建或重新构建项目时都会发生此错误,并且在连续构建几次后不会消失。该错误发生在几个引用 PostSharp 的项目中。

只有在我对解决方案进行更改后才会出现该错误。如果我签出新的 Trunk 副本,我可以加载该网站。只有在有机会发生这些错误之后。更改可能很小,例如在错误引用的不相关项目中添加新的控制器文件。

我尝试过恢复我的 NuGet 包,重新启动我的机器,甚至删除我的 repo 并重新检查一个全新的 Trunk 安装。我怎样才能克服这个错误?我不确定它是否肯定与 PostSharp 或更一般的 NuGet 错误有关。

在查看 .csproj 文件以查看导致其中一个项目出现错误的原因后,我发现了以下几行:

 <Import Project="packages\PostSharp.4.1.25\tools\PostSharp.targets" Condition="Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" />
 <Target Name="EnsurePostSharpImported" BeforeTargets="BeforeBuild" Condition="'$(PostSharp30Imported)' == ''">
    <Error Condition="!Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://www.postsharp.net/links/nuget-restore." />
    <Error Condition="Exists('packages\PostSharp.4.1.25\tools\PostSharp.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://www.postsharp.net/links/nuget-restore." />
  </Target>

我尝试删除它以查看会发生什么,但不出所料,它没有构建并且没有报告任何错误。

【问题讨论】:

  • 你能尝试从本地文件夹中删除所有包并重建项目吗?不要忘记备份文件夹..:D.
  • @Sham - 你指的是哪些包,来自哪个文件夹?我在 Windows 上。只是检查确定!
  • 可以安全地删除包文件夹(在您的项目文件夹中)以强制 NuGet 再次恢复。不过,这对我来说听起来像是 PostSharp 问题。
  • 在存在.sln 的解决方案目录中会有一个文件夹名称packages
  • 我是否还应该从错误提到的没有“包”文件夹的项目中删除“packages.xml”?我只能在我的启动项目文件夹中找到一个包文件夹(总共有 42 个项目)。

标签: c# visual-studio nuget postsharp build-error


【解决方案1】:

这看起来像是 PostSharp NuGet 包升级的问题。在您的 .csproj 文件中,安装了 PostSharp 4.1.25,但您说您使用的是 PostSharp 4.1.30。

以下其中一项可能会有所帮助:

  • 要么将 packages.config 中的包版本更改为 4.1.25,检查项目是否构建,然后根据需要使用 NuGet 包管理器升级到更新版本,
  • 或从 packages.confing 和 .csproj 中删除 PostSharp(您显示的行 + 对 PostSharp.dll 和任何其他 PostSharp.*.dll 的引用),然后使用 NuGet 包管理器安装 PostSharp。

请注意,不再支持 PostSharp 4.1。支持的版本列表见https://www.postsharp.net/support/policies#support

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-09-30
    相关资源
    最近更新 更多