构建错误,此项目引用 NuGet
Build error, This project references NuGet
当我尝试构建解决方案时,收到以下错误消息:
Severity Code Description Project File Line Suppression State
Error This project references NuGet package(s) that are missing on
this computer. Use NuGet Package Restore to download them. For more
information, see http://go.microsoft.com/fwlink/?LinkID=322105. The
missing file is
..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props. MusicKarma C:\Users\Bryan\Documents\Visual
Studio 2015\Projects\MusicKarma\MusicKarma.csproj 268
当我查看我的包文件夹时,我可以找到名为 Microsoft.Net.Compilers.props
的文件
我试过使用 Nuget Restore,但它一直说我有所有的包。
当我将此项目从 TFS 转移到我的一台计算机时,会发生这种情况。
首先我会检查您的 MusicKarma 项目的 packages.config 文件中是否有 Microsoft.Net.Compilers。如果不是,那么您可以从 MusicKarma.csproj.
中删除与该 NuGet 包有关的所有内容
如果您使用的是 Microsoft.Net.Compilers NuGet 包,那么我的猜测是路径不正确。查看错误消息中的目录名称,我猜想 MusicKarma 解决方案文件 (.sln) 与 MusicKarma.csproj 在同一目录中。如果是这样,那么 packages 目录可能是错误的,因为默认情况下 packages 目录将位于解决方案目录中。所以我假设你的包目录是:
C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\packages
当您的 MusicKarma.csproj 文件正在寻找 props 文件时:
C:\Users\Bryan\Documents\Visual Studio 2015\Projects\packages\Microsoft.Net.Compilers.1.1.1\build
因此,如果是这种情况,您可以通过编辑 MusicKarma.csproj 文件中的路径或重新安装 NuGet 程序包来解决问题。
当我在文件系统中(不是在我的解决方案中)创建文件夹并四处移动一些项目时,我遇到了这个问题。
事实证明,包路径是 csproj 文件的相对路径。所以我不得不更改参考文献的 "HintPath":
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
收件人:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
注意 'HintPath' 中的双“..\”。
我还必须更改我的错误条件,例如我必须更改:
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />
收件人:
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />
再次注意双“..\”。
我也有这个错误
我从 .csproj 文件中获取了这部分代码:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
删除那部分代码。如果用记事本打开.csproj文件,删除Targuet代码,保存,正常打开
它有点旧 post 但我最近 运行 关注这个问题。
我所做的只是从 packages 文件夹中删除所有 nuget 包并恢复它。
我能够成功构建解决方案。
希望对某人有所帮助。
为什么需要对 packages.config 或 .csproj 文件进行操作?
错误明确指出:使用 NuGet 包还原来下载它们。
根据此指令使用它:https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting:
Quick solution for Visual Studio users
1.Select the Tools > NuGet Package Manager > Package Manager Settings menu command.
2.Set both options under Package Restore.
3.Select OK.
4.Build your project again.
对我和其他人来说非常有效的快速解决方案:
如果您使用的是 VS 2015+,只需从项目的 .csproj 文件中删除以下行:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
在 VS 2015+ 解决方案资源管理器中:
- 右键单击项目名称 -> 卸载项目
- 右键单击项目名称 -> 编辑 .csproj
- 从文件中删除上面指定的行并保存
- 右键单击项目名称 -> 重新加载项目
在我的例子中,我删除了以前的项目并创建了一个不同名称的新项目,当我构建项目时它显示相同的错误。
我刚刚在项目的 csproj 文件中编辑了项目名称并且成功了...!
从 .csproj 文件中删除这部分代码,并将项目移动到一个短的绝对路径中。
这意味着,最好位于较短的绝对路径上。
C:\Users\name\OneDrive\Desktop\spath1\test\test5....\mvc\Ecommerce
你可以像下面这样移动项目,而不是上面的,
C:\Users\name\OneDrive\Desktop\mvc\Ecommerce
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
我不太确定,我的项目发生了什么变化,或者这种情况是因为 vs 2015 或 vs 2017 或 vs 2019 之间的 dll 版本崩溃而发生的。
我已经从 TFS 克隆了我的项目,并且发生了这种情况。
这就是我所做的:
- 将 Microsoft.Net.Compilers 从 v.1 更新到 v.1.1
- 在 Source Control Exproler 上签入待定更改
- 撤消对文件的更改:.csproj、packages.config 和 web.config
- 关闭 VS2015 - 清理解决方案 - 重建解决方案
当我尝试构建解决方案时,收到以下错误消息:
Severity Code Description Project File Line Suppression State Error This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props. MusicKarma C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\MusicKarma.csproj 268
当我查看我的包文件夹时,我可以找到名为 Microsoft.Net.Compilers.props
的文件我试过使用 Nuget Restore,但它一直说我有所有的包。
当我将此项目从 TFS 转移到我的一台计算机时,会发生这种情况。
首先我会检查您的 MusicKarma 项目的 packages.config 文件中是否有 Microsoft.Net.Compilers。如果不是,那么您可以从 MusicKarma.csproj.
中删除与该 NuGet 包有关的所有内容如果您使用的是 Microsoft.Net.Compilers NuGet 包,那么我的猜测是路径不正确。查看错误消息中的目录名称,我猜想 MusicKarma 解决方案文件 (.sln) 与 MusicKarma.csproj 在同一目录中。如果是这样,那么 packages 目录可能是错误的,因为默认情况下 packages 目录将位于解决方案目录中。所以我假设你的包目录是:
C:\Users\Bryan\Documents\Visual Studio 2015\Projects\MusicKarma\packages
当您的 MusicKarma.csproj 文件正在寻找 props 文件时:
C:\Users\Bryan\Documents\Visual Studio 2015\Projects\packages\Microsoft.Net.Compilers.1.1.1\build
因此,如果是这种情况,您可以通过编辑 MusicKarma.csproj 文件中的路径或重新安装 NuGet 程序包来解决问题。
当我在文件系统中(不是在我的解决方案中)创建文件夹并四处移动一些项目时,我遇到了这个问题。
事实证明,包路径是 csproj 文件的相对路径。所以我不得不更改参考文献的 "HintPath":
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
收件人:
<Reference Include="EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<HintPath>..\..\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll</HintPath>
<Private>True</Private>
</Reference>
注意 'HintPath' 中的双“..\”。
我还必须更改我的错误条件,例如我必须更改:
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />
收件人:
<Error Condition="!Exists('..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\Microsoft.Net.Compilers.1.1.1\build\Microsoft.Net.Compilers.props'))" />
再次注意双“..\”。
我也有这个错误 我从 .csproj 文件中获取了这部分代码:
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
删除那部分代码。如果用记事本打开.csproj文件,删除Targuet代码,保存,正常打开
它有点旧 post 但我最近 运行 关注这个问题。 我所做的只是从 packages 文件夹中删除所有 nuget 包并恢复它。 我能够成功构建解决方案。 希望对某人有所帮助。
为什么需要对 packages.config 或 .csproj 文件进行操作?
错误明确指出:使用 NuGet 包还原来下载它们。
根据此指令使用它:https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting:
Quick solution for Visual Studio users
1.Select the Tools > NuGet Package Manager > Package Manager Settings menu command.
2.Set both options under Package Restore.
3.Select OK.
4.Build your project again.
对我和其他人来说非常有效的快速解决方案:
如果您使用的是 VS 2015+,只需从项目的 .csproj 文件中删除以下行:
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
在 VS 2015+ 解决方案资源管理器中:
- 右键单击项目名称 -> 卸载项目
- 右键单击项目名称 -> 编辑 .csproj
- 从文件中删除上面指定的行并保存
- 右键单击项目名称 -> 重新加载项目
在我的例子中,我删除了以前的项目并创建了一个不同名称的新项目,当我构建项目时它显示相同的错误。
我刚刚在项目的 csproj 文件中编辑了项目名称并且成功了...!
从 .csproj 文件中删除这部分代码,并将项目移动到一个短的绝对路径中。 这意味着,最好位于较短的绝对路径上。
C:\Users\name\OneDrive\Desktop\spath1\test\test5....\mvc\Ecommerce
你可以像下面这样移动项目,而不是上面的,
C:\Users\name\OneDrive\Desktop\mvc\Ecommerce
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
我不太确定,我的项目发生了什么变化,或者这种情况是因为 vs 2015 或 vs 2017 或 vs 2019 之间的 dll 版本崩溃而发生的。
我已经从 TFS 克隆了我的项目,并且发生了这种情况。
这就是我所做的:
- 将 Microsoft.Net.Compilers 从 v.1 更新到 v.1.1
- 在 Source Control Exproler 上签入待定更改
- 撤消对文件的更改:.csproj、packages.config 和 web.config
- 关闭 VS2015 - 清理解决方案 - 重建解决方案